MasterWorkerRegisterLists.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\common\model\master_worker\MasterWorker;
  4. use app\common\model\master_worker_register\MasterWorkerRegister;
  5. use app\common\lists\ListsSearchInterface;
  6. use app\common\model\works\ServiceWork;
  7. use app\workerapi\logic\MasterWorkerLogic;
  8. use app\workerapi\logic\SaleLogic;
  9. use think\facade\Db;
  10. /**
  11. * MasterWorkerRegister列表
  12. * Class MasterWorkerRegisterLists
  13. * @package app\workerapi\lists
  14. */
  15. class MasterWorkerRegisterLists extends BaseWorkerDataLists implements ListsSearchInterface
  16. {
  17. /**
  18. * @notes 设置搜索条件
  19. * @return \string[][]
  20. * @author likeadmin
  21. * @date 2025/02/25 09:29
  22. */
  23. public function setSearch(): array
  24. {
  25. $sale_id = SaleLogic::getSaleIdByToken($this->params['sale_token']??'00000');
  26. $this->params['sale_id'] = $sale_id;
  27. return [
  28. '=' => ['maintain_exp_type', 'other_exp_type', 'city', 'vehicle_type', 'status','is_credential','sale_id'],
  29. '%like%' => ['name', 'mobile'],
  30. ];
  31. }
  32. public function queryWhere()
  33. {
  34. $where = [];
  35. if(isset($this->params['time_range']) && $this->params['time_range']){
  36. $time_range = explode(',', $this->params['time_range']);
  37. $startDateTime = strtotime($time_range[0]);
  38. $endDateTime = strtotime($time_range[1])+86400-1;
  39. $where[] = ['create_time','BETWEEN',[$startDateTime,$endDateTime]];
  40. }
  41. return $where;
  42. }
  43. /**
  44. * @notes 获取列表
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @author likeadmin
  50. * @date 2025/02/25 09:29
  51. */
  52. public function lists(): array
  53. {
  54. $list = MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())
  55. ->field(['*'])
  56. ->limit($this->limitOffset, $this->limitLength)
  57. ->order(['id' => 'desc'])
  58. ->select()
  59. ->toArray();
  60. $workCount = array_column(ServiceWork::where('master_worker_id','>',0)
  61. ->whereIn('master_worker_id', array_filter(array_column($list, 'worker_id'), function($value) { return $value != 0; })??[-1])
  62. ->field(['master_worker_id',Db::raw('COUNT(id) as work_total')])
  63. ->group('master_worker_id')
  64. ->select()->toArray(),'work_total','master_worker_id');
  65. foreach ($list as &$item) {
  66. $item['work_total'] = $workCount[$item['worker_id']]??0;
  67. if((int)$item['status'] === 1){
  68. $item['status'] = $this->requiredMasterWorker($item['worker_id'])?1:2;
  69. }
  70. }
  71. return $list;
  72. }
  73. /**
  74. * @notes 获取数量
  75. * @return int
  76. * @author likeadmin
  77. * @date 2025/02/25 09:29
  78. */
  79. public function count(): int
  80. {
  81. return MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())->count();
  82. }
  83. public function requiredMasterWorker($master_worker_id): bool
  84. {
  85. $masterWorker = MasterWorker::where('id',$master_worker_id)->findOrEmpty();
  86. if(!$masterWorker->isEmpty()){
  87. // 该工程师所有必须任务是否完成
  88. $taskRequired = MasterWorkerLogic::taskRequired($master_worker_id,$masterWorker->identity_source);
  89. if($masterWorker->audit_state == 1 && $taskRequired){
  90. return true;
  91. }
  92. }
  93. return false;
  94. }
  95. }