StoreActivityDao.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\activity;
  12. use app\dao\BaseDao;
  13. use app\model\activity\StoreActivity;
  14. class StoreActivityDao extends BaseDao
  15. {
  16. protected function setModel(): string
  17. {
  18. return StoreActivity::class;
  19. }
  20. public function conditionSearch($where)
  21. {
  22. return $this->getModel()
  23. ->when(isset($where['title']) && $where['title'] !== '', function ($query) use ($where) {
  24. $query->whereLike('title', '%' . $where['title'] . '%');
  25. })->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
  26. $query->where('is_del', $where['is_del']);
  27. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  28. $query->where('status', $where['status']);
  29. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  30. $query->where('type', $where['type']);
  31. })->when(isset($where['time_ids']) && count($where['time_ids']) > 0, function ($query) use ($where) {
  32. $query->where(function ($query) use ($where) {
  33. foreach ($where['time_ids'] as $value) {
  34. $query->whereOr('FIND_IN_SET(:value, time_ids)', ['value' => $value]);
  35. }
  36. });
  37. })->when(isset($where['time']) && $where['time'] !== '', function ($query) use ($where) {
  38. $time = explode('-', $where['time']);
  39. $query->where('start_day', '<=', strtotime($time[1]))->where('end_day', '>=', strtotime($time[0]));
  40. });
  41. }
  42. public function activityList(array $where = [], string $field = '*', int $page = 0, int $limit = 0, $with = [])
  43. {
  44. return $this->conditionSearch($where)->field($field)
  45. ->when($page && $limit, function ($query) use ($page, $limit) {
  46. $query->page($page, $limit);
  47. })->when(count($with), function ($query) use ($with) {
  48. $query->with($with);
  49. })->order('add_time DESC')->select()->toArray();
  50. }
  51. public function activityCount(array $where = [])
  52. {
  53. return $this->conditionSearch($where)->count();
  54. }
  55. }