Commit ebf6216b authored by clone's avatar clone

提现

parent bff0bb5a
<?php
namespace app\api\controller;
use app\api\extend\Basic;
use app\api\service\AccountBalanceService;
use think\Request;
......@@ -10,7 +12,8 @@ use think\Request;
* Date: 2019/3/13
* Time: 10:17
*/
class AccountBalance extends Basic{
class AccountBalance extends Basic
{
private $s_account_balance;
public function __construct(Request $request = null)
......@@ -33,11 +36,11 @@ class AccountBalance extends Basic{
"user_phone" => '6471',
"user_id" => '111',
);*/
if(empty($params["user_id"])){
if (empty($params["user_id"])) {
return $this->response("101", "请求参数错误");
}
$data = $this->s_account_balance->getBalanceList($params);
if(count($data) <= 0){
if (count($data) <= 0) {
return $this->response("200", "null");
}
return $this->response("200", "success!", $data);
......@@ -47,19 +50,55 @@ class AccountBalance extends Basic{
* 账户余额
* @return \think\Response
*/
public function totalAccount(){
public function totalAccount()
{
$params = $this->params;
/*$params = array(
"user_id" => 4
);*/
if(empty($params["user_id"])){
if (empty($params["user_id"])) {
return $this->response("101", "请求参数错误");
}
$total = $this->s_account_balance->getAccountTotal($params["user_id"]);
if($total <= 0 ){
if ($total <= 0) {
$total = 0;
}
return $this->response("200","success",["total"=>$total]);
return $this->response("200", "success", ["total" => $total]);
}
/**
* 申请提现
* @return \think\Response
*/
public function applyForWithdraw()
{
$params = $this->params;
/*$params = array(
"user_id" => 4,
"money" => 11,
"user_phone"=> "11231",
"user_name" => "12312"
);*/
if (empty($params["user_id"]) || empty($params["money"]) || empty($params["user_phone"])) {
return $this->response("101", "请求参数错误");
}
$user_id = $params["user_id"];
$user_phone = $params["money"];
$money = $params["user_phone"];
$user_name = $params["user_name"];
if ($money < 30) {
return $this->response("101", "提现金额不能小于30");
}
$total = $this->s_account_balance->getAccountTotal($user_id);
if($money > $total){
return $this->response("101", "账户余额不足,请刷新后再提交!");
}
$result = $this->s_account_balance->addCheck($user_id, $user_phone, $money, $user_name);
if ($result > 0) {
return $this->response("200", "success");
}
return $this->response("101", "申请提现异常");
}
}
\ No newline at end of file
......@@ -87,5 +87,17 @@ class AccountBalanceService{
return $balanceTotal - $checkTotal ;
}
public function addCheck($user_id,$user_phone,$money,$user_name){
$arr = array(
"user_id" => $user_id,
"user_phone" => $user_phone,
"money" => $money,
"status" => 0,
"user_name" => $user_name
);
$accountCheckModel = new UAccountCheck();
return $accountCheckModel->addCheck($arr);
}
}
\ No newline at end of file
......@@ -61,4 +61,17 @@ class UAccountCheck extends Model{
->sum("money");
return $result;
}
public function addCheck($params){
Db::startTrans();
$id = 0;
try {
$id = $this->db_->insertGetId($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
}
return $id;
}
}
\ No newline at end of file
......@@ -524,6 +524,7 @@ Route::group('api', [
'userAccountBalanceList' => ['api/AccountBalance/userAccountBalanceList', ['method' => 'get|post']],//
'totalAccount' => ['api/AccountBalance/totalAccount', ['method' => 'post']],
'applyForWithdraw' => ['api/AccountBalance/applyForWithdraw', ['method' => 'post']],
]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment