FeedbackDao.php 2.2 KB

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