CommunityReply.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\community;
  12. use app\common\model\BaseModel;
  13. use app\common\model\system\Relevance;
  14. use app\common\model\user\User;
  15. use app\common\repositories\system\RelevanceRepository;
  16. class CommunityReply extends BaseModel
  17. {
  18. /**
  19. * TODO
  20. * @return string
  21. * @author Qinii
  22. * @day 10/26/21
  23. */
  24. public static function tablePk(): string
  25. {
  26. return 'reply_id';
  27. }
  28. /**
  29. * TODO
  30. * @return string
  31. * @author Qinii
  32. * @day 10/26/21
  33. */
  34. public static function tableName(): string
  35. {
  36. return 'community_reply';
  37. }
  38. public function children()
  39. {
  40. return $this->hasMany(self::class, 'pid', 'reply_id')->where('status', 1);
  41. }
  42. public function hasReply()
  43. {
  44. return $this->hasOne(self::class, 'pid', 'reply_id');
  45. }
  46. public function author()
  47. {
  48. return $this->hasOne(User::class, 'uid', 'uid');
  49. }
  50. public function reply()
  51. {
  52. return $this->hasOne(User::class, 'uid', 're_uid');
  53. }
  54. public function community()
  55. {
  56. return $this->hasOne(Community::class, 'community_id', 'community_id');
  57. }
  58. public function isStart()
  59. {
  60. return $this->hasOne(Relevance::class, 'right_id', 'reply_id')->where('type', RelevanceRepository::TYPE_COMMUNITY_REPLY_START)->bind(['relevance_id']);
  61. }
  62. /**
  63. * 评论被删删除处理
  64. *
  65. * @param [string] $value
  66. * @return void
  67. */
  68. public function getContentAttr($value)
  69. {
  70. if ($this->is_del) $value = '[该评论已被删除]';
  71. return $value;
  72. }
  73. public function searchUidAttr($query, $value)
  74. {
  75. $query->where('uid', $value);
  76. }
  77. public function searchCommunityIdAttr($query, $value)
  78. {
  79. $query->where('community_id', $value);
  80. }
  81. public function searchIsDelAttr($query, $value)
  82. {
  83. $query->where('is_del', $value);
  84. }
  85. public function searchPidAttr($query, $value)
  86. {
  87. $query->where('pid', $value);
  88. }
  89. }