From dac6aecf5afd06973a2571b1d995e6dc9ee425e5 Mon Sep 17 00:00:00 2001 From: liapples Date: Mon, 26 Jul 2021 18:31:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E9=A1=B5=E7=A0=81=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=92=8CID=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/NoticeController.php | 12 ++---------- app/Http/Controllers/Api/UserFavController.php | 17 +++++++---------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/Api/NoticeController.php b/app/Http/Controllers/Api/NoticeController.php index 16412b8..28bfd75 100644 --- a/app/Http/Controllers/Api/NoticeController.php +++ b/app/Http/Controllers/Api/NoticeController.php @@ -14,12 +14,7 @@ class NoticeController extends Controller // 公告列表 public function index() { - $page = request()->input('page'); - if ($page && !ctype_digit($page)) { - return $this->error('页码错误'); - } - - $list = Notice::where('agent_id', $this->agent_id) + $list = Notice::query()->where('agent_id', $this->agent_id) ->select(['title', 'updated_at']) ->orderBy('id', 'DESC') ->simplePaginate(15); @@ -28,10 +23,7 @@ class NoticeController extends Controller public function show() { - $id = request()->input('id'); - if (!$id || !ctype_digit($id)) { - return $this->error('无效的ID'); - } + $id = (int)request()->input('id'); $data = Notice::where('agent_id', $this->agent_id)->find($id); if (!$data) { diff --git a/app/Http/Controllers/Api/UserFavController.php b/app/Http/Controllers/Api/UserFavController.php index 4d03875..40dee92 100644 --- a/app/Http/Controllers/Api/UserFavController.php +++ b/app/Http/Controllers/Api/UserFavController.php @@ -6,15 +6,15 @@ use App\Http\Controllers\Controller; use App\Models\AgentProduct; use App\Models\UserFav; +/** + * 用户收藏 + * Class UserFavController + * @package App\Http\Controllers\Api + */ class UserFavController extends Controller { public function index() { - $page = request()->input('page'); - if ($page && !ctype_digit($page)) { - return $this->error('页码错误'); - } - $list = UserFav::query()->with([ 'agentProduct' => fn($query) => $query->select('id', 'price', 'original_price'), 'product' => fn($query) => $query->select('id', 'title', 'pictures'), @@ -28,12 +28,9 @@ class UserFavController extends Controller public function create() { - $id = request()->input('id'); - if (!$id || !ctype_digit($id)) { - return $this->error('无效的ID'); - } + $id = (int)request()->input('id'); - $agent_product = AgentProduct::find($id); + $agent_product = AgentProduct::where('user_id', $this->user_id)->find($id); if (!$agent_product) { return $this->error('产品不存在或已被删除'); }