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.

73 lines
1.7 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 $appends = [
  11. 'created_at_text',
  12. 'state_text',
  13. 'pay_time_text',
  14. 'pay_type_text',
  15. 'shipping_type_text',
  16. ];
  17. public function getCreatedAtTextAttribute()
  18. {
  19. return date('Y-m-d H:i:s', $this->attributes['created_at']);
  20. }
  21. public function getPayTimeTextAttribute()
  22. {
  23. return date('Y-m-d H:i:s', $this->attributes['time_pay']);
  24. }
  25. public function getStateTextAttribute()
  26. {
  27. return OrderState::getMessage($this->attributes['state']);
  28. }
  29. public function getPayTypeTextAttribute()
  30. {
  31. return Payment::getMessage($this->attributes['pay_type']);
  32. }
  33. public function getShippingTypeTextAttribute()
  34. {
  35. return Shipping::getMessage($this->attributes['shipping_type']);
  36. }
  37. public function market()
  38. {
  39. return $this->belongsTo(Market::class, 'market_id', 'id');
  40. }
  41. public function orders()
  42. {
  43. return $this->hasMany(Order::class, 'order_main_id', 'id');
  44. }
  45. public function orderGoods()
  46. {
  47. // firstKey是中间表联当前表的列,secondKey是远程表对应中间表的列,localKey是当前表关联中间表的列,secondLocalKey是中间表关联远程表的列
  48. return $this->hasManyThrough(
  49. OrderGoods::class,
  50. Order::class,
  51. 'order_main_id',
  52. 'order_id',
  53. 'id',
  54. 'id'
  55. );
  56. }
  57. public function user()
  58. {
  59. return $this->belongsTo(User::class, 'user_id', 'id');
  60. }
  61. }