DdriveHyOrder.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class DdriveHyOrder extends Model
  5. {
  6. // 表名
  7. protected $name = 'ddrive_hy_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'appointment_time_text',
  18. 'status_text',
  19. 'cancel_type_text',
  20. 'comment_status_text',
  21. 'complete_time_text',
  22. 'fail_time_text',
  23. 'pay_type_text',
  24. 'pay_method_text',
  25. 'pay_time_text'
  26. ];
  27. public function getTypeList()
  28. {
  29. return ['1' => __('Type 1'), '2' => __('Type 2')];
  30. }
  31. public function getStatusList()
  32. {
  33. return ['-2' => __('Status -2'), '-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '99' => __('Status 99'), '7' => __('Status 7')];
  34. }
  35. public function getCancelTypeList()
  36. {
  37. return [' 1' => __('Cancel_type 1'), '2' => __('Cancel_type 2'), '3' => __('Cancel_type 3'), '4' => __('Cancel_type 4'), '5' => __('Cancel_type 5'), '6' => __('Cancel_type 6'), '7' => __('Cancel_type 7'), '8' => __('Cancel_type 8'), '9' => __('Cancel_type 9'), '10' => __('Cancel_type 10'), '11' => __('Cancel_type 11'), '12' => __('Cancel_type 12')];
  38. }
  39. public function getCommentStatusList()
  40. {
  41. return ['0' => __('Comment_status 0'), '1' => __('Comment_status 1')];
  42. }
  43. public function getPayTypeList()
  44. {
  45. return ['1' => __('Pay_type 1'), '2' => __('Pay_type 2'), '3' => __('Pay_type 3')];
  46. }
  47. public function getPayMethodList()
  48. {
  49. return ['1' => __('Pay_method 1'), '2' => __('Pay_method 2')];
  50. }
  51. public function getTypeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  54. $list = $this->getTypeList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. public function getAppointmentTimeTextAttr($value, $data)
  58. {
  59. $value = $value ? $value : (isset($data['appointment_time']) ? $data['appointment_time'] : '');
  60. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  61. }
  62. public function getStatusTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  65. $list = $this->getStatusList();
  66. return isset($list[$value]) ? $list[$value] : '';
  67. }
  68. public function getCancelTypeTextAttr($value, $data)
  69. {
  70. $value = $value ? $value : (isset($data['cancel_type']) ? $data['cancel_type'] : '');
  71. $list = $this->getCancelTypeList();
  72. return isset($list[$value]) ? $list[$value] : '';
  73. }
  74. public function getCommentStatusTextAttr($value, $data)
  75. {
  76. $value = $value ? $value : (isset($data['comment_status']) ? $data['comment_status'] : '');
  77. $list = $this->getCommentStatusList();
  78. return isset($list[$value]) ? $list[$value] : '';
  79. }
  80. public function getCompleteTimeTextAttr($value, $data)
  81. {
  82. $value = $value ? $value : (isset($data['complete_time']) ? $data['complete_time'] : '');
  83. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  84. }
  85. public function getFailTimeTextAttr($value, $data)
  86. {
  87. $value = $value ? $value : (isset($data['fail_time']) ? $data['fail_time'] : '');
  88. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  89. }
  90. public function getPayTypeTextAttr($value, $data)
  91. {
  92. $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
  93. $list = $this->getPayTypeList();
  94. return isset($list[$value]) ? $list[$value] : '';
  95. }
  96. public function getPayMethodTextAttr($value, $data)
  97. {
  98. $value = $value ? $value : (isset($data['pay_method']) ? $data['pay_method'] : '');
  99. $list = $this->getPayMethodList();
  100. return isset($list[$value]) ? $list[$value] : '';
  101. }
  102. public function getPayTimeTextAttr($value, $data)
  103. {
  104. $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
  105. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  106. }
  107. protected function setAppointmentTimeAttr($value)
  108. {
  109. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  110. }
  111. protected function setCompleteTimeAttr($value)
  112. {
  113. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  114. }
  115. protected function setFailTimeAttr($value)
  116. {
  117. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  118. }
  119. protected function setPayTimeAttr($value)
  120. {
  121. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  122. }
  123. public function user()
  124. {
  125. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->field('username,mobile')->setEagerlyType(0);
  126. }
  127. public function driver()
  128. {
  129. return $this->belongsTo('User', 'cargo_driver_id', 'id', [], 'LEFT')->field('username,mobile')->setEagerlyType(0);
  130. }
  131. public function car()
  132. {
  133. return $this->belongsTo('DdriveHyFreight', 'car_id', 'id', [], 'LEFT')->field('car_name')->setEagerlyType(0);
  134. }
  135. }