MasterWorkerRegisterLists.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /**
  33. * @notes 获取列表
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @author likeadmin
  39. * @date 2025/02/25 09:29
  40. */
  41. public function lists(): array
  42. {
  43. $list = MasterWorkerRegister::where($this->searchWhere)
  44. ->field(['*'])
  45. ->limit($this->limitOffset, $this->limitLength)
  46. ->order(['id' => 'desc'])
  47. ->select()
  48. ->toArray();
  49. $workCount = array_column(ServiceWork::where('master_worker_id','>',0)
  50. ->whereIn('master_worker_id', array_filter(array_column($list, 'worker_id'), function($value) { return $value != 0; })??[-1])
  51. ->field(['master_worker_id',Db::raw('COUNT(id) as work_total')])
  52. ->group('master_worker_id')
  53. ->select()->toArray(),'work_total','master_worker_id');
  54. foreach ($list as &$item) {
  55. $item['work_total'] = $workCount[$item['worker_id']]??0;
  56. if((int)$item['status'] === 1){
  57. $item['status'] = $this->requiredMasterWorker($item['worker_id'])?1:2;
  58. }
  59. }
  60. return $list;
  61. }
  62. /**
  63. * @notes 获取数量
  64. * @return int
  65. * @author likeadmin
  66. * @date 2025/02/25 09:29
  67. */
  68. public function count(): int
  69. {
  70. return MasterWorkerRegister::where($this->searchWhere)->count();
  71. }
  72. public function requiredMasterWorker($master_worker_id): bool
  73. {
  74. $masterWorker = MasterWorker::where('id',$master_worker_id)->findOrEmpty();
  75. if(!$masterWorker->isEmpty()){
  76. // 该工程师所有必须任务是否完成
  77. $taskRequired = MasterWorkerLogic::taskRequired($master_worker_id,$masterWorker->identity_source);
  78. if($masterWorker->audit_state == 1 && $taskRequired){
  79. return true;
  80. }
  81. }
  82. return false;
  83. }
  84. }