fix: 分页

This commit is contained in:
陈狼 2025-02-24 15:08:48 +08:00
parent cdc71c544a
commit 6151c4c739
2 changed files with 22 additions and 9 deletions

View File

@ -29,11 +29,12 @@ class Money_logController
*/
public function lists(Request $request)
{
$page = $request->post('page', 1); // 默认第一页
$size = $request->post('size', 15); // 默认每页15条
$status = $request->post('status', 0); // 默认状态为0全部
$time = $request->post('time', null); // 默认时间不做过滤
$user_id = $request->data['id'];
$status = $request->post('status');
$time = $request->post('time');
return ApiResponseApp::success(UserRewardDao::search($user_id, $status, $time));
return ApiResponseApp::success(UserRewardDao::search($user_id, $status, $time, $page, $size));
}
/**
* @Apidoc\Title("1.0 消息根据type 判断类型")

View File

@ -110,7 +110,7 @@ class UserRewardDao
* @param int $time 时间段0: 全部时间1: 今天2: 昨天3: 最近七天)
* @return mixed 返回查询结果(可以是数组或查询对象)
*/
public static function search($userid, $status, int $time)
public static function search($userid, $status, int $time,$page,$size)
{
// 初始化查询对象
if ($status == 0) {
@ -123,22 +123,34 @@ class UserRewardDao
switch ($time) {
case 0:
// 全部时间:查询没有时间限制的记录
return $query->get();
return $query->orderBy('id', 'DESC')
->skip(($page - 1) * $size)
->take($size)
->get();
case 1:
// 今天:查询今天的记录
$today = date('Y-m-d');
return $query->where('created_at', '>=', $today." 00:00:00")->orderBy('id','DESC')->get();
return $query->where('created_at', '>=', $today." 00:00:00")->orderBy('id','DESC')
->skip(($page - 1) * $size)
->take($size)
->get();
case 2:
// 昨天:查询昨天的记录
$endOfYesterday = date('Y-m-d', strtotime('-1 day'));
return $query->whereBetween('created_at', [$endOfYesterday." 00:00:00", $endOfYesterday." 23:59:59"])->orderBy('id','DESC')->get();
return $query->whereBetween('created_at', [$endOfYesterday." 00:00:00", $endOfYesterday." 23:59:59"])->orderBy('id','DESC')
->skip(($page - 1) * $size)
->take($size)
->get();
case 3:
// 最近七天:查询过去七天的记录
$sevenDaysAgo = date('Y-m-d', strtotime('-7 days'));
return $query->where('created_at', '>=', $sevenDaysAgo." 23:59:59")->orderBy('id','DESC')->get();
return $query->where('created_at', '>=', $sevenDaysAgo." 23:59:59")->orderBy('id','DESC')
->skip(($page - 1) * $size)
->take($size)
->get();
default:
// 如果没有匹配的时间段,返回空结果或其他处理方式