63 lines
1.0 KiB
PHP
63 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ShoppingCartItem extends Model
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'quantity' => 'int',
|
|
'specs' => 'json',
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'user_id',
|
|
'sku_id',
|
|
'name',
|
|
'cover',
|
|
'sell_price',
|
|
'vip_price',
|
|
'specs',
|
|
'quantity',
|
|
];
|
|
|
|
/**
|
|
* 此购物车物品所属的商品
|
|
*/
|
|
public function sku()
|
|
{
|
|
return $this->belongsTo(ProductSku::class);
|
|
}
|
|
|
|
/**
|
|
* 获取商品售价
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getSellPriceFormatAttribute()
|
|
{
|
|
return bcdiv($this->attributes['sell_price'], 100, 2);
|
|
}
|
|
|
|
/**
|
|
* 获取商品会员价
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getVipPriceFormatAttribute()
|
|
{
|
|
if (is_null($price = $this->attributes['vip_price'])) {
|
|
return '';
|
|
}
|
|
|
|
return bcdiv($price, 100, 2);
|
|
}
|
|
}
|