Article.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Article extends Model
  5. {
  6. // 设置字段信息
  7. protected $schema = [
  8. 'id' => 'int',
  9. 'cateid' => 'int',
  10. 'title' => 'string',
  11. 'tilpic' => 'string',
  12. 'author' => 'string',
  13. 'summary' => 'string',
  14. 'atype' => 'tinyint',
  15. 'details' => 'string',
  16. 'tilurl' => 'string',
  17. 'priority' => 'int',
  18. 'createtime' => 'int',
  19. 'status' => 'tinyint',
  20. 'volume' => 'int'
  21. ];
  22. // 设置字段自动转换类型
  23. protected $type = [
  24. 'createtime' => 'timestamp:Y-m-d H:i:s'
  25. ];
  26. public function getAtypeTextAttr($value,$data)
  27. {
  28. $atype = [1=>'文章详情',2=>'系统链接',3=>'网络链接'];
  29. return $atype[$data['atype']];
  30. }
  31. public function getStatusTextAttr($value,$data)
  32. {
  33. $status = [1=>'已发布',2=>'待修改'];
  34. return $status[$data['status']];
  35. }
  36. public function getCreatetimeTextAttr($value,$data)
  37. {
  38. return date('Y-m-d', $data['createtime']);
  39. }
  40. // 关联ArticleCate
  41. public function articleCate()
  42. {
  43. return $this->hasOne(ArticleCate::class, "id", "cateid");
  44. }
  45. // 关联ArticleComment
  46. public function articleComment()
  47. {
  48. return $this->hasMany(ArticleComment::class, "articleid", "id");
  49. }
  50. // 关联ArticleThumb
  51. public function articleThumb()
  52. {
  53. return $this->hasMany(ArticleThumb::class, "articleid", "id");
  54. }
  55. // 关联ArticleCollect
  56. public function articleCollect()
  57. {
  58. return $this->hasMany(ArticleCollect::class, "articleid", "id");
  59. }
  60. }