DealerDeliveryBillStatus::Pending, ]; protected $casts = [ 'status' => DealerDeliveryBillStatus::class, 'pay_way' => PayWay::class, 'pay_at' => 'datetime', ]; protected $fillable = [ 'sn', 'user_id', 'order_id', 'shipping_fee', 'remark', 'consignee_name', 'consignee_telephone', 'consignee_zone', 'consignee_address', 'pay_sn', 'pay_way', 'out_trade_no', 'pay_at', 'status', ]; /** * {@inheritdoc} */ protected static function booted() { parent::creating(function ($bill) { if ($bill->sn === null) { do { $bill->sn = serial_number(); } while (static::where('sn', $bill->sn)->exists()); } }); } public function user() { return $this->belongsTo(User::class, 'user_id'); } public function order() { return $this->hasOne(DealerOrder::class, 'order_id'); } public function payLogs() { return $this->morphMany(PayLog::class, 'payable'); } public function deliveryProducts() { return $this->hasMany(DealerDeliveryProduct::class, 'delivery_bill_id'); } public function isPending() { return $this->status === DealerDeliveryBillStatus::Pending; } }