6
0
Fork 0
release
panliang 2022-06-10 15:52:46 +08:00
parent 8cddb906f5
commit 27940e16d0
2 changed files with 4 additions and 7 deletions

View File

@ -14,6 +14,8 @@ class ProduckSkuResource extends JsonResource
*/
public function toArray($request)
{
// 商品处于预售状态, 不限制库存
$is_pre_sale = $this->spu->is_pre_sale || $this->is_pre_sale;
return [
'id' => $this->id,
'name' => $this->name,
@ -27,7 +29,7 @@ class ProduckSkuResource extends JsonResource
'sales' => $this->sales,
'description' => (string) $this->description,
'attrs' => $this->attrs,
'stock' => $this->saleable_stock,
'stock' => $this->when($is_pre_sale, 9999, $this->saleable_stock),
'weight' => (int) $this->weight,
'is_online' => $this->isOnline(),
'buynote' => (string) $this->when($this->relationLoaded('buynote'), function () {
@ -36,7 +38,7 @@ class ProduckSkuResource extends JsonResource
'growth_value' => (int) $this->growth_value,
'sales_value' => (int) $this->sales_value,
'is_bargaing' => $this->isBargaing() ? true : false,
'is_pre_sale' => !!$this->is_pre_sale,
'is_pre_sale' => !!$is_pre_sale,
];
}
}

View File

@ -160,11 +160,6 @@ class ProductSku extends Model
*/
public function getSaleableStockAttribute(): int
{
// 商品处于预售状态, 不限制库存
$is_pre_sale = $this->spu->is_pre_sale || $this->is_pre_sale;
if ($is_pre_sale) {
return 9999;
}
if ($this->isOnline()) {
return $this->attributes['stock'];
}