WalletLog.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace addons\shopro\controller\user;
  3. use addons\shopro\controller\Common;
  4. use app\admin\model\shopro\user\WalletLog as UserWalletLogModel;
  5. class WalletLog extends Common
  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}()->where('amount', '>', 0)->whereTime('createtime', 'between', $date)->sum('amount');
  26. $expense = UserWalletLogModel::where('user_id', $user->id)->{$type}()->where('amount', '<', 0)->whereTime('createtime', 'between', $date)->sum('amount');
  27. $logs = UserWalletLogModel::where($where)->{$type}()->whereTime('createtime', 'between', $date)->order('createtime', 'desc')->paginate($list_rows);
  28. $this->success('获取成功', ['list' => $logs, 'income' => $income, 'expense' => $expense]);
  29. }
  30. }