Order.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace App\Models;
  3. use DateTimeInterface;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 外卖订单
  7. *
  8. * @property int $id 外卖订单id
  9. * @property string $order_sn 订单号
  10. * @property int $order_type 订单类型 1堂食订单 2打包订单
  11. * @property int $order_status 订单状态 1:待支付 2待接单 3拒单 4备餐中 5退款
  12. * @property int $m_id 买家id
  13. * @property int $shop_id 商户id
  14. * @property int|null $number 取餐码/序号
  15. * @property string|null $order_money 订单金额
  16. * @property string|null $pay_money 订单支付金额
  17. * @property int $goods_number 商品数量
  18. * @property int|null $table_number 桌号
  19. * @property int|null $diner_number 就餐人数
  20. * @property int $pay_type 支付类型1微信,1支付宝支付
  21. * @property string|null $pay_time 支付时间
  22. * @property string|null $pay_code 支付流水号
  23. * @property string|null $note 订单备注
  24. * @property int|null $is_del 是否删除 0否1是
  25. * @property \Illuminate\Support\Carbon|null $created_at
  26. * @property \Illuminate\Support\Carbon|null $updated_at
  27. * @property string|null $pack_price 打包费
  28. * @property string|null $shop_money 商家到账金额
  29. * @property string $service_num 平台交易手续费比例
  30. * @property string|null $service_money 交易手续费
  31. * @method static \Illuminate\Database\Eloquent\Builder|Order newModelQuery()
  32. * @method static \Illuminate\Database\Eloquent\Builder|Order newQuery()
  33. * @method static \Illuminate\Database\Eloquent\Builder|Order query()
  34. * @method static \Illuminate\Database\Eloquent\Builder|Order whereCreatedAt($value)
  35. * @method static \Illuminate\Database\Eloquent\Builder|Order whereDinerNumber($value)
  36. * @method static \Illuminate\Database\Eloquent\Builder|Order whereGoodsNumber($value)
  37. * @method static \Illuminate\Database\Eloquent\Builder|Order whereId($value)
  38. * @method static \Illuminate\Database\Eloquent\Builder|Order whereIsDel($value)
  39. * @method static \Illuminate\Database\Eloquent\Builder|Order whereMId($value)
  40. * @method static \Illuminate\Database\Eloquent\Builder|Order whereNote($value)
  41. * @method static \Illuminate\Database\Eloquent\Builder|Order whereNumber($value)
  42. * @method static \Illuminate\Database\Eloquent\Builder|Order whereOrderMoney($value)
  43. * @method static \Illuminate\Database\Eloquent\Builder|Order whereOrderSn($value)
  44. * @method static \Illuminate\Database\Eloquent\Builder|Order whereOrderStatus($value)
  45. * @method static \Illuminate\Database\Eloquent\Builder|Order whereOrderType($value)
  46. * @method static \Illuminate\Database\Eloquent\Builder|Order wherePackPrice($value)
  47. * @method static \Illuminate\Database\Eloquent\Builder|Order wherePayCode($value)
  48. * @method static \Illuminate\Database\Eloquent\Builder|Order wherePayMoney($value)
  49. * @method static \Illuminate\Database\Eloquent\Builder|Order wherePayTime($value)
  50. * @method static \Illuminate\Database\Eloquent\Builder|Order wherePayType($value)
  51. * @method static \Illuminate\Database\Eloquent\Builder|Order whereServiceMoney($value)
  52. * @method static \Illuminate\Database\Eloquent\Builder|Order whereServiceNum($value)
  53. * @method static \Illuminate\Database\Eloquent\Builder|Order whereShopId($value)
  54. * @method static \Illuminate\Database\Eloquent\Builder|Order whereShopMoney($value)
  55. * @method static \Illuminate\Database\Eloquent\Builder|Order whereTableNumber($value)
  56. * @method static \Illuminate\Database\Eloquent\Builder|Order whereUpdatedAt($value)
  57. * @mixin \Eloquent
  58. */
  59. class Order extends Model
  60. {
  61. /**
  62. * The table associated with the model.
  63. *
  64. * @var string
  65. */
  66. protected $table = 'order';
  67. /**
  68. * The primary key associated with the table.
  69. *
  70. * @var string
  71. */
  72. protected $primaryKey = 'id';
  73. /**
  74. * Indicates if the model should be timestamped.
  75. *
  76. * @var bool
  77. */
  78. public $timestamps = true;
  79. /**
  80. * 类型转换
  81. *
  82. * @var array
  83. */
  84. protected $casts = [
  85. 'shopping_cart' => 'array',
  86. ];
  87. /**
  88. * 不能被批量赋值的属性
  89. *
  90. * @var array
  91. */
  92. protected $guarded = ['id', 'updated_at', 'created_at'];
  93. private $orderStatusEnum=[
  94. 1=>'待支付',
  95. 2=>'已完成',
  96. 3=>'已取消',
  97. 4=>'退款',
  98. ];
  99. private $refundStatusEnum=[
  100. 1=>'等待商家同意',
  101. 2=>'退款成功',
  102. 3=>'拒绝退款',
  103. ];
  104. private $payTypeEnum=[
  105. 1=>'微信',
  106. 2=>'支付宝',
  107. 3=>'余额支付',
  108. ];
  109. private $orderTypeEnum=[
  110. 1=>'堂食订单',
  111. 2=>'打包订单',
  112. ];
  113. /**
  114. * 为数组 / JSON 序列化准备日期。
  115. *
  116. * @param DateTimeInterface $date
  117. * @return string
  118. */
  119. protected function serializeDate(DateTimeInterface $date)
  120. {
  121. return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
  122. }
  123. /**
  124. * 序列化数据字典
  125. */
  126. function initializeModel(){
  127. if($this->{'order_status'}!==null){
  128. $this->{'order_status_str'}=empty($this->orderStatusEnum[$this->{'order_status'}])?'无':$this->orderStatusEnum[$this->{'order_status'}];
  129. }
  130. if($this->{'pay_type'}!==null){
  131. $this->{'pay_type_str'}=empty($this->payTypeEnum[$this->{'pay_type'}])?'无':$this->payTypeEnum[$this->{'pay_type'}];
  132. }
  133. if($this->{'order_type'}!==null){
  134. $this->{'order_type_str'}=empty($this->orderTypeEnum[$this->{'order_type'}])?'无':$this->orderTypeEnum[$this->{'order_type'}];
  135. }
  136. }
  137. }