123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- /**
- * @author: CeeFee
- * @description: 考试
- */
- class AScanTask extends BusinessActiveRecord {
- public static function model($className = __CLASS__){
- return parent::model($className);
- }
- public function tableName(){
- return "assist_scan_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_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'];
- }
- }
- }
|