Order.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\admin\model\order;
  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 = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'trip_type_text',
  17. 'payment_type_text',
  18. 'status_text',
  19. 'pay_time_text',
  20. 'cancel_time_text'
  21. ];
  22. public function getTripTypeList()
  23. {
  24. return ['bus' => __('Bus'), 'taxi' => __('Taxi')];
  25. }
  26. public function getPaymentTypeList()
  27. {
  28. return ['ali' => __('Ali'), 'wechat' => __('Wechat'), 'balance' => __('Balance')];
  29. }
  30. public function getStatusList()
  31. {
  32. return [
  33. 'default' => __('Default'),
  34. 'purchase' => __('Purchase'),
  35. 'proceed' => __('Proceed'),
  36. 'finish' => __('Finish'),
  37. 'wait_feedback' => __('Wait_feedback'),
  38. 'cancel' => __('Cancel'),
  39. 'reject' => __('Reject'),
  40. 'admin_cancel' => __('Admin_cancel'),
  41. 'auto_cancel' => __('Auto_cancel'),
  42. ];
  43. }
  44. public function getTripTypeTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['trip_type']) ? $data['trip_type'] : '');
  47. $list = $this->getTripTypeList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public function getPaymentTypeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['payment_type']) ? $data['payment_type'] : '');
  53. $list = $this->getPaymentTypeList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getStatusTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  59. $list = $this->getStatusList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. public function getPayTimeTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
  65. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  66. }
  67. public function getCancelTimeTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
  70. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  71. }
  72. protected function setPayTimeAttr($value)
  73. {
  74. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  75. }
  76. protected function setCancelTimeAttr($value)
  77. {
  78. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  79. }
  80. public function user()
  81. {
  82. return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  83. }
  84. public function store()
  85. {
  86. return $this->belongsTo('app\admin\model\Store', 'store_id', 'id', [], 'LEFT')->setEagerlyType(0);
  87. }
  88. public function massager()
  89. {
  90. return $this->belongsTo('app\admin\model\Massager', 'massager_id', 'id', [], 'LEFT')->setEagerlyType(0);
  91. }
  92. }