Messagesys.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Messagesys extends Model
  5. {
  6. // 表名
  7. protected $table = 'message_sys';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'sendtime_text',
  17. 'is_index_text',
  18. 'is_show_text',
  19. 'push_status_text'
  20. ];
  21. protected static function init()
  22. {
  23. self::afterInsert(function ($row) {
  24. $pk = $row->getPk();
  25. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  26. });
  27. }
  28. public function getIsIndexList()
  29. {
  30. return ['0' => __('Is_index 0'), '1' => __('Is_index 1')];
  31. }
  32. public function getIsShowList()
  33. {
  34. return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
  35. }
  36. public function getPushStatusList()
  37. {
  38. return ['0' => __('Push_status 0'), '1' => __('Push_status 1')];
  39. }
  40. public function getSendtimeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['sendtime']) ? $data['sendtime'] : '');
  43. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  44. }
  45. public function getIsIndexTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['is_index']) ? $data['is_index'] : '');
  48. $list = $this->getIsIndexList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getIsShowTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  54. $list = $this->getIsShowList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. public function getPushStatusTextAttr($value, $data)
  58. {
  59. $value = $value ? $value : (isset($data['push_status']) ? $data['push_status'] : '');
  60. $list = $this->getPushStatusList();
  61. return isset($list[$value]) ? $list[$value] : '';
  62. }
  63. protected function setSendtimeAttr($value)
  64. {
  65. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  66. }
  67. }