Commit 85eceb29 authored by 刘小敏's avatar 刘小敏

累计消费累计充值接口增加返回值

parent e9845ba8
...@@ -5,6 +5,7 @@ namespace addons\shopro\controller\user; ...@@ -5,6 +5,7 @@ namespace addons\shopro\controller\user;
use addons\shopro\controller\Common; use addons\shopro\controller\Common;
use app\admin\model\shopro\user\WalletLog as UserWalletLogModel; use app\admin\model\shopro\user\WalletLog as UserWalletLogModel;
use think\Cache; use think\Cache;
use app\admin\model\shopro\user\User as UserModel;
class WalletLog extends Common class WalletLog extends Common
{ {
...@@ -45,13 +46,19 @@ class WalletLog extends Common ...@@ -45,13 +46,19 @@ class WalletLog extends Common
/** /**
* 钱包统计( 累计充值 和 累计消费 ) * 钱包统计( 累计充值 和 累计消费 )
* @param string $type 钱包类型:money-余额, score-积分, commission-佣金(默认money * @param string $type 钱包类型:money-余额, score-积分, commission-佣金(score
* @return array * @return array
*/ */
public function walletStats() public function walletStats()
{ {
$user = auth_user(); $user = auth_user();
$type = $this->request->param('type', 'score'); $type = $this->request->param('type', 'score');
$date = $this->request->param('date/a');
// 验证并设置默认时间范围
if (!is_array($date) || count($date) < 2 || empty($date[0]) || empty($date[1])) {
$date = [date('0000-00-00 00:00:00'), date('Y-m-d 23:59:59')];
}
// 验证钱包类型 // 验证钱包类型
if (!in_array($type, ['money', 'score', 'commission'])) { if (!in_array($type, ['money', 'score', 'commission'])) {
...@@ -75,23 +82,37 @@ class WalletLog extends Common ...@@ -75,23 +82,37 @@ class WalletLog extends Common
->where('type', $type) ->where('type', $type)
->where('amount', '>', 0) ->where('amount', '>', 0)
->whereIn('event', $rechargeEvents[$type]) ->whereIn('event', $rechargeEvents[$type])
->whereTime('createtime', 'between', $date)
->sum('amount') ?: 0; ->sum('amount') ?: 0;
// 累计消费(支出) // 累计消费(支出)
$consume = UserWalletLogModel::where('user_id', $user->id) $consume = UserWalletLogModel::where('user_id', $user->id)
->where('type', $type) ->where('type', $type)
->where('amount', '<', 0) ->where('amount', '<', 0)
->whereTime('createtime', 'between', $date)
->sum('amount') ?: 0; ->sum('amount') ?: 0;
//用户当前积分/余额/佣金
$user_info = UserModel::where('id', $user->id)->find();
$result = [ $result = [
'recharge' => round($recharge, 2), 'recharge' => round($recharge, 2),
'consume' => round(abs($consume), 2), 'consume' => round(abs($consume), 2),
'type' => $type 'type' => $type,
'score' => $user_info->score,
'commission' => $user_info->commission,
'money' => $user_info->money,
]; ];
} catch (\Exception $e) { } catch (\Exception $e) {
$result = [ $result = [
'recharge' => 0, 'recharge' => 0,
'consume' => 0, 'consume' => 0,
'type' => $type 'type' => $type,
'score' => 0,
'commission' => 0,
'money' => 0,
]; ];
} }
......
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