6
0
Fork 0

商品购买须知

release
李静 2021-12-11 16:22:34 +08:00
parent f88a9b0e5b
commit adc099d6f6
3 changed files with 12 additions and 1 deletions

View File

@ -43,7 +43,7 @@ class ProductSkuController extends Controller
{ {
$user = $request->user(); $user = $request->user();
$sku = ProductSku::findOrFail($id); $sku = ProductSku::with('buynote')->findOrFail($id);
// 是否收藏商品 // 是否收藏商品
$isCollected = (bool) $user?->skuFavorites()->where('sku_id', $sku->id)->exists(); $isCollected = (bool) $user?->skuFavorites()->where('sku_id', $sku->id)->exists();

View File

@ -29,6 +29,9 @@ class ProduckSkuResource extends JsonResource
'stock' => $this->saleable_stock, 'stock' => $this->saleable_stock,
'weight' => (int) $this->weight, 'weight' => (int) $this->weight,
'is_online' => $this->isOnline(), 'is_online' => $this->isOnline(),
'buynote' => (string) $this->when($this->relationLoaded('buynote'), function () {
return $this->buynote?->content;
}),
]; ];
} }
} }

View File

@ -98,6 +98,14 @@ class ProductSku extends Model
return $this->hasMany(ProductGift::class, 'sku_id'); return $this->hasMany(ProductGift::class, 'sku_id');
} }
/**
* 此商品的购买须知
*/
public function buynote()
{
return $this->belongsTo(ProductBuynote::class, 'buynote_id');
}
/** /**
* 确认此商品是否已上架 * 确认此商品是否已上架
* *