VideoComment.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\activity\video;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 视频评价Model
  18. * Class VideoComment
  19. * @package app\model\activity\video
  20. */
  21. class VideoComment extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'video_comment';
  34. /**
  35. * @var bool
  36. */
  37. protected $autoWriteTimestamp = false;
  38. /**
  39. * 一对一关联
  40. * 视频评论关联视频
  41. * @return \think\model\relation\HasOne
  42. */
  43. public function video()
  44. {
  45. return $this->hasOne(Video::class, 'id', 'video_id');
  46. }
  47. /**
  48. * 一对一关联
  49. * 视频评论关联用户
  50. * @return \think\model\relation\HasOne
  51. */
  52. public function user()
  53. {
  54. return $this->hasOne(User::class, 'uid', 'uid');
  55. }
  56. /**
  57. * 管理回复
  58. * @return \think\model\relation\HasOne
  59. */
  60. public function reply()
  61. {
  62. return $this->hasOne(self::class, 'pid', 'id')->where('is_del', 0)->where('uid', 0);
  63. }
  64. /**
  65. * @return \think\model\relation\hasMany
  66. */
  67. public function children()
  68. {
  69. return $this->hasMany(self::class, 'pid', 'id')->where('is_del', 0);
  70. }
  71. /**
  72. * 商户搜索器
  73. * @param Model $query
  74. * @param $value
  75. */
  76. public function searchTypeAttr($query, $value)
  77. {
  78. if (is_array($value)) {
  79. if ($value) $query->whereIn('type', $value);
  80. } else {
  81. if ($value !== '') $query->where('type', $value);
  82. }
  83. }
  84. /**
  85. * 关联门店ID、供应商ID搜索器
  86. * @param Model $query
  87. * @param $value
  88. */
  89. public function searchRelationIdAttr($query, $value)
  90. {
  91. if (is_array($value)) {
  92. if ($value) $query->whereIn('relation_id', $value);
  93. } else {
  94. if ($value !== '') $query->where('relation_id', $value);
  95. }
  96. }
  97. /**
  98. * 上级评论搜索器
  99. * @param Model $query
  100. * @param $value
  101. */
  102. public function searchPidAttr($query, $value)
  103. {
  104. if (is_array($value)) {
  105. if ($value) $query->whereIn('pid', $value);
  106. } else {
  107. if ($value !== '') $query->where('pid', $value);
  108. }
  109. }
  110. /**
  111. * 视频ID搜索器
  112. * @param Model $query
  113. * @param $value
  114. */
  115. public function searchVideoIdAttr($query, $value)
  116. {
  117. if (is_array($value)) {
  118. if ($value) $query->whereIn('video_id', $value);
  119. } else {
  120. if ($value) $query->where('video_id', $value);
  121. }
  122. }
  123. /**
  124. * UID搜索器
  125. * @param Model $query
  126. * @param $value
  127. */
  128. public function searchUidAttr($query, $value)
  129. {
  130. if (is_array($value)) {
  131. if ($value) $query->whereIn('uid', $value);
  132. } else {
  133. if ($value !== '') $query->where('uid', $value);
  134. }
  135. }
  136. /**
  137. * is_reply搜索器
  138. * @param Model $query
  139. * @param $value
  140. */
  141. public function searchIsReplyAttr($query, $value)
  142. {
  143. if ($value !== '') $query->where('is_reply', $value);
  144. }
  145. /**
  146. * is_del搜索器
  147. * @param Model $query
  148. * @param $value
  149. */
  150. public function searchIsDelAttr($query, $value)
  151. {
  152. if ($value !== '') $query->where('is_del', $value);
  153. }
  154. }