ServiceWorkLists.php 4.4 KB

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