Order.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Models;
  3. use DateTimeInterface;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 外卖订单
  7. */
  8. class Order extends Model
  9. {
  10. /**
  11. * The table associated with the model.
  12. *
  13. * @var string
  14. */
  15. protected $table = 'order';
  16. /**
  17. * The primary key associated with the table.
  18. *
  19. * @var string
  20. */
  21. protected $primaryKey = 'id';
  22. /**
  23. * Indicates if the model should be timestamped.
  24. *
  25. * @var bool
  26. */
  27. public $timestamps = true;
  28. /**
  29. * 不能被批量赋值的属性
  30. *
  31. * @var array
  32. */
  33. protected $guarded = ['id', 'updated_at', 'created_at'];
  34. private $orderStatusEnum=[
  35. 1=>'待支付',
  36. 2=>'制作中',
  37. 3=>'已完成',
  38. 4=>'已取消',
  39. 5=>'退款',
  40. ];
  41. private $refundStatusEnum=[
  42. 1=>'等待商家同意',
  43. 2=>'退款成功',
  44. 3=>'拒绝退款',
  45. ];
  46. private $payTypeEnum=[
  47. 1=>'微信',
  48. 2=>'支付宝',
  49. 3=>'余额支付',
  50. ];
  51. private $orderTypeEnum=[
  52. 1=>'堂食订单',
  53. 2=>'打包订单',
  54. ];
  55. /**
  56. * 为数组 / JSON 序列化准备日期。
  57. *
  58. * @param DateTimeInterface $date
  59. * @return string
  60. */
  61. protected function serializeDate(DateTimeInterface $date)
  62. {
  63. return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
  64. }
  65. /**
  66. * 序列化数据字典
  67. */
  68. function initializeModel(){
  69. if($this->{'order_status'}!==null){
  70. $this->{'order_status_str'}=empty($this->orderStatusEnum[$this->{'order_status'}])?'无':$this->orderStatusEnum[$this->{'order_status'}];
  71. }
  72. if($this->{'pay_type'}!==null){
  73. $this->{'pay_type_str'}=empty($this->payTypeEnum[$this->{'pay_type'}])?'无':$this->payTypeEnum[$this->{'pay_type'}];
  74. }
  75. if($this->{'order_type'}!==null){
  76. $this->{'order_type_str'}=empty($this->orderTypeEnum[$this->{'order_type'}])?'无':$this->orderTypeEnum[$this->{'order_type'}];
  77. }
  78. }
  79. }