Order.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Order extends Model
  5. {
  6. // 表名
  7. protected $name = 'order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'ordertype_text',
  17. 'server_time_text',
  18. 'package_endtime_text',
  19. 'status_text',
  20. 'pay_time_text',
  21. 'paytype_text',
  22. 'hexiao_time_text',
  23. 'cancel_time_text',
  24. 'finish_time_text'
  25. ];
  26. public function getOrdertypeList()
  27. {
  28. return ['1' => __('Ordertype 1'), '2' => __('Ordertype 2'), '3' => __('Ordertype 3')];
  29. }
  30. public function getStatusList()
  31. {
  32. return ['1' => __('Status 1'),'2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4')];
  33. }
  34. public function getPaytypeList()
  35. {
  36. return ['1' => __('Paytype 1'), '2' => __('Paytype 2'), '3' => __('Paytype 3')];
  37. }
  38. public function getOrdertypeTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['ordertype']) ? $data['ordertype'] : '');
  41. $list = $this->getOrdertypeList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getServerTimeTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['server_time']) ? $data['server_time'] : '');
  47. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  48. }
  49. public function getPackageEndtimeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['package_endtime']) ? $data['package_endtime'] : '');
  52. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  53. }
  54. public function getStatusTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  57. $list = $this->getStatusList();
  58. return isset($list[$value]) ? $list[$value] : '';
  59. }
  60. public function getPayTimeTextAttr($value, $data)
  61. {
  62. $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
  63. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  64. }
  65. public function getPaytypeTextAttr($value, $data)
  66. {
  67. $value = $value ? $value : (isset($data['paytype']) ? $data['paytype'] : '');
  68. $list = $this->getPaytypeList();
  69. return isset($list[$value]) ? $list[$value] : '';
  70. }
  71. public function getHexiaoTimeTextAttr($value, $data)
  72. {
  73. $value = $value ? $value : (isset($data['hexiao_time']) ? $data['hexiao_time'] : '');
  74. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  75. }
  76. public function getCancelTimeTextAttr($value, $data)
  77. {
  78. $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
  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['finish_time']) ? $data['finish_time'] : '');
  84. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  85. }
  86. protected function setServerTimeAttr($value)
  87. {
  88. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  89. }
  90. protected function setPackageEndtimeAttr($value)
  91. {
  92. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  93. }
  94. protected function setPayTimeAttr($value)
  95. {
  96. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  97. }
  98. protected function setHexiaoTimeAttr($value)
  99. {
  100. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  101. }
  102. protected function setCancelTimeAttr($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 company()
  111. {
  112. return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
  113. }
  114. public function staff()
  115. {
  116. return $this->belongsTo('app\admin\model\CompanyStaff', 'staff_id', 'id', [], 'LEFT')->setEagerlyType(0);
  117. }
  118. public function user()
  119. {
  120. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  121. }
  122. public function preorder()
  123. {
  124. return $this->belongsTo('app\admin\model\Preorder', 'pre_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
  125. }
  126. public function servicetype()
  127. {
  128. return $this->belongsTo('Servicetype', 'servicetype_id', 'id', [], 'LEFT')->setEagerlyType(0);
  129. }
  130. }