select = '*'; $criteria->addCondition('exam_group_id=:id'); $criteria->params[':id'] = $examGroupId; return $this->find($criteria); } //更新任务 public function updateTask($examGroupId,$arr){ return $this->updateAll($arr,'exam_group_id=:eid',array(':eid'=>$examGroupId)); } public function getList($where,$param,$page,$pageLimit){ $sql="select * from assist_task "; if($where){ $sql.=' where '.implode(' and ',$where); } $offset=($page-1)*$pageLimit; $sql.=" order by create_time desc "; $sql.=" limit {$offset},{$pageLimit}"; $data=$this->getDbConnection()->createCommand($sql,$param)->queryAll(); return $data; } //手动分配 public function apply($examGroupId,$userId){ if(!$examGroupId || !$userId) return false; $transaction = $this->getDbConnection()->beginTransaction(); try { $ExamInfo=$this->getDbConnection()->createCommand("select operator,answer_sheet_task,paper_task,parse_task from assist_task where exam_group_id='".$examGroupId."'")->queryRow(); if(!$ExamInfo ) return false; $updateTask=array(); $time=time(); if($ExamInfo['answer_sheet_task']==1){ $updateTask[]=" `answer_sheet_task`=2 "; $updateTask[]=" `ast_update_time`= {$time}"; $updateTask[]=" `ast_apply_time`= {$time}"; } if($ExamInfo['paper_task']==1){ $updateTask[]=" `paper_task`=2 "; $updateTask[]=" `ppt_update_time`= {$time}"; $updateTask[]=" `ppt_apply_time`= {$time}"; } if($ExamInfo['parse_task']==1){ $updateTask[]=" `parse_task`=2 "; $updateTask[]=" `pat_update_time`= {$time}"; $updateTask[]=" `pat_apply_time`= {$time}"; } $updateTask[]=" `update_time`= {$time}"; $updateTask[]=" `operator`='".$userId."'"; $this->getDbConnection()->createCommand("update assist_task set ".implode(",",$updateTask)." where exam_group_id='".$examGroupId."'")->execute(); $transaction->commit(); return true; } catch (\Exception $e) { $transaction->rollBack(); debug($e); return false; } } //自动分配 public function autoApply($userId){ if(!$userId) return false; $transaction = $this->getDbConnection()->beginTransaction(); try { $ExamInfo=$this->getDbConnection()->createCommand("select exam_group_id,answer_sheet_task,paper_task,parse_task from assist_task where operator=0 and (answer_sheet_task=1 or paper_task=1 or parse_task=1) order by create_time asc limit 1")->queryRow(); if(!$ExamInfo ) return false; $updateTask=array(); $time=time(); if($ExamInfo['answer_sheet_task']==1){ $updateTask[]=" `answer_sheet_task`=2 "; $updateTask[]=" `ast_update_time`= {$time}"; $updateTask[]=" `ast_apply_time`= {$time}"; } if($ExamInfo['paper_task']==1){ $updateTask[]=" `paper_task`=2 "; $updateTask[]=" `ppt_update_time`= {$time}"; $updateTask[]=" `ppt_apply_time`= {$time}"; } if($ExamInfo['parse_task']==1){ $updateTask[]=" `parse_task`=2 "; $updateTask[]=" `pat_update_time`= {$time}"; $updateTask[]=" `pat_apply_time`= {$time}"; } $updateTask[]=" `update_time`= {$time}"; $updateTask[]=" `operator`='".$userId."'"; $this->getDbConnection()->createCommand("update assist_task set ".implode(",",$updateTask)." where exam_group_id='".$ExamInfo['exam_group_id']."'")->execute(); $transaction->commit(); return true; } catch (\Exception $e) { $transaction->rollBack(); return false; } catch (\Throwable $e) { $transaction->rollBack(); return false; } } public function countTask($where=array()){ $sql="select count(*) as count from assist_task "; if($where){ $sql.=" where ".implode(' and ',$where); } $data=$this->getDbConnection()->createCommand($sql)->queryRow(); if($data){ return $data['count']; } } public function getHandleTask($uid){ if(!$uid) return 0; $sql="select count(*) as count from assist_task where (answer_sheet_task=2 or paper_task=2 or parse_task=2) and operator='".$uid."'"; $data=$this->getDbConnection()->createCommand($sql)->queryRow(); if($data){ return $data['count']; } } public function getGroupServer($tableName){ $sql="select * from `".$tableName."` "; $data=$this->getDbConnection()->createCommand($sql)->queryAll(); return $data; } }