diff --git a/app/controller/api/Money_logController.php b/app/controller/api/Money_logController.php index a33a035..35f0179 100644 --- a/app/controller/api/Money_logController.php +++ b/app/controller/api/Money_logController.php @@ -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 判断类型") diff --git a/app/dao/UserRewardDao.php b/app/dao/UserRewardDao.php index c919718..0d0b1ef 100644 --- a/app/dao/UserRewardDao.php +++ b/app/dao/UserRewardDao.php @@ -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: // 如果没有匹配的时间段,返回空结果或其他处理方式