CommissionController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace api\modules\v1\controllers\user;
  3. use api\controllers\OnAuthController;
  4. use common\models\common\CapitalLog;
  5. use common\models\user\UserWallet;
  6. use Yii;
  7. class CommissionController extends OnAuthController
  8. {
  9. public $modelClass = '';
  10. /**
  11. *
  12. * 不用进行登录验证的方法
  13. *
  14. * 例如: ['index', 'update', 'create', 'view', 'delete']
  15. * 默认全部需要验证
  16. *
  17. * @var array
  18. */
  19. protected $authOptional = ['login', 'mobile-login', 'sms-code', 'register', 'up-pwd'];
  20. /**
  21. * 余额详情
  22. * @return mixed|void
  23. */
  24. public function actionDetail()
  25. {
  26. $user_wallet = UserWallet::findOne(['user_id' => $this->user_id]);
  27. $data['now_balance'] = $user_wallet['balance']??0;
  28. $data['today_income'] = 0;
  29. $data['withdraw_num'] = 0;
  30. $data['use_num'] = 0;
  31. $data['top_up_num'] = 0;
  32. $where = [];
  33. $where[] = ['mall_id' => $this->mall_id];
  34. $where[] = ['user_id' => $this->user_id];
  35. $params['order'] = 'id desc';
  36. $params['select'] = 'type,balance_from_type,sum(money) as money';
  37. $params['where'] = $where;
  38. $params['group'] = 'type,balance_from_type';
  39. $list = BalanceLog::listPage($params);
  40. if (!empty($list['list'])) {
  41. $use_num_arr = [BalanceLog::getBalanceLogFrom('Pk支付'),
  42. BalanceLog::getBalanceLogFrom('云库存补货'),
  43. BalanceLog::getBalanceLogFrom('支付拿货款'),
  44. BalanceLog::getBalanceLogFrom('余额支付'),];
  45. $top_up_num_arr = [BalanceLog::getBalanceLogFrom('后台充值'),
  46. BalanceLog::getBalanceLogFrom('前端会员充值')];
  47. foreach ($list['list'] as $v) {
  48. if ($v['type'] == 2 && in_array($v['balance_from_type'], $use_num_arr)) $data['use_num'] += $v['money'];
  49. if ($v['balance_from_type'] == 17) $data['withdraw_num'] = $v['money'];
  50. if ($v['type'] == 1 && in_array($v['balance_from_type'], $top_up_num_arr)) $data['top_up_num'] += $v['money'];
  51. }
  52. }
  53. $where[] = ['type' => 1];
  54. $where[] = ['>=', 'created_at', strtotime(date('Y-m-d', time()) . ' 00:00:00')];
  55. $where[] = ['<=', 'created_at', strtotime(date('Y-m-d', time()) . ' 23:59:59')];
  56. $result = BalanceLog::listPage(['where' => $where, 'select' => 'sum(money) as money']);
  57. if (!empty($result['list']) && !empty($result['list'][0]['money'])) $data['today_income'] = $result['list'][0]['money'];
  58. return $this->success('操作成功', $data);
  59. }
  60. /**
  61. * 余额充值/消费/提现记录
  62. * @return mixed|void
  63. */
  64. public function actionList()
  65. {
  66. $params = \Yii::$app->request->get();
  67. $res = Yii::$app->services->validate->validate($params, [
  68. [['type'], 'required', 'message' => 'type,必传'],
  69. ]);
  70. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  71. $where = [];
  72. $where[] = ['mall_id' => $this->mall_id];
  73. $where[] = ['user_id' => $this->user_id];
  74. if ($params['type'] == 3) {
  75. $use_num_arr = [BalanceLog::getBalanceLogFrom('Pk支付'),
  76. BalanceLog::getBalanceLogFrom('云库存补货'),
  77. BalanceLog::getBalanceLogFrom('支付拿货款'),
  78. BalanceLog::getBalanceLogFrom('余额支付')];
  79. $where[] = ['type' => 2];
  80. $where[] = ['balance_from_type' => $use_num_arr];
  81. }
  82. if ($params['type'] == 2) {
  83. $where[] = ['type' => 2];
  84. $where[] = ['balance_from_type' => [BalanceLog::getBalanceLogFrom('余额提现')]];
  85. }
  86. if ($params['type'] == 1) {
  87. $where[] = ['type' => 1];
  88. $where[] = ['balance_from_type' => [BalanceLog::getBalanceLogFrom('后台充值'), BalanceLog::getBalanceLogFrom('前端会员充值')]];
  89. }
  90. $params['select'] = 'id,type,money,desc,balance,created_at';
  91. $params['order'] = 'id desc';
  92. $params['where'] = $where;
  93. $list = BalanceLog::listPage($params);
  94. return $this->success('操作成功', $list);
  95. }
  96. }