|
|
@ -60,7 +60,7 @@ class AgentProductController extends Controller |
|
|
|
|
|
|
|
|
// TODO 优惠券查询待优化
|
|
|
// TODO 优惠券查询待优化
|
|
|
$agent_product = AgentProduct::query() |
|
|
$agent_product = AgentProduct::query() |
|
|
->with(['coupon:tag,agent_product_id', 'fav:agent_product_id']) |
|
|
|
|
|
|
|
|
->with(['coupon:tag,agent_product_id']) |
|
|
->whereDoesntHave('agentProductItem', function ($query) { |
|
|
->whereDoesntHave('agentProductItem', function ($query) { |
|
|
return $query->whereHas('product', function ($query) { |
|
|
return $query->whereHas('product', function ($query) { |
|
|
return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); |
|
|
return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); |
|
|
@ -76,8 +76,12 @@ class AgentProductController extends Controller |
|
|
$prefix = Storage::disk('public')->url(''); |
|
|
$prefix = Storage::disk('public')->url(''); |
|
|
$agent_product->pictures = array_map(fn($item) => ($prefix . $item), $agent_product->pictures); |
|
|
$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) { |
|
|
if ($agent_product->price < $agent_product->original_price) { |
|
|
$agent_product->cost = round($agent_product->price / $agent_product->original_price * 10, 1); |
|
|
$agent_product->cost = round($agent_product->price / $agent_product->original_price * 10, 1); |
|
|
|