Active.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Active extends Model
  5. {
  6. // 表名
  7. protected $table = 'active';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'activestarttime_text',
  17. 'activeendtime_text',
  18. 'is_show_text'
  19. ];
  20. protected static function init()
  21. {
  22. self::afterInsert(function ($row) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  25. });
  26. }
  27. public function getIsShowList()
  28. {
  29. return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
  30. }
  31. public function getActivestarttimeTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['activestarttime']) ? $data['activestarttime'] : '');
  34. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  35. }
  36. public function getActiveendtimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['activeendtime']) ? $data['activeendtime'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. public function getIsShowTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  44. $list = $this->getIsShowList();
  45. return isset($list[$value]) ? $list[$value] : '';
  46. }
  47. protected function setActivestarttimeAttr($value)
  48. {
  49. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  50. }
  51. protected function setActiveendtimeAttr($value)
  52. {
  53. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  54. }
  55. }