|
|
@ -59,6 +59,11 @@ class AgentProductController extends Controller |
|
|
$id = (int)request()->input('id'); |
|
|
$id = (int)request()->input('id'); |
|
|
|
|
|
|
|
|
// TODO 优惠券查询待优化
|
|
|
// TODO 优惠券查询待优化
|
|
|
|
|
|
if (AgentProduct::withTrashed()->where('agent_id', $this->agent_id)->count() === 0) { //演示产品用
|
|
|
|
|
|
$where = ['id' => $id, 'agent_id' => $this->agent_id, 'status' => ProductStatus::ON_SALE]; |
|
|
|
|
|
} else { |
|
|
|
|
|
$where = ['id' => $id, 'status' => ProductStatus::ON_SALE]; |
|
|
|
|
|
} |
|
|
$agent_product = AgentProduct::query() |
|
|
$agent_product = AgentProduct::query() |
|
|
->with(['coupon:tag,agent_product_id']) |
|
|
->with(['coupon:tag,agent_product_id']) |
|
|
->whereDoesntHave('agentProductItem', function ($query) { |
|
|
->whereDoesntHave('agentProductItem', function ($query) { |
|
|
@ -67,7 +72,7 @@ class AgentProductController extends Controller |
|
|
}); |
|
|
}); |
|
|
}) |
|
|
}) |
|
|
->where('stock', '>', 0) |
|
|
->where('stock', '>', 0) |
|
|
->firstWhere(['id' => $id, 'agent_id' => $this->agent_id, 'status' => ProductStatus::ON_SALE]); |
|
|
|
|
|
|
|
|
->firstWhere($where); |
|
|
|
|
|
|
|
|
if (!$agent_product) { |
|
|
if (!$agent_product) { |
|
|
return $this->error('产品已下架或库存不足'); |
|
|
return $this->error('产品已下架或库存不足'); |
|
|
@ -142,7 +147,7 @@ class AgentProductController extends Controller |
|
|
//如果是新入驻代理商没有数据,且没有删除过的数据,则显示最早的几条
|
|
|
//如果是新入驻代理商没有数据,且没有删除过的数据,则显示最早的几条
|
|
|
if ($list->isEmpty()) { |
|
|
if ($list->isEmpty()) { |
|
|
if (AgentProduct::list($this->agent_id)->withTrashed()->count() === 0 && request('page', 1) <= 2) { //只获取2页数据
|
|
|
if (AgentProduct::list($this->agent_id)->withTrashed()->count() === 0 && request('page', 1) <= 2) { //只获取2页数据
|
|
|
$list = AgentProduct::list($this->agent_id)->orWhere([['status', '=', ProductStatus::ON_SALE], ['price', '>', 100]])->orderBy('id')->simplePaginate(); |
|
|
|
|
|
|
|
|
$list = AgentProduct::list($this->agent_id)->orWhere([['status', '=', ProductStatus::ON_SALE], ['price', '>', 500]])->orderBy('id')->simplePaginate(); |
|
|
} else { |
|
|
} else { |
|
|
return $list; //因为只获取2页数据,不return可能会导入下面的代码出错
|
|
|
return $list; //因为只获取2页数据,不return可能会导入下面的代码出错
|
|
|
} |
|
|
} |
|
|
|