input('category_id'); if ($category_id) { $where['category_id'] = $category_id; } $where['agent_id'] = $this->agent_id; $list = AgentProduct::where($where) ->with('product:id,title,pictures') ->whereHas('product', function ($query) { return $query->where('status', ProductStatus::ON_SALE); }) ->select('id', 'sale', 'product_id', 'price', 'original_price') ->orderBy('id', 'DESC') ->simplePaginate(); return $this->success($list); } // 产品详情 public function show() { $id = (int)request()->input('id'); // TODO 优惠券查询待优化 $agent_product = AgentProduct::query() ->with('product:id,title,pictures,know,stock,content') ->with('coupon:tag,agent_product_id') ->with('fav:agent_product_id') ->whereHas('product', function ($query) { return $query->where('status', ProductStatus::ON_SALE); }) ->firstWhere(['id' => $id, 'agent_id' => $this->agent_id, 'status' => ProductStatus::ON_SALE]); if (!$agent_product || !$agent_product->product) { return $this->error('产品不存在或已下架'); } $agent_product->is_collect = !is_null($agent_product->fav); //判断是否收藏 //计算折扣 if ($agent_product->price < $agent_product->original_price) { $agent_product->cost = round($agent_product->price / $agent_product->original_price * 10, 1); } else { $agent_product->cost = ''; } unset($agent_product->agent_id, $agent_product->status, $agent_product->deleted_at); return $this->success($agent_product); } // 猜你喜欢 public function guessLike() { // TODO 此处需要再优化排序规则,并增加广告功能 $list = AgentProduct::where('agent_id', $this->agent_id) ->with('product:id,title,pictures') ->whereHas('product', function ($query) { return $query->where('status', ProductStatus::ON_SALE); }) ->select('id', 'sale', 'product_id', 'price', 'original_price') ->orderBy('id', 'DESC') ->simplePaginate(); return $this->success($list); } //【我的】页面下方推荐 public function recommendList() { //TODO 推荐数据暂时使用产品列表,后期需要通过后台设置获取或根据用户购买过的关键词获取 return $this->index(); } //人气爆款列表 public function hotList() { //TODO 具体排序规则,后期再做修改 return $this->index(); } }