1, 'isp'=>2, 'studytrend'=>3,'third_wb'=>1,'third_isp'=>3); $subjectId = Yii::app()->session['session_duoxueke_subject_id']?Yii::app()->session['session_duoxueke_subject_id']:3; if(in_array($subjectId,$this->mathSubjectId)){ $exam_subject_id = $this->mathSubjectId; }else{ $exam_subject_id = array($subjectId); } $examNum = 0;//可生成的考试数量 $studentNum = 0;//可生成的学生数量 $examAddTime = array();//考试发送打印时间 if (!isset($productTypeArr[$printType])) { $error[] = '产品类型参数不正确'; } //获取本学期7天外的考试 if (!$error) { $time = time() - 7 * 24 * 3600; $criteria = new CDbCriteria(); $criteria->select= 'exam_id,exam_group_id,class_id,is_backlog,subject_id'; $criteria->addCondition('`semester_id` = '.$this->semesterId); $criteria->addInCondition('subject_id',$exam_subject_id); $criteria->addCondition('`status` = 1'); $criteria->addCondition('complete_time < '.$time); $result = Exam::model()->findAll($criteria); if (!$result) { $error[] = '没有需要处理的考试'; } } //判断有没有发送打印 if (!$error) { $examInfo = array(); foreach ($result as $value) { $examInfo[$value->exam_id] = array( 'is_backlog'=>$value->is_backlog, 'class_id'=>$value->class_id, 'exam_group_id'=>$value->exam_group_id, 'subject_id'=>$value->subject_id, ); } unset($result); $examIds = array_keys($examInfo); $criteria = new CDbCriteria(); $criteria->select= 'exam_id'; $criteria->addInCondition('exam_id',$examIds); $criteria->addCondition('`type` = '.$productTypeArr[$printType]); $result = ClassExamPrinter::model()->findAll($criteria); if ($result) { foreach ($result as $value) { if (isset($examInfo[$value->exam_id])) { unset($examInfo[$value->exam_id]); } } } unset($result); if (!$examInfo) { $error[] = '没有需要处理的考试'; } } //获取发送打印时间 if (!$error) { $examIds = array_keys($examInfo); $criteria = new CDbCriteria(); $criteria->select= 'exam_id,add_time'; $criteria->addInCondition('exam_id',$examIds); $criteria->addCondition('`type` = 0'); $result = ClassExamPrinter::model()->findAll($criteria); if ($result) { foreach ($result as $value) { if (isset($examInfo[$value->exam_id])) { $examAddTime[$value->exam_id] = $value->add_time; } } } } //过滤标注 if (!$error) { $examIds = array_keys($examInfo); $criteria = new CDbCriteria(); $criteria->select= 'exam_id'; $criteria->addInCondition('exam_id',$examIds); $criteria->addCondition('`is_labelled` = 1'); $result = SPaper::model()->findAll($criteria); $_examInfo = array(); if ($result) { foreach ($result as $value) { if (isset($examInfo[$value->exam_id])) { $_examInfo[$value->exam_id] = $examInfo[$value->exam_id]; } } } if ($_examInfo) { $examInfo = $_examInfo; unset($_examInfo); }else{ $error[] = '没有需要处理的考试'; } } //导入成绩和线下阅卷必须点代办 if (!$error) { $examGroupIds = array(); $offlineExam = array();//线下考试 $importScoreExam = array();//导入成绩的考试 foreach ($examInfo as $value) { $examGroupIds[$value['exam_group_id']] = $value['exam_group_id']; } if ($examGroupIds) { $examGroupIds = array_keys($examGroupIds); $criteria = new CDbCriteria(); $criteria->select= 'exam_group_id,import_score_type,mark_type'; $criteria->addInCondition('exam_group_id',$examGroupIds); // $criteria->addCondition('`mark_type` = 0'); $result = SExamGroup::model()->findAll($criteria); if ($result) { foreach ($result as $value) { if ($value->mark_type == 0) { $offlineExam[$value->exam_group_id] = $value->exam_group_id; } if ($value->import_score_type == 3) { $importScoreExam[$value->exam_group_id] = $value->exam_group_id; } } } } //删除线下阅卷没点代办 foreach ($examInfo as $examId => $value) { if ((isset($offlineExam[$value['exam_group_id']]) && $value['is_backlog'] == 0) || (isset($importScoreExam[$value['exam_group_id']]) && $value['is_backlog'] == 0)) { unset($examInfo[$examId]); } } if (!$examInfo) { $error[] = '没有需要处理的考试'; } } //过滤没下订单的考试 if (!$error) { foreach ($examInfo as $examId => $value) { $classId = $value['class_id']; $semester=new SSemester(); $nowsem = $semester->getCurrentSemester(); $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId)); //考试关联的学生 $criteria = new CDbCriteria(); $criteria->select= 'student_id'; $criteria->addCondition('`exam_id` = '.$examId); $result = SStudentPaperRelation::model()->findAll($criteria); $studentsIds = $this->getColumns($result, 'student_id'); unset($result); $orderStudentIds = array(); $errorMsg = ''; if ($studentsIds) { if(in_array($value['subject_id'],$this->mathSubjectId)){ $int_subject_id = 3; }else{ $int_subject_id = $value['subject_id']; } $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$classId, "semester"=>$nowsem['refer_code'], "grade"=>$classinfo['grade'], "students"=>$studentsIds, "examTime"=>isset($examAddTime[$examId])?$examAddTime[$examId]:0, "classify"=>$productTypeArr[$printType], "subject"=>$int_subject_id, ); list($orderStudentIds,$errorMsg) = $this->getStuOrder($intarr); if ($errorMsg) { $error[] = $errorMsg; } } if (!$orderStudentIds) { unset($examInfo[$examId]); }else{ $examNum += 1; $studentNum += count($orderStudentIds); } } if (!$examInfo) { $error[] = '没有需要处理的考试'; } } //插入数据 if (!$error) { $time = time(); $value_arr = array(); foreach ($examInfo as $examId => $value) { $value_arr[] = "({$value['class_id']},{$examId},{$productTypeArr[$printType]},0,0,0,{$time},{$time})"; } $sql = "insert into class_exam_printer (class_id,exam_id,`type`,is_print,is_print_online,is_checked,print_time,add_time) values ".implode(',',$value_arr); $dbConn = ClassExamPrinter::model()->getDbConnection(); $bool = $dbConn->createCommand($sql)->execute(); if ($bool === false) { $error[] = '操作失败'; } } if (!$error) { $data['status'] = 1; $data['data'] = array( 'exam_num' => $examNum, 'student_num' => $studentNum, ); }else{ $data['message'] = implode(PHP_EOL, $error); } exit(json_encode($data)); } /** * 获取学生是否有订单 * @param $intarr * @param $stuids */ protected function getStuOrder($intarr){ $msg = ''; $stuids = array(); $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic)); if (!$rs) { $msg = '订单接口错误'; }else{ if (!empty($rs->data)) { $stuids = $rs->data; } } return array($stuids,$msg); } protected function getColumns($obj,$key) { $rs = array(); if ($obj) { foreach ($obj as $_obj) { if (isset($_obj->$key)) { $_key = (string)$_obj->$key; $rs[$_key] = $_key; } } } if ($rs) { $rs = array_values($rs); } return $rs; } }