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.

108 lines
2.4 KiB

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. class OrderMain extends Model
  8. {
  9. protected $table = 'lanzu_order_main';
  10. protected $fillable = [
  11. 'market_id',
  12. 'order_num',
  13. 'global_order_id',
  14. 'user_id',
  15. 'pay_type',
  16. 'type',
  17. 'order_type',
  18. 'shipping_type',
  19. 'money',
  20. 'total_money',
  21. 'services_money',
  22. 'coupon_money',
  23. 'delivery_money',
  24. 'state',
  25. 'pay_time',
  26. 'receive_time',
  27. 'delivery_time',
  28. 'complete_time',
  29. 'cancel_time',
  30. 'refund_time',
  31. 'tel',
  32. 'address',
  33. 'area',
  34. 'lat',
  35. 'lng',
  36. 'name',
  37. 'print_num',
  38. 'plat',
  39. 'refuse_refund_note',
  40. 'delivery_time_note',
  41. 'total_refund_note',
  42. 'note'
  43. ];
  44. protected $appends = [
  45. 'created_at_text',
  46. 'state_text',
  47. 'pay_time_text',
  48. 'pay_type_text',
  49. 'shipping_type_text',
  50. ];
  51. public function getCreatedAtTextAttribute()
  52. {
  53. return date('Y-m-d H:i:s', $this->attributes['created_at']);
  54. }
  55. public function getPayTimeTextAttribute()
  56. {
  57. return date('Y-m-d H:i:s', $this->attributes['pay_time']);
  58. }
  59. public function getStateTextAttribute()
  60. {
  61. return OrderState::getMessage($this->attributes['state']);
  62. }
  63. public function getPayTypeTextAttribute()
  64. {
  65. return Payment::getMessage($this->attributes['pay_type']);
  66. }
  67. public function getShippingTypeTextAttribute()
  68. {
  69. return Shipping::getMessage($this->attributes['shipping_type']);
  70. }
  71. public function market()
  72. {
  73. return $this->belongsTo(Market::class, 'market_id', 'id');
  74. }
  75. public function orders()
  76. {
  77. return $this->hasMany(Order::class, 'order_main_id', 'id');
  78. }
  79. public function orderGoods()
  80. {
  81. // firstKey是中间表联当前表的列,secondKey是远程表对应中间表的列,localKey是当前表关联中间表的列,secondLocalKey是中间表关联远程表的列
  82. return $this->hasManyThrough(
  83. OrderGoods::class,
  84. Order::class,
  85. 'order_main_id',
  86. 'order_id',
  87. 'id',
  88. 'id'
  89. );
  90. }
  91. public function user()
  92. {
  93. return $this->belongsTo(User::class, 'user_id', 'id');
  94. }
  95. }