Notice.php 837 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Notice extends Model
  5. {
  6. // 设置字段信息
  7. protected $schema = [
  8. 'id' => 'int',
  9. 'cateid' => 'int',
  10. 'title' => 'string',
  11. 'details' => 'string',
  12. 'priority' => 'int',
  13. 'createtime' => 'int',
  14. 'status' => 'tinyint',
  15. 'volume' => 'int'
  16. ];
  17. // 设置字段自动转换类型
  18. protected $type = [
  19. 'createtime' => 'timestamp:Y-m-d H:i:s'
  20. ];
  21. public function getStatusTextAttr($value,$data)
  22. {
  23. $status = [1=>'已发布',2=>'待修改'];
  24. return $status[$data['status']];
  25. }
  26. public function getCreatetimeTextAttr($value,$data)
  27. {
  28. return date('Y-m-d H:i', $data['createtime']);
  29. }
  30. // 关联NoticeCate
  31. public function noticeCate()
  32. {
  33. return $this->hasOne(NoticeCate::class, "id", "cateid");
  34. }
  35. }