| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Models;
- use DateTimeInterface;
- use Illuminate\Database\Eloquent\Model;
- /**
- * 外卖订单
- */
- class Order extends Model
- {
- /**
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'order';
- /**
- * The primary key associated with the table.
- *
- * @var string
- */
- protected $primaryKey = 'id';
- /**
- * Indicates if the model should be timestamped.
- *
- * @var bool
- */
- public $timestamps = true;
- /**
- * 不能被批量赋值的属性
- *
- * @var array
- */
- protected $guarded = ['id', 'updated_at', 'created_at'];
- private $orderStatusEnum=[
- 1=>'待支付',
- 2=>'制作中',
- 3=>'已完成',
- 4=>'已取消',
- 5=>'退款',
- ];
- private $refundStatusEnum=[
- 1=>'等待商家同意',
- 2=>'退款成功',
- 3=>'拒绝退款',
- ];
- private $payTypeEnum=[
- 1=>'微信',
- 2=>'支付宝',
- 3=>'余额支付',
- ];
- private $orderTypeEnum=[
- 1=>'堂食订单',
- 2=>'打包订单',
- ];
- /**
- * 为数组 / JSON 序列化准备日期。
- *
- * @param DateTimeInterface $date
- * @return string
- */
- protected function serializeDate(DateTimeInterface $date)
- {
- return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
- }
- /**
- * 序列化数据字典
- */
- function initializeModel(){
- if($this->{'order_status'}!==null){
- $this->{'order_status_str'}=empty($this->orderStatusEnum[$this->{'order_status'}])?'无':$this->orderStatusEnum[$this->{'order_status'}];
- }
- if($this->{'pay_type'}!==null){
- $this->{'pay_type_str'}=empty($this->payTypeEnum[$this->{'pay_type'}])?'无':$this->payTypeEnum[$this->{'pay_type'}];
- }
- if($this->{'order_type'}!==null){
- $this->{'order_type_str'}=empty($this->orderTypeEnum[$this->{'order_type'}])?'无':$this->orderTypeEnum[$this->{'order_type'}];
- }
- }
- }
|