From 9d616f73dc5184a9b727b778bff02b2420d9da6b Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 27 Aug 2021 16:08:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96list()=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/AgentProductController.php | 11 +++++------ app/Http/Controllers/Api/ChannelController.php | 2 +- app/Http/Controllers/Api/IndexController.php | 2 +- app/Http/Controllers/Api/SpecialController.php | 3 +-- app/Models/AgentProduct.php | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Api/AgentProductController.php b/app/Http/Controllers/Api/AgentProductController.php index 40fdc4a..f44b4de 100644 --- a/app/Http/Controllers/Api/AgentProductController.php +++ b/app/Http/Controllers/Api/AgentProductController.php @@ -19,13 +19,12 @@ class AgentProductController extends Controller public function index() { $category_id = request()->input('category_id'); + $where = []; if ($category_id) { $where['category_id'] = $category_id; } - $where['agent_id'] = $this->agent_id; - - $list = AgentProduct::list()->where($where)->orderBy('id', 'DESC')->simplePaginate(); + $list = AgentProduct::list($this->agent_id)->where($where)->orderBy('id', 'DESC')->simplePaginate(); $list = $this->paginatePicAddHost($list); $list = $this->insertAd($list); @@ -70,7 +69,7 @@ class AgentProductController extends Controller // 猜你喜欢 public function guessLike() { - $list = AgentProduct::list()->where('agent_id', $this->agent_id)->orderBy('id', 'DESC')->simplePaginate(); + $list = AgentProduct::list($this->agent_id)->orderBy('id', 'DESC')->simplePaginate(); $list = $this->paginatePicAddHost($list); $list = $list->toArray(); if (!empty($list['data']) && is_array($list['data'])) { @@ -84,7 +83,7 @@ class AgentProductController extends Controller //【我的】页面下方推荐 public function recommendList() { - $list = AgentProduct::list()->where(['agent_id' => $this->agent_id, 'is_rec' => 1]) + $list = AgentProduct::list($this->agent_id)->where(['is_rec' => 1]) ->orderBy('id', 'DESC')->simplePaginate(); $list = $this->paginatePicAddHost($list); $list = $this->insertAd($list); @@ -95,7 +94,7 @@ class AgentProductController extends Controller //人气爆款列表,销量排序 public function hotList() { - $list = AgentProduct::list()->where('agent_id', $this->agent_id)->orderBy('id', 'DESC')->simplePaginate(); + $list = AgentProduct::list($this->agent_id)->orderBy('id', 'DESC')->simplePaginate(); $list = $this->paginatePicAddHost($list); $list = $this->insertAd($list); diff --git a/app/Http/Controllers/Api/ChannelController.php b/app/Http/Controllers/Api/ChannelController.php index 2e4ee2d..34bf70e 100644 --- a/app/Http/Controllers/Api/ChannelController.php +++ b/app/Http/Controllers/Api/ChannelController.php @@ -42,7 +42,7 @@ class ChannelController extends Controller { $channel_id = (int)request()->input('channel_id'); - $list = AgentProduct::list()->where('agent_id', $this->agent_id) + $list = AgentProduct::list($this->agent_id) ->whereRaw("FIND_IN_SET($channel_id, `channel_id`)") ->orderBy('id', 'DESC') ->simplePaginate(); diff --git a/app/Http/Controllers/Api/IndexController.php b/app/Http/Controllers/Api/IndexController.php index 0f32d30..1224a2b 100644 --- a/app/Http/Controllers/Api/IndexController.php +++ b/app/Http/Controllers/Api/IndexController.php @@ -82,7 +82,7 @@ class IndexController extends Controller } # 人气爆款 - $hots = AgentProduct::list()->where('agent_id', $this->agent_id) + $hots = AgentProduct::list($this->agent_id) ->orderBy('sale', 'desc')->orderBy('id', 'desc') ->limit(6)->get(); if (!$hots->isEmpty()) { diff --git a/app/Http/Controllers/Api/SpecialController.php b/app/Http/Controllers/Api/SpecialController.php index 638e828..977735e 100644 --- a/app/Http/Controllers/Api/SpecialController.php +++ b/app/Http/Controllers/Api/SpecialController.php @@ -19,8 +19,7 @@ class SpecialController extends Controller ->find($id); $detail->picture = array_map(fn($v) => $prefix . $v, $detail->picture); - $detail->product = AgentProduct::list() - ->where('agent_id', $this->agent_id) + $detail->product = AgentProduct::list($this->agent_id) ->whereIn('id', $detail->agent_product_id) ->orderBy('id', 'DESC')->limit(6)->get(); foreach ($detail->product as $k => &$v) { diff --git a/app/Models/AgentProduct.php b/app/Models/AgentProduct.php index 5957e13..d8cb9ce 100644 --- a/app/Models/AgentProduct.php +++ b/app/Models/AgentProduct.php @@ -90,12 +90,12 @@ class AgentProduct extends BaseModel } //列表查询统一查询条件 - public function scopeList($query) + public function scopeList($query, $agent_id) { return $query->whereHas('product', function ($query) { return $query->where('status', ProductStatus::ON_SALE)->where('stock', '>', 0); }) - ->where('status', ProductStatus::ON_SALE)->where('stock', '>', 0) + ->where(['agent_id' => $agent_id, 'status' => ProductStatus::ON_SALE])->where('stock', '>', 0) ->select('id', 'sale', 'product_id', 'price', 'original_price', 'title', 'pictures'); } }