ServiceWorkLists.php 3.1 KB

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