From 37a1eb6a6cc2d12ee0d4e24319f5c175dfd09240 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 10 Dec 2025 15:29:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=96=E5=AD=90=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/PostFavoriteController.php | 16 ++++++++++++---- app/common/service/PostFavoriteService.php | 12 ++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/common/controller/PostFavoriteController.php b/app/common/controller/PostFavoriteController.php index 46b46cb..e015554 100644 --- a/app/common/controller/PostFavoriteController.php +++ b/app/common/controller/PostFavoriteController.php @@ -32,10 +32,18 @@ class PostFavoriteController extends BaseController try { // $raw = $this->service->serviceSelfList($request); $raw = $this->service->serviceList($request); - $data = $this->transformData($raw, method_exists($this, 'indexFormat') - ? [$this, 'indexFormat'] - : null); - return $this->success($data); +// $data = $this->transformData($raw, method_exists($this, 'indexFormat') +// ? [$this, 'indexFormat'] +// : null); + + $data = []; + foreach ($raw['records'] as $key => $item) { + $item['created_at'] = strtotime($item['created_at']); + $item['updated_at'] = strtotime($item['updated_at']); + $data[$key] = $this->indexFormat($item); + } + $raw['records'] = $data; + return $this->success($raw); } catch (\Throwable $e) { return $this->error($e->getMessage()); } diff --git a/app/common/service/PostFavoriteService.php b/app/common/service/PostFavoriteService.php index a1dee73..f3e0aa2 100644 --- a/app/common/service/PostFavoriteService.php +++ b/app/common/service/PostFavoriteService.php @@ -79,10 +79,9 @@ class PostFavoriteService { $param = $request->all(); $size = $param['size'] ?? 10; + $current = $param['current'] ?? 1; $orderField = $param['sort_by'] ?? 'post_favorites.created_at'; // 默认按收藏时间 $orderType = in_array($param['order'],['desc','asc']) ? $param['order'] :'desc'; // 默认倒序 - var_dump($orderType); - var_dump($request->user->uid); // 构建基础查询 $query = PostFavorite::select('post_favorite.*') // 明确选择主表字段 @@ -113,7 +112,7 @@ class PostFavoriteService // 执行分页查询 - $paginator = $query->paginate($size); + $paginator = $query->paginate($size, ['*'], 'page', $current); // 由于使用了join,需要重新手动加载关联的post数据 $paginator->getCollection()->transform(function ($item) { @@ -121,7 +120,12 @@ class PostFavoriteService return $item; }); - return $paginator->items(); + $res = ['records' => $paginator->items(), + 'current' => $current ?? 1, + 'size' => $size, + 'total' => $query->count(), + ]; + return $res; } /**