FeedbackDao.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\common\dao\user;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\user\Feedback;
  6. use think\db\BaseQuery;
  7. /**
  8. * Class FeedbackDao
  9. * @package app\common\dao\user
  10. * @author zfy
  11. * @day 2020/5/28
  12. */
  13. class FeedbackDao extends BaseDao
  14. {
  15. /**
  16. * @return string
  17. * @author zfy
  18. * @day 2020/5/28
  19. */
  20. protected function getModel(): string
  21. {
  22. return Feedback::class;
  23. }
  24. /**
  25. * @param array $where
  26. * @return BaseQuery
  27. * @author zfy
  28. * @day 2020/5/28
  29. */
  30. public function search(array $where)
  31. {
  32. return Feedback::getDB()->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
  33. $query->where('uid', $where['uid']);
  34. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  35. $query->where('content','like', '%'.$where['keyword'].'%')
  36. ->whereOr('reply','like', '%'.$where['keyword'].'%')
  37. ->whereOr('remake','like', '%'.$where['keyword'].'%')
  38. ->whereOr('realname','like', '%'.$where['keyword'].'%');
  39. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  40. $query->where('type',$where['type']);
  41. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  42. $query->where('status', $where['status']);
  43. })->when(isset($where['realname']) && $where['realname'] !== '', function ($query) use ($where) {
  44. $query->where('realname','like', '%'.$where['realname'].'%');
  45. })->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
  46. $query->where('is_del',$where['is_del']);
  47. })->order('create_time DESC');
  48. }
  49. /**
  50. * @param $id
  51. * @param $uid
  52. * @return bool
  53. * @author zfy
  54. * @day 2020/5/28
  55. */
  56. public function uidExists($id, $uid): bool
  57. {
  58. return Feedback::getDB()->where($this->getPk(), $id)->where('uid', $uid)->where('is_del', 0)->count($this->getPk()) > 0;
  59. }
  60. public function merExists(int $id)
  61. {
  62. return $this->getModel()::getDB()->where($this->getPk(), $id)->where('is_del', 0)->count() > 0;
  63. }
  64. }