12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace addons\shopro\controller\user;
- use app\api\controller\Base;
- use app\common\model\user\WalletLog as UserWalletLogModel;
- class WalletLog extends Base
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- public function index()
- {
- $type = $this->request->param('type', 'money');
- $tab = $this->request->param('tab', 'all');
- $list_rows = $this->request->param('list_rows', 10);
- $date = $this->request->param('date/a');
- $user = auth_user();
- $where['user_id'] = $user->id;
- switch ($tab) {
- case 'income':
- $where['amount'] = ['>', 0];
- break;
- case 'expense':
- $where['amount'] = ['<', 0];
- break;
- }
- $income = UserWalletLogModel::where('user_id', $user->id)->{$type}()
- ->where('amount', '>', 0)
- ->whereTime('createtime', 'between', $date)->sum('amount');
- $expense = UserWalletLogModel::where('user_id', $user->id)->{$type}()->where('amount', '<', 0)->whereTime('createtime', 'between', $date)->sum('amount');
- $logs = UserWalletLogModel::where($where)->{$type}()->whereTime('createtime', 'between', $date)->order('createtime', 'desc')->paginate($list_rows);
- $this->success('获取成功', ['list' => $logs, 'income' => $income, 'expense' => $expense]);
- }
- }
|