67 lines
1.2 KiB
PHP
67 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class OrderProduct extends Model
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'specs' => 'json',
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'user_id',
|
|
'order_id',
|
|
'spu_id',
|
|
'sku_id',
|
|
'category_id',
|
|
'name',
|
|
'specs',
|
|
'cover',
|
|
'weight',
|
|
'sell_price',
|
|
'vip_price',
|
|
'quantity',
|
|
'coupon_discount_amount',
|
|
'vip_discount_amount',
|
|
'reduced_amount',
|
|
'total_amount',
|
|
];
|
|
|
|
public function packageProducts()
|
|
{
|
|
return $this->hasMany(OrderPackageProduct::class, 'order_product_id');
|
|
}
|
|
|
|
/**
|
|
* 获取订单商品销售价格
|
|
*
|
|
* @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);
|
|
}
|
|
}
|