From 28ab7dbbd18b3ccbad853789746321d895e5626f Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 23 Jul 2021 11:30:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0AgentProductController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/AgentProductController.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 app/Http/Controllers/Api/AgentProductController.php diff --git a/app/Http/Controllers/Api/AgentProductController.php b/app/Http/Controllers/Api/AgentProductController.php new file mode 100644 index 0000000..6d5dda6 --- /dev/null +++ b/app/Http/Controllers/Api/AgentProductController.php @@ -0,0 +1,79 @@ +input('channel_id'); + if ($channel_id) { + $where['channel_id'] = $channel_id; + } + + $where['agent_id'] = $this->agent_id; + + $list = AgentProduct::where($where) + ->with(['product' => fn($query) => $query->select('id', 'title', 'pictures')]) + ->select('id', 'sale', 'product_id', 'price', 'original_price') + ->orderBy('id', 'DESC') + ->simplePaginate(); + return $this->success($list); + } + + // 产品详情 + public function show() + { + $id = request()->input('id'); + if (!$id || !ctype_digit($id)) { + return $this->error('无效的ID'); + } + + // TODO 此处待优化 + $data = DB::table('agent_products AS ap') + ->leftJoin('products AS p', 'p.id', '=', 'ap.product_id') + //->leftJoin('product_infos AS pi', 'p.id', '=', 'pi.product_id') + ->select('ap.*', 'p.title', 'p.pictures') + ->where('ap.id', $id) + ->where(['ap.status' => 1, 'p.status' => 1]) + ->first(); + + if (!$data) { + return $this->error('产品不存在或已下架'); + } + $coupon_ids = explode(',', $data->coupon_ids); + $data->coupon_ids = DB::table('coupons')->whereIn('id', $coupon_ids)->pluck('tag'); + $data->pictures = json_decode($data->pictures, true); + unset($data->deleted_at); + return $this->success($data); + } + + // 人气爆款 + /*public function hot() + { + $list = Product::get(['title', 'price', 'original_price', 'pictures', 'sale']); + return $this->success($list); + }*/ + + // 猜你喜欢 + public function guessLike() + { + $page = request()->only('page'); + if ($page && !ctype_digit($page)) { + return $this->error('页码错误'); + } + + $list = Product::get(['title', 'price', 'original_price', 'pictures', 'sale'])->simplePaginate(); + return $this->success($list); + } +}