优化商品
parent
df55b1b90e
commit
4811472d88
|
|
@ -46,24 +46,12 @@ class ProductSkuController extends Controller
|
||||||
if (! $sku->isOnline()) {
|
if (! $sku->isOnline()) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'spu_specs' => [],
|
'spu_specs' => [],
|
||||||
'sku' => array_merge(ProduckSkuResource::make($sku)->resolve(), [
|
'sku' => ProduckSkuResource::make($sku),
|
||||||
'status' => ProductSku::STATUS_OFFLINE,
|
|
||||||
]),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$spu = ProductSpu::with('specs')->findOrFail($sku->spu_id);
|
$spu = ProductSpu::with('specs')->findOrFail($sku->spu_id);
|
||||||
|
|
||||||
// 如果商品已失效
|
|
||||||
if (! $spu->isValidProductSku($sku)) {
|
|
||||||
return response()->json([
|
|
||||||
'spu_specs' => [],
|
|
||||||
'sku' => array_merge(ProduckSkuResource::make($sku)->resolve(), [
|
|
||||||
'status' => ProductSku::STATUS_INVALID,
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 主商品的规格
|
// 主商品的规格
|
||||||
$spuSpecs = [];
|
$spuSpecs = [];
|
||||||
|
|
||||||
|
|
@ -106,9 +94,7 @@ class ProductSkuController extends Controller
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'spu_specs' => $spuSpecs,
|
'spu_specs' => $spuSpecs,
|
||||||
'sku' => array_merge(ProduckSkuResource::make($sku)->resolve(), [
|
'sku' => ProduckSkuResource::make($sku),
|
||||||
'status' => ProductSku::STATUS_ONLINE,
|
|
||||||
]),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ class ProduckSkuResource extends JsonResource
|
||||||
'attrs' => $this->attrs,
|
'attrs' => $this->attrs,
|
||||||
'stock' => $this->saleable_stock,
|
'stock' => $this->saleable_stock,
|
||||||
'weight' => (int) $this->weight,
|
'weight' => (int) $this->weight,
|
||||||
|
'is_online' => $this->isOnline(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,6 @@ class ProductSku extends Model
|
||||||
use Release;
|
use Release;
|
||||||
use SkuInfo;
|
use SkuInfo;
|
||||||
|
|
||||||
public const STATUS_INVALID = -1; // 无效的
|
|
||||||
public const STATUS_ONLINE = 1; // 已上架
|
|
||||||
public const STATUS_OFFLINE = 2; // 已下架
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
@ -94,6 +90,14 @@ class ProductSku extends Model
|
||||||
return $this->belongsToMany(ProductPart::class, ProductPartSku::class, 'sku_id', 'part_id');
|
return $this->belongsToMany(ProductPart::class, ProductPartSku::class, 'sku_id', 'part_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此商品的赠品
|
||||||
|
*/
|
||||||
|
public function gifts()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProductGift::class, 'sku_id');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 确认此商品是否已上架
|
* 确认此商品是否已上架
|
||||||
*
|
*
|
||||||
|
|
@ -117,14 +121,4 @@ class ProductSku extends Model
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 此商品的赠品
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function gifts()
|
|
||||||
{
|
|
||||||
return $this->hasMany(ProductGift::class, 'sku_id');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue