WalletLog.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace addons\shopro\controller\user;
  3. use app\api\controller\Base;
  4. use app\common\model\user\WalletLog as UserWalletLogModel;
  5. class WalletLog extends Base
  6. {
  7. protected $noNeedLogin = [];
  8. protected $noNeedRight = ['*'];
  9. public function index()
  10. {
  11. $type = $this->request->param('type', 'money');
  12. $tab = $this->request->param('tab', 'all');
  13. $list_rows = $this->request->param('list_rows', 10);
  14. $date = $this->request->param('date/a');
  15. $user = auth_user();
  16. $where['user_id'] = $user->id;
  17. switch ($tab) {
  18. case 'income':
  19. $where['amount'] = ['>', 0];
  20. break;
  21. case 'expense':
  22. $where['amount'] = ['<', 0];
  23. break;
  24. }
  25. $income = UserWalletLogModel::where('user_id', $user->id)->{$type}()
  26. ->where('amount', '>', 0)
  27. ->whereTime('createtime', 'between', $date)->sum('amount');
  28. $expense = UserWalletLogModel::where('user_id', $user->id)->{$type}()->where('amount', '<', 0)->whereTime('createtime', 'between', $date)->sum('amount');
  29. $logs = UserWalletLogModel::where($where)->{$type}()->whereTime('createtime', 'between', $date)->order('createtime', 'desc')->paginate($list_rows);
  30. $this->success('获取成功', ['list' => $logs, 'income' => $income, 'expense' => $expense]);
  31. }
  32. }