| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?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){
- if ($this->{'order_status'} == 8){
- $this->{'order_status_str'}=empty($this->refundStatusEnum[$this->{'refund_status'}])?'无':$this->refundStatusEnum[$this->{'refund_status'}];
- }else{
- $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'}];
- }
- }
- }
|