Active.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Active extends Model
  5. {
  6. // 表名
  7. protected $name = 'active';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'starttime_text',
  18. 'endtime_text',
  19. 'collectiontime_text',
  20. 'signupendtime_text',
  21. 'refundendtime_text',
  22. 'showtime_text',
  23. 'is_autoshow_text',
  24. 'showtime_text',
  25. 'is_banner_text',
  26. 'is_free_text',
  27. 'is_overlying_text',
  28. 'status_text'
  29. ];
  30. protected static function init()
  31. {
  32. self::afterInsert(function ($row) {
  33. $pk = $row->getPk();
  34. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  35. });
  36. }
  37. public function getTypeList()
  38. {
  39. return ['1' => __('Type 1'), '2' => __('Type 2')];
  40. }
  41. public function getIsFreeList()
  42. {
  43. return ['0' => __('Is_free 0'), '1' => __('Is_free 1')];
  44. }
  45. public function getIsOverlyingList()
  46. {
  47. return ['0' => __('Is_overlying 0'), '1' => __('Is_overlying 1')];
  48. }
  49. public function getStatusList()
  50. {
  51. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
  52. }
  53. public function getShowstatusList()
  54. {
  55. return ['0' => __('Showstatus 0'), '1' => __('Showstatus 1')];
  56. }
  57. public function getIsAutoshowList()
  58. {
  59. return ['0' => __('Is_autoshow 0'), '1' => __('Is_autoshow 1')];
  60. }
  61. public function getIsBannerList()
  62. {
  63. return ['0' => __('Is_banner 0'), '1' => __('Is_banner 1')];
  64. }
  65. public function getTypeTextAttr($value, $data)
  66. {
  67. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  68. $list = $this->getTypeList();
  69. return isset($list[$value]) ? $list[$value] : '';
  70. }
  71. public function getStarttimeTextAttr($value, $data)
  72. {
  73. $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
  74. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  75. }
  76. public function getEndtimeTextAttr($value, $data)
  77. {
  78. $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
  79. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  80. }
  81. public function getCollectiontimeTextAttr($value, $data)
  82. {
  83. $value = $value ? $value : (isset($data['collectiontime']) ? $data['collectiontime'] : '');
  84. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  85. }
  86. public function getSignupendtimeTextAttr($value, $data)
  87. {
  88. $value = $value ? $value : (isset($data['signupendtime']) ? $data['signupendtime'] : '');
  89. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  90. }
  91. public function getRefundendtimeTextAttr($value, $data)
  92. {
  93. $value = $value ? $value : (isset($data['refundendtime']) ? $data['refundendtime'] : '');
  94. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  95. }
  96. public function getIsFreeTextAttr($value, $data)
  97. {
  98. $value = $value ? $value : (isset($data['is_free']) ? $data['is_free'] : '');
  99. $list = $this->getIsFreeList();
  100. return isset($list[$value]) ? $list[$value] : '';
  101. }
  102. public function getIsOverlyingTextAttr($value, $data)
  103. {
  104. $value = $value ? $value : (isset($data['is_overlying']) ? $data['is_overlying'] : '');
  105. $list = $this->getIsOverlyingList();
  106. return isset($list[$value]) ? $list[$value] : '';
  107. }
  108. public function getStatusTextAttr($value, $data)
  109. {
  110. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  111. $list = $this->getStatusList();
  112. return isset($list[$value]) ? $list[$value] : '';
  113. }
  114. public function getShowstatusTextAttr($value, $data)
  115. {
  116. $value = $value ? $value : (isset($data['showstatus']) ? $data['showstatus'] : '');
  117. $list = $this->getShowstatuslist();
  118. return isset($list[$value]) ? $list[$value] : '';
  119. }
  120. public function getIsAutoshowTextAttr($value, $data)
  121. {
  122. $value = $value ? $value : (isset($data['is_autoshow']) ? $data['is_autoshow'] : '');
  123. $list = $this->getIsAutoshowList();
  124. return isset($list[$value]) ? $list[$value] : '';
  125. }
  126. public function getShowtimeTextAttr($value, $data)
  127. {
  128. $value = $value ? $value : (isset($data['showtime']) ? $data['showtime'] : '');
  129. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  130. }
  131. public function getIsBannerTextAttr($value, $data)
  132. {
  133. $value = $value ? $value : (isset($data['is_banner']) ? $data['is_banner'] : '');
  134. $list = $this->getIsBannerList();
  135. return isset($list[$value]) ? $list[$value] : '';
  136. }
  137. protected function setStarttimeAttr($value)
  138. {
  139. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  140. }
  141. protected function setEndtimeAttr($value)
  142. {
  143. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  144. }
  145. protected function setCollectiontimeAttr($value)
  146. {
  147. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  148. }
  149. protected function setSignupendtimeAttr($value)
  150. {
  151. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  152. }
  153. protected function setRefundendtimeAttr($value)
  154. {
  155. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  156. }
  157. protected function setShowtimeAttr($value)
  158. {
  159. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  160. }
  161. }