123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * @author: CeeFee
- * @description: 考试
- */
- class ATask extends BusinessActiveRecord {
- public static function model($className = __CLASS__){
- return parent::model($className);
- }
- public function tableName(){
- return "assist_task";
- }
- public function primaryKey(){
- return array('exam_group_id');
- }
- //读取任务详情
- public function getTaskByExamGroupId($examGroupId){
- $criteria = new CDbCriteria();
- $criteria->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;
- }
- }
|