StoreActivityDao.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\dao\activity;
  3. use app\dao\BaseDao;
  4. use app\model\activity\StoreActivity;
  5. class StoreActivityDao extends BaseDao
  6. {
  7. protected function setModel(): string
  8. {
  9. return StoreActivity::class;
  10. }
  11. public function conditionSearch($where)
  12. {
  13. return $this->getModel()
  14. ->when(isset($where['title']) && $where['title'] !== '', function ($query) use ($where) {
  15. $query->whereLike('title', '%' . $where['title'] . '%');
  16. })->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
  17. $query->where('is_del', $where['is_del']);
  18. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  19. $query->where('status', $where['status']);
  20. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  21. $query->where('type', $where['type']);
  22. })->when(isset($where['time_ids']) && count($where['time_ids']) > 0, function ($query) use ($where) {
  23. $query->where(function ($query) use ($where) {
  24. foreach ($where['time_ids'] as $value) {
  25. $query->whereOr('FIND_IN_SET(:value, time_ids)', ['value' => $value]);
  26. }
  27. });
  28. })->when(isset($where['time']) && $where['time'] !== '', function ($query) use ($where) {
  29. $time = explode('-', $where['time']);
  30. $query->where('start_day', '<=', strtotime($time[1]))->where('end_day', '>=', strtotime($time[0]));
  31. });
  32. }
  33. public function activityList(array $where = [], string $field = '*', int $page = 0, int $limit = 0, $with = [])
  34. {
  35. return $this->conditionSearch($where)->field($field)
  36. ->when($page && $limit, function ($query) use ($page, $limit) {
  37. $query->page($page, $limit);
  38. })->when(count($with), function ($query) use ($with) {
  39. $query->with($with);
  40. })->order('add_time DESC')->select()->toArray();
  41. }
  42. public function activityCount(array $where = [])
  43. {
  44. return $this->conditionSearch($where)->count();
  45. }
  46. }