Packageorder.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Packageorder extends Model
  5. {
  6. // 表名
  7. protected $table = 'package_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'starttime_text',
  17. 'endtime_text',
  18. 'order_status_text',
  19. 'use_status_text',
  20. 'paytime_text',
  21. 'pay_type_text',
  22. 'is_gift_text',
  23. 'notice_status_text',
  24. 'buy_notice_status_text'
  25. ];
  26. public function getOrderStatusList()
  27. {
  28. return ['0' => __('Order_status 0'), '1' => __('Order_status 1'), '10' => __('Order_status 10')];
  29. }
  30. public function getUseStatusList()
  31. {
  32. return ['0' => __('Use_status 0'), '1' => __('Use_status 1')];
  33. }
  34. public function getPayTypeList()
  35. {
  36. return ['1' => __('Pay_type 1'), '2' => __('Pay_type 2')];
  37. }
  38. public function getIsGiftList()
  39. {
  40. return ['0' => __('Is_gift 0'), '1' => __('Is_gift 1')];
  41. }
  42. public function getNoticeStatusList()
  43. {
  44. return ['0' => __('Notice_status 0'), '1' => __('Notice_status 1'), '2' => __('Notice_status 2'), '3' => __('Notice_status 3')];
  45. }
  46. public function getBuyNoticeStatusList()
  47. {
  48. return ['0' => __('Buy_notice_status 0'), '1' => __('Buy_notice_status 1')];
  49. }
  50. public function getStarttimeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
  53. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  54. }
  55. public function getEndtimeTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
  58. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  59. }
  60. public function getOrderStatusTextAttr($value, $data)
  61. {
  62. $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
  63. $list = $this->getOrderStatusList();
  64. return isset($list[$value]) ? $list[$value] : '';
  65. }
  66. public function getUseStatusTextAttr($value, $data)
  67. {
  68. $value = $value ? $value : (isset($data['use_status']) ? $data['use_status'] : '');
  69. $list = $this->getUseStatusList();
  70. return isset($list[$value]) ? $list[$value] : '';
  71. }
  72. public function getPaytimeTextAttr($value, $data)
  73. {
  74. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  75. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  76. }
  77. public function getPayTypeTextAttr($value, $data)
  78. {
  79. $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
  80. $list = $this->getPayTypeList();
  81. return isset($list[$value]) ? $list[$value] : '';
  82. }
  83. public function getIsGiftTextAttr($value, $data)
  84. {
  85. $value = $value ? $value : (isset($data['is_gift']) ? $data['is_gift'] : '');
  86. $list = $this->getIsGiftList();
  87. return isset($list[$value]) ? $list[$value] : '';
  88. }
  89. public function getNoticeStatusTextAttr($value, $data)
  90. {
  91. $value = $value ? $value : (isset($data['notice_status']) ? $data['notice_status'] : '');
  92. $list = $this->getNoticeStatusList();
  93. return isset($list[$value]) ? $list[$value] : '';
  94. }
  95. public function getBuyNoticeStatusTextAttr($value, $data)
  96. {
  97. $value = $value ? $value : (isset($data['buy_notice_status']) ? $data['buy_notice_status'] : '');
  98. $list = $this->getBuyNoticeStatusList();
  99. return isset($list[$value]) ? $list[$value] : '';
  100. }
  101. protected function setStarttimeAttr($value)
  102. {
  103. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  104. }
  105. protected function setEndtimeAttr($value)
  106. {
  107. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  108. }
  109. protected function setPaytimeAttr($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')->setEagerlyType(0);
  116. }
  117. public function package()
  118. {
  119. return $this->belongsTo('Lessonpackage', 'package_id', 'id', [], 'LEFT')->setEagerlyType(0);
  120. }
  121. }