You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Model\v3;
  3. use App\Constants\v3\OrderState;
  4. use App\Constants\v3\Payment;
  5. use App\Constants\v3\Shipping;
  6. use App\Model\Model;
  7. use Hyperf\Database\Model\SoftDeletes;
  8. class OrderMain extends Model
  9. {
  10. use SoftDeletes;
  11. protected $table = 'lanzu_order_main';
  12. protected $guarded = [];
  13. // protected $fillable = [
  14. // 'market_id',
  15. // 'order_num',
  16. // 'global_order_id',
  17. // 'user_id',
  18. // 'pay_type',
  19. // 'type',
  20. // 'order_type',
  21. // 'shipping_type',
  22. // 'money',
  23. // 'total_money',
  24. // 'services_money',
  25. // 'coupon_money',
  26. // 'delivery_money',
  27. // 'state',
  28. // 'pay_time',
  29. // 'receive_time',
  30. // 'delivery_time',
  31. // 'complete_time',
  32. // 'cancel_time',
  33. // 'refund_time',
  34. // 'tel',
  35. // 'address',
  36. // 'area',
  37. // 'lat',
  38. // 'lng',
  39. // 'name',
  40. // 'print_num',
  41. // 'plat',
  42. // 'refuse_refund_note',
  43. // 'delivery_time_note',
  44. // 'total_refund_note',
  45. // 'note',
  46. // 'delivery_distance'
  47. // ];
  48. protected $appends = [
  49. 'created_at_text',
  50. 'state_text',
  51. 'pay_time_text',
  52. 'pay_type_text',
  53. 'shipping_type_text',
  54. 'complete_time_text'
  55. ];
  56. protected $casts = [
  57. 'global_order_id' => 'string'
  58. ];
  59. public function getCreatedAtTextAttribute()
  60. {
  61. return date('Y-m-d H:i:s', $this->attributes['created_at']);
  62. }
  63. public function getPayTimeTextAttribute()
  64. {
  65. return date('Y-m-d H:i:s', $this->attributes['pay_time']);
  66. }
  67. public function getCompleteTimeTextAttribute()
  68. {
  69. return date('Y-m-d H:i:s', $this->attributes['complete_time']);
  70. }
  71. public function getStateTextAttribute()
  72. {
  73. if ($this->attributes['state'] == OrderState::DELIVERY) {
  74. if($this->attributes['shipping_type'] == 3) {
  75. return '待自提';
  76. }elseif ($this->attributes['shipping_type'] == 1 && empty($this->attributes['horseman_id'])){
  77. return '已接单';
  78. }
  79. }
  80. return OrderState::getMessage($this->attributes['state']);
  81. }
  82. public function getPayTypeTextAttribute()
  83. {
  84. return Payment::getMessage($this->attributes['pay_type']);
  85. }
  86. public function getShippingTypeTextAttribute()
  87. {
  88. return Shipping::getMessage($this->attributes['shipping_type']);
  89. }
  90. public function getNoteAttribute($value)
  91. {
  92. if ($this->attributes['refuse_refund_note'] || $this->attributes['total_refund_note']) {
  93. return $this->attributes['refuse_refund_note'] ?: $this->attributes['total_refund_note'];
  94. }
  95. return $value;
  96. }
  97. public function market()
  98. {
  99. return $this->belongsTo(Market::class, 'market_id', 'id');
  100. }
  101. public function orders()
  102. {
  103. return $this->hasMany(Order::class, 'order_main_id', 'global_order_id');
  104. }
  105. public function orderGoods()
  106. {
  107. // firstKey是中间表联当前表的列,secondKey是远程表对应中间表的列,localKey是当前表关联中间表的列,secondLocalKey是中间表关联远程表的列
  108. return $this->hasManyThrough(
  109. OrderGoods::class,
  110. Order::class,
  111. 'order_main_id',
  112. 'order_id',
  113. 'global_order_id',
  114. 'id'
  115. );
  116. }
  117. public function user()
  118. {
  119. return $this->belongsTo(User::class, 'user_id', 'id');
  120. }
  121. public function employees()
  122. {
  123. return $this->belongsTo(Employees::class, 'horseman_id', 'id');
  124. }
  125. }