Browse Source

收藏判断逻辑修改

develop
李可松 4 years ago
parent
commit
99a76f4c46
  1. 10
      app/Http/Controllers/Api/AgentProductController.php

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

@ -60,7 +60,7 @@ class AgentProductController extends Controller
// TODO 优惠券查询待优化
$agent_product = AgentProduct::query()
->with(['coupon:tag,agent_product_id', 'fav:agent_product_id'])
->with(['coupon:tag,agent_product_id'])
->whereDoesntHave('agentProductItem', function ($query) {
return $query->whereHas('product', function ($query) {
return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE);
@ -76,8 +76,12 @@ class AgentProductController extends Controller
$prefix = Storage::disk('public')->url('');
$agent_product->pictures = array_map(fn($item) => ($prefix . $item), $agent_product->pictures);
$agent_product->is_collect = !is_null($agent_product->fav); //判断是否收藏
unset($agent_product->fav);
if ($this->user_id) {
$agent_product->is_collect = UserFav::query()->where(['user_id' => $this->user_id, 'agent_product_id' => $id])->exists() ? 1 : 0; //判断是否收藏
} else {
$agent_product->is_collect = 0;
}
//计算折扣
if ($agent_product->price < $agent_product->original_price) {
$agent_product->cost = round($agent_product->price / $agent_product->original_price * 10, 1);

Loading…
Cancel
Save