GroupActivityLists.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\workerapi\logic\SaleLogic;
  4. use app\api\lists\BaseApiDataLists;
  5. use app\common\lists\ListsSearchInterface;
  6. use app\common\model\group_activity\GroupActivityCategory;
  7. /**
  8. * 销售-拼团活动列表
  9. * Class GroupActivityLists
  10. * @package app\api\lists\property
  11. */
  12. class GroupActivityLists 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. $sale_id = SaleLogic::getSaleIdByToken($this->params['sale_token']??'00000');
  30. $where[] = ['b.sale_id', '=', $sale_id];
  31. if (isset($this->params['start_time']) && !empty($this->params['start_time'])) {
  32. $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time'])));
  33. $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time'])));
  34. $where[] = ['start_time', 'between', [$monthStart, $monthEnd]];
  35. }
  36. return $where;
  37. }
  38. /**
  39. * @notes 获取列表
  40. * @return array
  41. */
  42. public function lists(): array
  43. {
  44. $lists = GroupActivityCategory::alias("a")
  45. ->leftJoin("property_head b","a.property_head_id=b.id")
  46. ->where($this->queryWhere())
  47. ->field('a.id,a.title,a.start_time,a.end_time,a.service_time')
  48. ->limit($this->limitOffset, $this->limitLength)
  49. ->order('a.id', 'desc')
  50. ->select()
  51. ->toArray();
  52. foreach($lists as &$item) {
  53. $item['start_time'] = date('Y-m-d', strtotime($item['start_time']));
  54. $item['end_time'] = date('m-d', $item['end_time']);
  55. $item['service_time'] = date('Y-m-d', strtotime($item['service_time']));
  56. }
  57. return $lists;
  58. }
  59. /**
  60. * @notes 获取数量
  61. * @return int
  62. */
  63. public function count(): int
  64. {
  65. return GroupActivityCategory::alias("a")
  66. ->leftJoin("property_head b","a.property_head_id=b.id")
  67. ->where($this->queryWhere())
  68. ->count();
  69. }
  70. }