Commit e9845ba8 authored by 刘小敏's avatar 刘小敏

钱包日志记录接口优化

parent 5372a577
......@@ -18,10 +18,16 @@ class WalletLog extends Common
$type = $this->request->param('type', 'money');
$tab = $this->request->param('tab', 'all');
$list_rows = $this->request->param('list_rows', 10);
$page = $this->request->param('page', 1);
$date = $this->request->param('date/a');
$user = auth_user();
$where['user_id'] = $user->id;
// 验证并设置默认时间范围
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')];
}
switch ($tab) {
case 'income':
$where['amount'] = ['>', 0];
......@@ -33,7 +39,7 @@ class WalletLog extends Common
$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);
$logs = UserWalletLogModel::where($where)->{$type}()->whereTime('createtime', 'between', $date)->order('createtime', 'desc')->paginate($list_rows, false, ['page' => $page]);
$this->success('获取成功', ['list' => $logs, 'income' => $income, 'expense' => $expense]);
}
......
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