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_scan_task "; if($where){ $sql.=' where '.implode(' and ',$where); } $offset=($page-1)*$pageLimit; $sql.=" order by resend_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,scan_task from assist_scan_task where exam_group_id='".$examGroupId."'")->queryRow(); if(!$ExamInfo ) return false; $updateTask=array(); $time=time(); if($ExamInfo['scan_task']==1){ $updateTask[]=" `scan_task`=2 "; $updateTask[]=" `scan_task_apply_time`= {$time}"; $updateTask[]=" `scan_task_update_time`= {$time}"; } $updateTask[]=" `update_time`= {$time}"; $updateTask[]=" `operator`='".$userId."'"; $this->getDbConnection()->createCommand("update assist_scan_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,scan_task from assist_scan_task where operator=0 and scan_task<>4 order by create_time asc limit 1")->queryRow(); if(!$ExamInfo ) return false; $updateTask=array(); $time=time(); if($ExamInfo['scan_task']==1){ $updateTask[]=" `scan_task`=2 "; $updateTask[]=" `scan_task_apply_time`= {$time}"; $updateTask[]=" `scan_task_update_time`= {$time}"; } $updateTask[]=" `update_time`= {$time}"; $updateTask[]=" `operator`='".$userId."'"; $this->getDbConnection()->createCommand("update assist_scan_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_scan_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_scan_task where scan_task=2 and operator='".$uid."'"; $data=$this->getDbConnection()->createCommand($sql)->queryRow(); if($data){ return $data['count']; } } }