Commit f5c62c3b authored by clone's avatar clone

账户余额

parent b03c2e95
......@@ -21,6 +21,7 @@ class AccountBalance extends Basic{
}
/**
* 收益明细
* @return \think\Response
*/
public function userAccountBalanceList()
......@@ -42,4 +43,23 @@ class AccountBalance extends Basic{
return $this->response("200", "success!", $data);
}
/**
* 账户余额
* @return \think\Response
*/
public function totalAccount(){
$params = $this->params;
/*$params = array(
"user_id" => 4
);*/
if(empty($params["user_id"])){
return $this->response("101", "请求参数错误");
}
$total = $this->s_account_balance->getAccountTotal($params["user_id"]);
if($total <= 0 ){
$total = 0;
}
return $this->response("200","success",["total"=>$total]);
}
}
\ No newline at end of file
......@@ -80,5 +80,12 @@ class AccountBalanceService{
return $referrer_res;
}
public function getAccountTotal($user_id){
$balanceTotal = $this->m_account_balance->getBalanceTotal($user_id);
$accountCheckModel = new UAccountCheck();
$checkTotal = $accountCheckModel->getCheckTotal($user_id);
return $balanceTotal - $checkTotal ;
}
}
\ No newline at end of file
......@@ -81,5 +81,24 @@ class UAccountBalance extends Model
return $result;
}
/**
* @param $params
* @return int|string
*/
public function getBalanceTotal($user_id)
{
$where_arr = [];
if (!empty($user_id)) {
$where_arr['user_id'] = $user_id;
}
$where_arr['status'] = 0;
$result = $this->db_
->field("id")
->where($where_arr)
->sum("money");
return $result;
}
}
......@@ -43,4 +43,22 @@ class UAccountCheck extends Model{
->count();
return $result;
}
/**
* @param $params
* @return int|string
*/
public function getCheckTotal($user_id)
{
$where_arr = [];
if (!empty($user_id)) {
$where_arr['user_id'] = $user_id;
}
$where_arr['status'] = array("in", "0,1");;
$result = $this->db_
->field("id")
->where($where_arr)
->sum("money");
return $result;
}
}
\ No newline at end of file
......@@ -523,6 +523,7 @@ Route::group('api', [
'userAccountBalanceList' => ['api/AccountBalance/userAccountBalanceList', ['method' => 'get|post']],//
'totalAccount' => ['api/AccountBalance/totalAccount', ['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