ServiceWorkLists.php 4.0 KB

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