|
|
|
@ -132,10 +132,14 @@ class OrderController extends Controller |
|
|
|
]); |
|
|
|
|
|
|
|
$ap = AgentProduct::query() |
|
|
|
->where(['id' => $formData['id'], 'status' => ProductStatus::ON_SALE]) |
|
|
|
->where('stock', '>=', $formData['num']) |
|
|
|
->with(['coupon', 'product', 'agentCloudProduct:id,price']) |
|
|
|
->has('product') |
|
|
|
->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); |
|
|
|
}); |
|
|
|
}) |
|
|
|
->first(); |
|
|
|
if (!$ap || !$ap->product) { |
|
|
|
return $this->error('产品已下架或库存不足'); |
|
|
|
|