ArticleComment.php 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class ArticleComment extends Model
  5. {
  6. // 设置字段信息
  7. protected $schema = [
  8. 'id' => 'int',
  9. 'userid' => 'int',
  10. 'articleid' => 'int',
  11. 'puserid' => 'int',
  12. 'details' => 'string',
  13. 'createtime' => 'int',
  14. 'status' => 'tinyint'
  15. ];
  16. // 设置字段自动转换类型
  17. protected $type = [
  18. 'createtime' => 'timestamp:Y-m-d H:i:s'
  19. ];
  20. public function getStatusTextAttr($value,$data)
  21. {
  22. $status = [1=>'已通过',2=>'待审核'];
  23. return $status[$data['status']];
  24. }
  25. // 关联Article
  26. public function article()
  27. {
  28. return $this->hasOne(Article::class, "id", "articleid");
  29. }
  30. // 关联User
  31. public function user()
  32. {
  33. return $this->hasOne(User::class, "id", "userid")->field('id,nickname,avatar');
  34. }
  35. // 关联User
  36. public function puser()
  37. {
  38. return $this->hasOne(User::class, "id", "puserid")->field('id,nickname,avatar');
  39. }
  40. }