PropertyGroupActivityLists.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\api\lists\property;
  3. use app\api\lists\BaseApiDataLists;
  4. use app\common\lists\ListsSearchInterface;
  5. use app\common\model\group_activity\GroupActivityCategory;
  6. use app\common\model\property\PropertyHead;
  7. /**
  8. * 代理人拼团活动列表
  9. * Class PropertyGroupActivityLists
  10. * @package app\api\lists\property
  11. */
  12. class PropertyGroupActivityLists extends BaseApiDataLists implements ListsSearchInterface
  13. {
  14. /**
  15. * @notes 设置搜索条件
  16. * @return \string[][]
  17. * @author likeadmin
  18. * @date 2024/07/07 18:37
  19. */
  20. public function setSearch(): array
  21. {
  22. return [
  23. '=' => [],
  24. ];
  25. }
  26. public function queryWhere()
  27. {
  28. // 指定用户
  29. $propertyHeadId = (int)PropertyHead::where('user_id',$this->userId)->value('id');
  30. $where[] = ['property_head_id', '=', $propertyHeadId];
  31. $where[] = ['status','=',1];
  32. if (isset($this->params['start_time']) && !empty($this->params['start_time'])) {
  33. $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time'])));
  34. $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time'])));
  35. $where[] = function($query) use ($monthStart, $monthEnd) {
  36. $query->where('start_time', 'between', [$monthStart, $monthEnd])
  37. ->whereOr('end_time', 'between', [$monthStart, $monthEnd]);
  38. };
  39. }
  40. return $where;
  41. }
  42. /**
  43. * @notes 获取列表
  44. * @return array
  45. */
  46. public function lists(): array
  47. {
  48. $lists = GroupActivityCategory::where($this->queryWhere())
  49. ->field('id,title,start_time,end_time,participant_num')
  50. ->limit($this->limitOffset, $this->limitLength)
  51. ->order('start_time', 'desc')
  52. ->select()
  53. ->toArray();
  54. foreach($lists as &$item) {
  55. $item['start_time'] = date('Y-m-d', strtotime($item['start_time']));
  56. $item['end_time'] = date('m-d', $item['end_time']);
  57. }
  58. return $lists;
  59. }
  60. /**
  61. * @notes 获取数量
  62. * @return int
  63. */
  64. public function count(): int
  65. {
  66. return GroupActivityCategory::where($this->queryWhere())->count();
  67. }
  68. }