CommunityReplyDao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\dao\community;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\community\CommunityReply;
  14. class CommunityReplyDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return CommunityReply::class;
  19. }
  20. /**
  21. * 查询用户的帖子回复
  22. * @param int $id
  23. * @param int $uid
  24. * @return mixed
  25. * @author wuhaotian
  26. * @email 442384644@qq.com
  27. * @date 2024/7/12
  28. */
  29. public function uidExists(int $id, int $uid)
  30. {
  31. return $this->getModel()::getDb()->where($this->getPk(), $id)->where('uid', $uid)->where('is_del', 0)->find();
  32. }
  33. /**
  34. * 查询帖子回复
  35. * @param array $where
  36. * @return \think\db\BaseQuery
  37. * @author wuhaotian
  38. * @email 442384644@qq.com
  39. * @date 2024/7/12
  40. */
  41. public function search(array $where)
  42. {
  43. $query = CommunityReply::hasWhere('author',function($query) use($where) {
  44. $query->when(isset($where['username']) && $where['username'] !== '', function ($query) use($where) {
  45. $query->whereLike('nickname',"%{$where['username']}%");
  46. });
  47. $query->where(true);
  48. });
  49. $query->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use($where) {
  50. $query->whereLike('content',"%{$where['keyword']}%");
  51. });
  52. $query->when(isset($where['date']) && $where['date'] !== '', function ($query) use($where) {
  53. getModelTime($query, $where['date'], 'CommunityReply.create_time');
  54. });
  55. $query->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use($where) {
  56. $query->where('is_del',$where['is_del']);
  57. });
  58. $query->when(isset($where['pid']) && $where['pid'] !== '', function ($query) use($where) {
  59. $query->where('pid',$where['pid']);
  60. });
  61. $query->when(isset($where['community_id']) && $where['community_id'] !== '', function ($query) use($where) {
  62. $query->where('community_id',$where['community_id']);
  63. });
  64. return $query->order('CommunityReply.create_time DESC');
  65. }
  66. }