123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <?php
- /**
- * 打印过期产品
- * User: Administrator
- * Date: 2020/5/20 0020
- * Time: 18:07
- */
- class HistoryProductController extends Controller
- {
- /**
- * 显示出过期有学生下订单的产品列表
- */
- public function actionViewProduct()
- {
- $data = $error = array();
- $data['status'] = 0;
- $data['message'] = '';
- $data['data'] = array();
- $printType = Req::post("printType");
- $productTypeArr = array('wtb'=>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;
- }
- }
|