diff --git a/app/AdminAgent/Renderable/SelectAgentCloudProduct.php b/app/AdminAgent/Renderable/SelectAgentCloudProduct.php index d128258..dde9318 100644 --- a/app/AdminAgent/Renderable/SelectAgentCloudProduct.php +++ b/app/AdminAgent/Renderable/SelectAgentCloudProduct.php @@ -30,12 +30,11 @@ class SelectAgentCloudProduct extends LazyRenderable ['is_cloud', '=', 1], ['type', '=', 1], ['agent_id', '<>', Admin::user()->id], - ])->whereDoesntHave('agentProductItem', function ($query) { - return $query->whereHas('product', function ($query) { - return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); - }); - }); - + ])->where(function ($query) { + $query->whereHas('product', function ($query) { + return $query->where([['stock', '>', 0], ['status', '=', ProductStatus::ON_SALE]]); + })->orWhere('product_id', 0); + }); $grid->quickSearch(['title'])->placeholder('搜索产品名称'); diff --git a/app/AdminAgent/Renderable/SelectAgentProduct.php b/app/AdminAgent/Renderable/SelectAgentProduct.php index 896e258..4b5fefc 100644 --- a/app/AdminAgent/Renderable/SelectAgentProduct.php +++ b/app/AdminAgent/Renderable/SelectAgentProduct.php @@ -26,11 +26,12 @@ class SelectAgentProduct extends LazyRenderable $grid->model()->where('stock', '>', 0) ->where(['agent_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]) - ->whereDoesntHave('agentProductItem', function ($query) { - return $query->whereHas('product', function ($query) { - return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); - }); + ->where(function ($query) { + $query->whereHas('product', function ($query) { + return $query->where([['stock', '>', 0], ['status', '=', ProductStatus::ON_SALE]]); + })->orWhere('product_id', 0); }); + $grid->quickSearch(['title'])->placeholder('搜索产品名称'); $grid->column('id'); diff --git a/app/Http/Controllers/Api/AgentProductController.php b/app/Http/Controllers/Api/AgentProductController.php index 1170f8f..3c49db7 100644 --- a/app/Http/Controllers/Api/AgentProductController.php +++ b/app/Http/Controllers/Api/AgentProductController.php @@ -166,10 +166,10 @@ SQL }); } ]) - ->whereDoesntHave('agentProductItem', function ($query) { - return $query->whereHas('product', function ($query) { - return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); - }); + ->where(function ($query) { + $query->whereHas('product', function ($query) { + return $query->where([['stock', '>', 0], ['status', '=', ProductStatus::ON_SALE]]); + })->orWhere('product_id', 0); }) ->where('stock', '>', 0) ->firstWhere($where); diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 5a2695d..5200a6b 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -143,11 +143,11 @@ class OrderController extends Controller $ap = AgentProduct::with(['coupon', 'product.diyForm.fields', 'diyForm.fields', 'agentCloudProduct:id,price']) ->where('stock', '>=', $formData['num']) ->where(['id' => $formData['id'], 'status' => ProductStatus::ON_SALE, 'agent_id' => $this->agent_id]) //判断agent_id,防止新入驻小程序的演示产品被下单 - /*->whereDoesntHave('agentProductItem', function ($query) { 与代理商自营产品冲突,所以注释掉 - return $query->whereHas('product', function ($query) { - return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); - }); - })*/ + ->where(function ($query) { + $query->whereHas('product', function ($query) { + return $query->where([['stock', '>', 0], ['status', '=', ProductStatus::ON_SALE]]); + })->orWhere('product_id', 0); + }) ->first(); if (!$ap) { return $this->error('产品已下架或库存不足'); diff --git a/app/Models/AgentProduct.php b/app/Models/AgentProduct.php index 12a928d..b19004f 100644 --- a/app/Models/AgentProduct.php +++ b/app/Models/AgentProduct.php @@ -88,10 +88,10 @@ class AgentProduct extends BaseModel public static function list($agent_id) { return static::withoutGlobalScope('orderById') - ->whereDoesntHave('agentProductItem', function ($query) { - return $query->whereHas('product', function ($query) { - return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); - }); + ->where(function ($query) { + $query->whereHas('product', function ($query) { + return $query->where([['stock', '>', 0], ['status', '=', ProductStatus::ON_SALE]]); + })->orWhere('product_id', 0); }) ->where('stock', '>', 0)->where(['agent_id' => $agent_id, 'status' => ProductStatus::ON_SALE]) ->select('id', 'sale', 'product_id', 'price', 'original_price', 'title', 'pictures');