Order.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Order extends Model
  5. {
  6. // 表名
  7. protected $table = 'order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'paytime_text',
  18. 'roadtype_text',
  19. 'cancle_time_text',
  20. 'refund_time_text',
  21. 'jxtype_text',
  22. 'go_chufatime_text',
  23. 'back_chufatime_text',
  24. 'finishtime_text'
  25. ];
  26. public function getStatusList()
  27. {
  28. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '10' => __('Status 10'), '21' => __('Status 21'), '22' => __('Status 22')];
  29. }
  30. public function getRoadtypeList()
  31. {
  32. return ['1' => __('Roadtype 1'), '2' => __('Roadtype 2'), '3' => __('Roadtype 3')];
  33. }
  34. public function getJxtypeList()
  35. {
  36. return ['0' => __('Jxtype 0'), '1' => __('Jxtype 1')];
  37. }
  38. public function getStatusTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  41. $list = $this->getStatusList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getPaytimeTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  47. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  48. }
  49. public function getRoadtypeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['roadtype']) ? $data['roadtype'] : '');
  52. $list = $this->getRoadtypeList();
  53. return isset($list[$value]) ? $list[$value] : '';
  54. }
  55. public function getCancleTimeTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['cancle_time']) ? $data['cancle_time'] : '');
  58. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  59. }
  60. public function getRefundTimeTextAttr($value, $data)
  61. {
  62. $value = $value ? $value : (isset($data['refund_time']) ? $data['refund_time'] : '');
  63. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  64. }
  65. public function getJxtypeTextAttr($value, $data)
  66. {
  67. $value = $value ? $value : (isset($data['jxtype']) ? $data['jxtype'] : '');
  68. $list = $this->getJxtypeList();
  69. return isset($list[$value]) ? $list[$value] : '';
  70. }
  71. public function getGoChufatimeTextAttr($value, $data)
  72. {
  73. $value = $value ? $value : (isset($data['go_chufatime']) ? $data['go_chufatime'] : '');
  74. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  75. }
  76. public function getBackChufatimeTextAttr($value, $data)
  77. {
  78. $value = $value ? $value : (isset($data['back_chufatime']) ? $data['back_chufatime'] : '');
  79. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  80. }
  81. public function getFinishtimeTextAttr($value, $data)
  82. {
  83. $value = $value ? $value : (isset($data['finishtime']) ? $data['finishtime'] : '');
  84. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  85. }
  86. protected function setPaytimeAttr($value)
  87. {
  88. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  89. }
  90. protected function setCancleTimeAttr($value)
  91. {
  92. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  93. }
  94. protected function setRefundTimeAttr($value)
  95. {
  96. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  97. }
  98. protected function setGoChufatimeAttr($value)
  99. {
  100. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  101. }
  102. protected function setBackChufatimeAttr($value)
  103. {
  104. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  105. }
  106. protected function setFinishtimeAttr($value)
  107. {
  108. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  109. }
  110. public function product()
  111. {
  112. return $this->belongsTo('Product', 'product_id', 'id', [], 'LEFT')->setEagerlyType(0);
  113. }
  114. public function usera()
  115. {
  116. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  117. }
  118. public function userb()
  119. {
  120. return $this->belongsTo('User', 'share_uid', 'id', [], 'LEFT')->setEagerlyType(0);
  121. }
  122. }