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.

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