Browse Source

增加演示产品

develop
李可松 4 years ago
parent
commit
4fb2e79a62
  1. 18
      app/Http/Controllers/Api/AgentProductController.php
  2. 10
      app/Http/Controllers/Api/OrderController.php
  3. 2
      app/Models/AgentProduct.php

18
app/Http/Controllers/Api/AgentProductController.php

@ -135,14 +135,20 @@ class AgentProductController extends Controller
//分页列表产品图片加域名
private function paginatePicAddHost($list)
{
if (!$list->isEmpty()) {
$prefix = Storage::disk('public')->url('');
foreach ($list->items() as $k=>&$v) {
$v->pictures = array_map(function($item) use ($prefix) {
return strpos($item, $prefix) === false ? $prefix . $item : $item;
}, $v->pictures);
//如果是新入驻代理商没有数据,则显示最早的几条
if ($list->isEmpty()) {
if (AgentProduct::list($this->agent_id)->count() === 0) {
$list = AgentProduct::list($this->agent_id)->orWhereRaw(1)->orderBy('id')->simplePaginate();
}
}
$prefix = Storage::disk('public')->url('');
foreach ($list->items() as $k=>&$v) {
$v->pictures = array_map(function($item) use ($prefix) {
return strpos($item, $prefix) === false ? $prefix . $item : $item;
}, $v->pictures);
}
return $list;
}

10
app/Http/Controllers/Api/OrderController.php

@ -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('产品已下架或库存不足');

2
app/Models/AgentProduct.php

@ -97,7 +97,7 @@ class AgentProduct extends BaseModel
return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE);
});
})
->where(['agent_id' => $agent_id, 'status' => ProductStatus::ON_SALE])->where('stock', '>', 0)
->where('stock', '>', 0)->where(['agent_id' => $agent_id, 'status' => ProductStatus::ON_SALE])
->select('id', 'sale', 'product_id', 'price', 'original_price', 'title', 'pictures');
}

Loading…
Cancel
Save