0, 'status' => self::STATUS_PENDING, ]; /** * @var array */ protected $casts = [ 'completed_at' => 'datetime', ]; /** * @var array */ protected $fillable = [ 'user_id', 'sn', 'coupon_disount_amount', 'vip_disount_amount', 'reduced_amount', 'shipping_fee', 'products_total_amount', 'total_amount', 'note', 'remark', 'pay_sn', 'pay_way', 'pay_at', 'consignee_name', 'consignee_telephone', 'consignee_zone', 'consignee_address', 'status', 'completed_at', ]; /** * 属于此订单的商品 */ public function products() { return $this->hasMany(OrderProduct::class); } /** * 确认此订单是否可以被确认 * * @return bool */ public function isConfirmable(): bool { return in_array($this->status, [static::STATUS_PAID, static::STATUS_SHIPPED]); } /** * 确认此订单是否可以被取消 * * @return bool */ public function isCancelable(): bool { return in_array($this->status, [static::STATUS_PENDING, static::STATUS_PAID]); } /** * 获取订单支付金额 * * @return string */ public function getTotalAmountFormatAttribute() { return Numeric::trimTrailingZero(bcdiv($this->attributes['total_amount'], 100, 2)); } /** * 待支付订单过期时间 * * @return int */ public function getExpiresAtAttribute() { // todo 待支付订单过期时间 return 3600; } }