GroupServiceWorkLists.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\common\model\works\GroupServiceWork;
  4. use app\common\lists\ListsSearchInterface;
  5. use DateTime;
  6. /**
  7. * GroupServiceWork列表
  8. * Class GroupServiceWorkLists
  9. * @package app\workerapi\listsworks
  10. */
  11. class GroupServiceWorkLists extends BaseWorkerDataLists implements ListsSearchInterface
  12. {
  13. protected $count = 0;
  14. public function setSearch(): array
  15. {
  16. return [];
  17. }
  18. /**
  19. * @notes 获取列表
  20. * @return array
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\DbException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @author whitef
  25. * @date 2024/07/10 15:06
  26. */
  27. public function lists(): array
  28. {
  29. $where = [
  30. 'master_worker_id'=>$this->userId,
  31. ];
  32. //条件搜索
  33. $status = $this->params['status'] ?? 0;
  34. switch ($status){
  35. case 0:
  36. $where[] = ['work_status','<>',1];
  37. $where[] = ['service_status','in','0,1,2'];
  38. break;
  39. case 1:
  40. $where[] = ['work_status','<>',1];
  41. $where[] = ['service_status','in','0,1,2'];
  42. // 创建 DateTime 对象并设置为今天午夜
  43. $startOfDay = new DateTime('today midnight');
  44. // 设置为今天最后一秒
  45. $endOfDay = new DateTime('today midnight');
  46. $endOfDay->modify('+1 day -1 second');
  47. // 转换为时间戳
  48. $startOfDayTimestamp = $startOfDay->getTimestamp();
  49. $endOfDayTimestamp = $endOfDay->getTimestamp();
  50. $where[] = ['appointment_time','between',[$startOfDayTimestamp, $endOfDayTimestamp]];
  51. break;
  52. case 2:
  53. $where[] = ['work_status','<>',1];
  54. $where[] = ['service_status','in','0,1,2'];
  55. // 创建一个 DateTime 对象表示当前时间
  56. $dateNow = new DateTime();
  57. // 修改这个对象以表示明天的午夜
  58. $midnightTomorrow = clone $dateNow;
  59. $midnightTomorrow->modify('+1 day midnight');
  60. // 修改这个对象以表示明天的最后一秒
  61. $lastSecondTomorrow = clone $dateNow;
  62. $lastSecondTomorrow->modify('+1 day 23:59:59');
  63. $midnightTimestamp = $midnightTomorrow->getTimestamp();
  64. $lastSecondTimestamp = $lastSecondTomorrow->getTimestamp();
  65. $where[] = ['appointment_time','between',[$midnightTimestamp, $lastSecondTimestamp]];
  66. break;
  67. case 3:
  68. $where[] = ['work_status','<>',1];
  69. break;
  70. case 4:
  71. $where['work_status'] = 7;
  72. break;
  73. }
  74. $list = GroupServiceWork::where($where)
  75. ->field(['id', 'work_sn', 'address', 'title', 'work_status', 'service_status','appointment_time'])
  76. ->append(['work_status_text','service_status_text'])
  77. ->limit($this->limitOffset, $this->limitLength)
  78. ->order(['appointment_time' => 'asc'])//上门时间排序
  79. ->select()
  80. ->toArray();
  81. $this->count = GroupServiceWork::where($where)->count();
  82. return $list;
  83. }
  84. /**
  85. * @notes 获取数量
  86. * @return int
  87. * @author whitef
  88. * @date 2024/07/10 15:06
  89. */
  90. public function count(): int
  91. {
  92. return $this->count;
  93. }
  94. }