DdriveSfOrder.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class DdriveSfOrder extends Model
  5. {
  6. // 表名
  7. protected $name = 'ddrive_sf_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'order_type_text',
  17. 'start_time_text',
  18. 'status_text',
  19. 'cancel_type_text',
  20. 'assess_text',
  21. 'pay_type_text',
  22. 'pay_time_text',
  23. 'pay_status_text',
  24. 'cancel_time_text'
  25. ];
  26. public function getOrderTypeList()
  27. {
  28. return ['1' => __('Order_type 1'), '2' => __('Order_type 2')];
  29. }
  30. public function getStatusList()
  31. {
  32. return ['-2' => __('Status -2'), '-1' => __('Status -1'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5')];
  33. }
  34. public function getCancelTypeList()
  35. {
  36. 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')];
  37. }
  38. public function getAssessList()
  39. {
  40. return ['0' => __('Assess 0'), '1' => __('Assess 1')];
  41. }
  42. public function getPayTypeList()
  43. {
  44. return ['1' => __('Pay_type 1'), '2' => __('Pay_type 2'), '3' => __('Pay_type 3')];
  45. }
  46. public function getPayStatusList()
  47. {
  48. return ['0' => __('Pay_status 0'), '1' => __('Pay_status 1')];
  49. }
  50. public function getOrderTypeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['order_type']) ? $data['order_type'] : '');
  53. $list = $this->getOrderTypeList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getStartTimeTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
  59. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  60. }
  61. public function getStatusTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  64. $list = $this->getStatusList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. public function getCancelTypeTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['cancel_type']) ? $data['cancel_type'] : '');
  70. $list = $this->getCancelTypeList();
  71. return isset($list[$value]) ? $list[$value] : '';
  72. }
  73. public function getAssessTextAttr($value, $data)
  74. {
  75. $value = $value ? $value : (isset($data['assess']) ? $data['assess'] : '');
  76. $list = $this->getAssessList();
  77. return isset($list[$value]) ? $list[$value] : '';
  78. }
  79. public function getPayTypeTextAttr($value, $data)
  80. {
  81. $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
  82. $list = $this->getPayTypeList();
  83. return isset($list[$value]) ? $list[$value] : '';
  84. }
  85. public function getPayTimeTextAttr($value, $data)
  86. {
  87. $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
  88. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  89. }
  90. public function getPayStatusTextAttr($value, $data)
  91. {
  92. $value = $value ? $value : (isset($data['pay_status']) ? $data['pay_status'] : '');
  93. $list = $this->getPayStatusList();
  94. return isset($list[$value]) ? $list[$value] : '';
  95. }
  96. public function getCancelTimeTextAttr($value, $data)
  97. {
  98. $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
  99. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  100. }
  101. protected function setStartTimeAttr($value)
  102. {
  103. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  104. }
  105. protected function setPayTimeAttr($value)
  106. {
  107. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  108. }
  109. protected function setCancelTimeAttr($value)
  110. {
  111. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  112. }
  113. public function user()
  114. {
  115. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->field('username,mobile')->setEagerlyType(0);
  116. }
  117. public function driver()
  118. {
  119. return $this->belongsTo('User', 'other_user_id', 'id', [], 'LEFT')->field('username,mobile')->setEagerlyType(0);
  120. }
  121. }