fix: 分页
This commit is contained in:
parent
cdc71c544a
commit
6151c4c739
|
@ -29,11 +29,12 @@ class Money_logController
|
||||||
*/
|
*/
|
||||||
public function lists(Request $request)
|
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'];
|
$user_id = $request->data['id'];
|
||||||
$status = $request->post('status');
|
return ApiResponseApp::success(UserRewardDao::search($user_id, $status, $time, $page, $size));
|
||||||
$time = $request->post('time');
|
|
||||||
return ApiResponseApp::success(UserRewardDao::search($user_id, $status, $time));
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @Apidoc\Title("1.0 消息根据type 判断类型")
|
* @Apidoc\Title("1.0 消息根据type 判断类型")
|
||||||
|
|
|
@ -110,7 +110,7 @@ class UserRewardDao
|
||||||
* @param int $time 时间段(0: 全部时间,1: 今天,2: 昨天,3: 最近七天)
|
* @param int $time 时间段(0: 全部时间,1: 今天,2: 昨天,3: 最近七天)
|
||||||
* @return mixed 返回查询结果(可以是数组或查询对象)
|
* @return mixed 返回查询结果(可以是数组或查询对象)
|
||||||
*/
|
*/
|
||||||
public static function search($userid, $status, int $time)
|
public static function search($userid, $status, int $time,$page,$size)
|
||||||
{
|
{
|
||||||
// 初始化查询对象
|
// 初始化查询对象
|
||||||
if ($status == 0) {
|
if ($status == 0) {
|
||||||
|
@ -123,22 +123,34 @@ class UserRewardDao
|
||||||
switch ($time) {
|
switch ($time) {
|
||||||
case 0:
|
case 0:
|
||||||
// 全部时间:查询没有时间限制的记录
|
// 全部时间:查询没有时间限制的记录
|
||||||
return $query->get();
|
return $query->orderBy('id', 'DESC')
|
||||||
|
->skip(($page - 1) * $size)
|
||||||
|
->take($size)
|
||||||
|
->get();
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// 今天:查询今天的记录
|
// 今天:查询今天的记录
|
||||||
$today = date('Y-m-d');
|
$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:
|
case 2:
|
||||||
// 昨天:查询昨天的记录
|
// 昨天:查询昨天的记录
|
||||||
$endOfYesterday = date('Y-m-d', strtotime('-1 day'));
|
$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:
|
case 3:
|
||||||
// 最近七天:查询过去七天的记录
|
// 最近七天:查询过去七天的记录
|
||||||
$sevenDaysAgo = date('Y-m-d', strtotime('-7 days'));
|
$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:
|
default:
|
||||||
// 如果没有匹配的时间段,返回空结果或其他处理方式
|
// 如果没有匹配的时间段,返回空结果或其他处理方式
|
||||||
|
|
Loading…
Reference in New Issue