['master_worker_id', 'shop_goods_id', 'shop_orders_id', 'training_task_id', 'training_status', 'lead_master_worker_id', 'operate_status'], ]; } public function queryWhere() { $where = []; $whereWorker = []; if(isset($this->params['province']) && !empty($this->params['province'])){ $whereWorker[] = ['province','=' ,$this->params['province']]; } if(isset($this->params['city']) && !empty($this->params['city'])){ $whereWorker[] = ['city','=' ,$this->params['city']]; } if(!empty($whereWorker)){ $worker_ids = MasterWorker::where($whereWorker)->column('id')??[0]; $where = [['master_worker_id','in' ,$worker_ids]]; } return $where; } /** * 获取数据权限 * $this->adminInfo['data_rules'] * province city admin_id sale_group_id sale_id property_head_id */ public function queryDataWhere(){ $where = []; $data_rules = $this->adminInfo['data_rules']; if (isset($data_rules['province']) && !empty($data_rules['province'])) { $where[] = ['province','in' ,$data_rules['province']]; } if (isset($data_rules['city']) && !empty($data_rules['city'])) { $where[] = ['city','in' ,$data_rules['city']]; } if(!empty($where)){ $worker_ids = MasterWorker::where($where)->column('id')??[0]; $where = [['master_worker_id','in' ,$worker_ids]]; } return $where; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2025/02/16 13:49 */ public function lists(): array { $lists = TrainingWorkerTask::with([ 'TrainingTask', 'MasterWorker', 'LeadMasterWorker', 'ShopGoods', 'ShopOrders', ])->where($this->searchWhere)->where($this->queryWhere())->where($this->queryDataWhere()) ->field(['id', 'task_list','master_worker_id', 'shop_goods_id', 'shop_orders_id', 'training_task_id', 'training_status', 'lead_master_worker_id', 'operate_status']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); foreach ($lists as &$item) { $item['taskDetail'] = $this->taskDetail($item['master_worker_id'],$item['MasterWorker']['identity_source']); } return $lists; } /** * @notes 获取数量 * @return int * @author likeadmin * @date 2025/02/16 13:49 */ public function count(): int { return TrainingWorkerTask::where($this->searchWhere)->count(); } public function taskDetail($master_worker_id,$identity_source) { $trainingWorkerTask = TrainingWorkerTask::where(['master_worker_id'=>$master_worker_id])->findOrEmpty(); if($trainingWorkerTask->isEmpty()){ return []; } $configs = TrainingBlockConfigLogic::getRequiredConfig($identity_source); $taskDetail = []; foreach ($configs as $item) { if(empty($item['execute_function'])) continue; if(!class_exists(\app\workerapi\service\MasterWokerTaskRequiredService::class)){ continue; } if(!method_exists(\app\workerapi\service\MasterWokerTaskRequiredService::class,$item['execute_function'])){ continue; } $execute_function = $item['execute_function']; $res = (new MasterWokerTaskRequiredService())::$execute_function($master_worker_id); $taskDetail[] = [ 'type_name'=>$item['type_name'], 'is_must'=> $item['is_must']?'是':'否', 'result'=> $res===false?'未完成':'已完成', ]; } return $taskDetail; } }