Browse Source

增加extends字段

develop
李可松 4 years ago
parent
commit
63fb3d53d1
  1. 11
      app/Http/Controllers/Api/AgentProductController.php

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

@ -5,6 +5,7 @@ use App\Common\ProductStatus;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Advertising; use App\Models\Advertising;
use App\Models\AgentProduct; use App\Models\AgentProduct;
use App\Models\Product;
use App\Models\UserFav; use App\Models\UserFav;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
@ -59,8 +60,7 @@ class AgentProductController extends Controller
// TODO 优惠券查询待优化 // TODO 优惠券查询待优化
$agent_product = AgentProduct::query() $agent_product = AgentProduct::query()
->with('coupon:tag,agent_product_id')
->with('fav:agent_product_id')
->with(['coupon:tag,agent_product_id', 'fav: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);
@ -85,6 +85,13 @@ class AgentProductController extends Controller
$agent_product->cost = ''; $agent_product->cost = '';
} }
//如果是单品销售,显示附加信息字段,组合产品和组团产品不显示
if ($agent_product->type == 0) {
$agent_product->product = Product::query()->where('id', $agent_product->product_id)->first(['type', 'extends']);
} else {
$agent_product->product = null;
}
unset($agent_product->agent_id, $agent_product->status, $agent_product->deleted_at); unset($agent_product->agent_id, $agent_product->status, $agent_product->deleted_at);
return $this->success($agent_product); return $this->success($agent_product);
} }

Loading…
Cancel
Save