session['session_duoxueke_subject_id']; $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId; //分层作业 个性化学习手册 分层测评卷 分层作业数学物理3级目录,其他全是2级目录 $level=2; if($type==1 && in_array($subjectId,array(3,6,51,12))){ $level=3; } //版本 模块 单元 章节 $textbooks=$modules=$units=$chapters=array(); $postRs = $this->apiPost('all_textbook/getTextbookBySubjectId', array( 'subjectId' => $subjectId,'type'=>1)); $textbookResult=json_decode(json_encode($postRs),true); if(isset($textbookResult['status']) && $textbookResult['status'] && isset($textbookResult['data']) && $textbookResult['data']){ $textbookResult=$textbookResult['data']; foreach($textbookResult as $textbookKey=>$textbookItem){ $textbooks[]=array('textbook_id'=>$textbookItem['textbook_id'],'textbook_name'=>$textbookItem['textbook_name']); if($textbookKey==0 && isset($textbookItem['child']) && $textbookItem['child']){ foreach($textbookItem['child'] as $moduleKey=>$moduleItem){ $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']); if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){ foreach($moduleItem['child'] as $unitKey=>$unitItem){ $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']); if($unitKey==0 && isset($unitItem['child']) && $unitItem['child']){ foreach($unitItem['child'] as $chapterItem){ $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']); } } } } } } } } //分层测评卷-高三备考的类别和试卷 $productDetailsResult=$this->apiPost('all_product/getProductDetails',array('subjectId'=>$subjectId,)); $productDetailsResult=json_decode(json_encode($productDetailsResult),true); $productDetails=array(); if(isset($productDetailsResult['status']) && $productDetailsResult['status'] && isset($productDetailsResult['data']) && $productDetailsResult['data']){ $productDetails=$productDetailsResult['data']; } $data=array( 'year' => $year = date("Y"), 'month' => $month = (int)date("m"), 'week' => $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1, 'textbooks'=>$textbooks,//版本 'modules'=>$modules,//模块 'units'=>$units,//单元 'chapters'=>$chapters,//章节 'level'=>$level, 'type'=>$type, 'productDetails'=>$productDetails, 'subjectId'=>$subjectId, ); $this->render('index', $data); } /** * 导出 */ public function actionExportExcel(){ $type=(int)Req::get('type');//类型 1分层作业 2个性化学习手册 3分层测评卷 $textbookId = (int)Req::get('textbookId');//版本 $moduleId = (int)Req::get('moduleId');//模块 $unitId = (int)Req::get('unitId');//单元 $unitName = Req::get('unitName');//单元名称 $chapterId = (int)Req::get('chapterId');//节 $chapterName = Req::get('chapterName');//节名称 $grade = (int)Req::get('grade');//年级 $classIdsStr = trim(Req::get('selectClassIds'),',');//班级 $markPaperType = (int)Req::get('markPaperType');//分层测评卷类型 $layoutType = (int)Req::get('layoutType');//分层测评卷类别 $layoutPaper = (string)Req::get('layoutPaper');//分层测评卷试卷 $layoutPaperName = (string)Req::get('layoutPaperName');//分层测评卷试卷名称 $level = (int)Req::get('level');//层级目录 $subjectId=Yii::app()->session['session_duoxueke_subject_id']; $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId; if(!$classIdsStr){ exit("请后退,缺少班级"); } $classIds=explode(',',$classIdsStr); $classIdsStr=implode(',',$classIds); $sql="select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_id in ($classIdsStr) and class_type=1 and is_hide=0 and grade={$grade}"; $classInfo= $this->sConn->createCommand($sql)->queryAll(); $classInfo=_array_column($classInfo,'class_name','class_id'); $header=array('X-Basic-V:2',"schoolId:{$this->schoolId}"); $cgi=Yii::app()->params['cgi']; $postParam=array( "clazzIds"=>$classIds, "schoolId"=>$this->schoolId, "subjectId"=>$subjectId, ); $username=$cgi['username']; $password=$cgi['password']; $url=$cgi['domain'].'qxk/academic/student-stat/student-level';//是否可以创建新版词汇组 $rs=$this->CrmApiPost($url,$postParam,$username,$password,'POST',$header); $rs=json_decode(json_encode($rs),true); $studentLevelArr=array(); if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data'])){ $studentLevelArr=$rs['data']; } if(!$studentLevelArr){ exit('获取层级数据为空'); } //每个班级的初始化数据 $classLevelArr=array(); foreach($classIds as $itemClassId){ $classLevelArr[$itemClassId]=array( 1=>array('count'=>0,'lists'=>array()), 2=>array('count'=>0,'lists'=>array()), 3=>array('count'=>0,'lists'=>array()) ); } $productTypeNameArr=array(1=>'分层作业',2=>'个性化学习手册',3=>'分层测评卷');//所有产品 $excelFileName='e学惠通';//产品名称 规则:末级章节+“_"+ 产品类型,如:1.2 函数的定义_分层测评卷 $productTypeName=''; if(isset($productTypeNameArr[$type])){ $productTypeName=$productTypeNameArr[$type]; if(in_array($type,array(1,2)) || ($type==3 && $markPaperType==1)){ if($level==3){ $excelFileName=$chapterName; }else{ $excelFileName=$unitName; } $excelFileName=$excelFileName?$excelFileName.'_'.$productTypeNameArr[$type]:$productTypeNameArr[$type]; }elseif($type==3 && $markPaperType==2){ $excelFileName=$layoutPaperName?$layoutPaperName.'_'.$productTypeNameArr[$type]:$productTypeNameArr[$type]; } } $excelFileName.='_'.time(); $levelArr=array(1=>'Ⅰ类', 2=>'Ⅱ类', 3=>'Ⅲ类',);//三个等级及对应的文字 $levelTotal=array(1=>0,2=>0,3=>0);//三个层级的总份数 $total=0;//总份数 $classStudentTotalArr=array();//班级总份数 $studentIdsStr=''; foreach($studentLevelArr as $item){ $studentIdsStr.=$item['studentId'].','; } $studentIdsStr=trim($studentIdsStr,','); $sql="select student_id,realname from student_info where student_id in ($studentIdsStr) "; $students= $this->sConn->createCommand($sql)->queryAll(); $students=_array_column($students,'realname','student_id'); foreach($studentLevelArr as $item){ $classId=$item['clazzId']; $studentId=$item['studentId']; $studentLevel=$item['level']; if(!isset($classLevelArr[$classId][$studentLevel])){ continue; } $studentName=isset($students[$studentId])?$students[$studentId]:''; unset($students[$studentId]); $classLevelArr[$classId][$studentLevel]['lists'][]=array('student_id'=>$studentId,'student_name'=>$studentName); $classLevelArr[$classId][$studentLevel]['count']=$classLevelArr[$classId][$studentLevel]['count']+1; $levelTotal[$studentLevel]=$levelTotal[$studentLevel]+1; $total++; if(!isset($classStudentTotalArr[$classId])){ $classStudentTotalArr[$classId]=0; } $classStudentTotalArr[$classId]=$classStudentTotalArr[$classId]+1; } $levelTotalArr=array(); foreach($levelTotal as $studentLevel=>$itemTotal){ $levelTotalArr[$studentLevel]="共{$itemTotal}份"; } unset($studentLevelArr);unset($studentIdsStr);unset($levelTotal); $obpe = new PHPExcel(); $obpe->setactivesheetindex(0); $obpe->getActiveSheet()->setTitle($productTypeName); $obpe->getActiveSheet()->mergeCells('A1:C1');//合并 $obpe->setActiveSheetIndex(0)->setCellValue("A1","总计:共{$total}份");//总计 $start=1; //非分层测评卷-高三备考 if(!($type==3 && $markPaperType==2)) { $totalData = array( $levelArr, $levelTotalArr, ); foreach ($totalData as $k => $v) { $start++; /* @func 设置列 */ $obpe->getactivesheet()->setcellvalue('A' . $start, $v[1]); $obpe->getactivesheet()->setcellvalue('B' . $start, $v[2]); $obpe->getactivesheet()->setcellvalue('C' . $start, $v[3]); } } $start=$start+2; foreach($classLevelArr as $keyClassId=>$classData){ $className=isset($classInfo[$keyClassId])?$classInfo[$keyClassId]:''; $classTotal=isset($classStudentTotalArr[$keyClassId])?$classStudentTotalArr[$keyClassId]:''; $classTitle="{$className} 共{$classTotal}人"; $obpe->getActiveSheet()->mergeCells("A{$start}:C{$start}"); $obpe->setActiveSheetIndex(0)->setCellValue("A{$start}",$classTitle); $max=0;//增加最大的行数 $originNum = 65;//A对饮的ascii码 //非分层测评卷-高三备考(分层测评卷-高三备考不需要层次和学科信息) if(!($type==3 && $markPaperType==2)) { foreach ($classData as $studentLevel => $levelData) { $index = $start; $col =chr($originNum); $levelName = isset($levelArr[$studentLevel]) ? $levelArr[$studentLevel] : ''; $index++; $obpe->getactivesheet()->setcellvalue($col . $index, "{$levelName}"); $index++; $obpe->getactivesheet()->setcellvalue($col . $index, "共{$levelData['count']}人"); $max = $levelData['count'] + 2 > $max ? $levelData['count'] + 2 : $max; foreach ($levelData['lists'] as $studentInfo) { $index++; $obpe->getactivesheet()->setcellvalue($col . $index, $studentInfo['student_name']); } $originNum++; } } $start=$start+$max+2; } unset($classLevelArr);unset($classInfo);unset($classStudentTotalArr); //创建一个新sheet 下载地址 $obpe->createSheet(); $obpe->setactivesheetindex(1); $obpe->getActiveSheet()->setTitle('下载地址'); //分层测评卷-高三备考 if($type==3 && $markPaperType==2){ $data = array( array('url'=>'地址'), array('url'=>$layoutPaper), ); foreach($data as $k=>$v){ $k = $k+1; $obpe->getactivesheet()->setcellvalue('A'.$k, $v['url']); } }else{//非分层测评卷-高三备考 //201-同步分层练习 202-阶段学习手册 203-高一高二单元训练卷 204-高三备考训练卷 $productTypeArr=array(1=>201,2=>202,3=>203); $productType=isset($productTypeArr[$type])?$productTypeArr[$type]:0; $gpId=$level==3?$chapterId:$unitId; //新高考 数学、物理-分层测评卷(同步/一轮) 英语-分层作业、个性化学习手册、分层测评卷(同步/一轮) 表里sub_type默认为0 if(($type==3 && in_array($subjectId,array(3,12)) && $markPaperType==1) || ($subjectId==8 && $markPaperType!=2)) { $examType=1; $schoolInfo = BusinessSchool::model()->find('school_id=:sid', array(':sid' => $this->schoolId)); if (isset($schoolInfo['province_id'])) { $provinceGradeIsnewResult = $this->apiPost('all_content/provinceGradeIsnew', array('subjectId' => array($subjectId), 'provinceId' => $schoolInfo['province_id'], 'grade' => $grade)); $provinceGradeIsnewResult = json_decode(json_encode($provinceGradeIsnewResult), true); if (isset($provinceGradeIsnewResult['status']) && $provinceGradeIsnewResult['status'] && isset($provinceGradeIsnewResult['data'][0]['is_new'])) { $examType = $provinceGradeIsnewResult['data'][0]['is_new']; } } $subType=$examType; }else{ $subType=0; } $sql="SELECT student_id,qcloud_url FROM `layered_isp_qcloud` where gp_id=$gpId and product_type={$productType} and subject_id={$subjectId} and sub_type={$subType} group by student_id order by student_id"; $layeredIspQclouds=Yii::app()->businessDb->createCommand($sql)->queryAll(); $layeredIspQclouds=_array_column($layeredIspQclouds,'qcloud_url','student_id'); $data = array( array('level'=>'层次','url'=>'地址'), array('level'=>'Ⅰ类','url'=>isset($layeredIspQclouds[1])?$layeredIspQclouds[1]:''), array('level'=>'Ⅱ类','url'=>isset($layeredIspQclouds[2])?$layeredIspQclouds[2]:''), array('level'=>'Ⅲ类','url'=>isset($layeredIspQclouds[3])?$layeredIspQclouds[3]:''), ); foreach($data as $k=>$v){ $k = $k+1; /* @func 设置列 */ $obpe->getactivesheet()->setcellvalue('A'.$k, $v['level']); $obpe->getactivesheet()->setcellvalue('B'.$k, $v['url']); } } $obpe->setactivesheetindex(0); //写入类容 $obwrite = PHPExcel_IOFactory::createWriter($obpe, 'Excel5'); ob_end_clean(); //直接在浏览器输出 header("Accept-Ranges:bytes"); header('Content-Type:application/vnd.ms-excel'); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header("Content-Disposition:attachment;filename={$excelFileName}.xls"); header('Cache-Control:max-age=0'); $obwrite->save('php://output'); } /** * 设置 */ public function actionAjaxSaveSetting(){ $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $type=(int)Req::post('type');//类型 1分层作业 2个性化学习手册 3分层测评卷 $textbookId = (int)Req::post('textbookId');//版本 $moduleId = (int)Req::post('moduleId');//模块 $unitId = (int)Req::post('unitId');//单元 $chapterId = (int)Req::post('chapterId');//节 $grade = (int)Req::post('grade');//年级 $classIds = Req::post('selectClassIds');//班级 $markPaperType = (int)Req::post('markPaperType');//分层测评卷类型 $layoutType = (int)Req::post('layoutType');//分层测评卷类别 $layoutPaper = (string)Req::post('layoutPaper');//分层测评卷试卷 $level = (int)Req::post('level');//层级 if(!in_array($type,array(1,2,3))){ $error[] = '请选择分层作业或个性化学习手册或分层测评卷'; } if($type==1 || $type==2 || ($type==3 && $markPaperType==1)){ if(!$unitId){ $error[] = '单元数据不能为空'; } if($level==3 && !$chapterId){ $error[] = '节数据不能为空'; } } if($type==3 && !in_array($markPaperType,array(1,2))){ $error[] = '分层测评卷时请选择同步/一轮或高三备考'; } if($type==3 && $markPaperType==2){ if(!$markPaperType){ $error[] = '分层测评卷类型不能为空'; } if(!$layoutType){ $error[] = '分层测评卷类别不能为空'; } if(!$layoutPaper){ $error[] = '分层测评卷-高三备考试卷不能为空'; } } if(!$grade){ $error[] = '请选择年级'; } if(!$classIds){ $error[] = '请选择班级'; } $subjectIds=$this->subjectId; if(in_array($subjectIds,array(3,6,51))){ $subjectIds=array(3,6,51); }else{ $subjectIds=array($subjectIds); } $subjectIds=implode(',',$subjectIds); $classIdsStr=implode(',',$classIds); $sql="select class_id from exam where class_id in ({$classIdsStr}) and status=1 and subject_id in ({$subjectIds}) group by class_id"; $examInfo = $this->sConn->createCommand($sql)->queryAll(); $examClassIds=_array_column($examInfo,'class_id'); if(count($classIds)!=count($examClassIds)){ $diff=array_diff($classIds,$examClassIds); $diffClassIdsStr=implode(',',$diff); $sql="select class_id,class_name from class where class_id in ({$diffClassIdsStr})"; $classInfo=$this->sConn->createCommand($sql)->queryAll(); if(!$classInfo){ $error[] = '没有查到班级数据'; } $classNames=implode(',',_array_column($classInfo,'class_name')); $msg="{$classNames},班级无考试数据!
无考试数据的班级,可以至试卷管理中导入一场考试数据"; $error[] = $msg; } } if ($error) { exit(json_encode(array('status' => 0, 'error' => $error))); } else { exit(json_encode(array('status' => 1))); } } public function actionAjaxGetClasses(){ $result = array(); $grade=(int)Req::post('grade'); if($grade){ $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0"; $result = $this->sConn->createCommand($sql)->queryAll(); } echo json_encode($result);exit; } public function CrmApiPost($url, $arr, $username,$password,$type='POST',$header=array()) { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); $headerArr=array( 'Content-Type: application/json', 'Content-Length: '. strlen($data), 'Connection: false', 'Expect:' ); if($header){ $headerArr=array_merge($headerArr,$header); } if($type=='POST'){ // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT,120); curl_setopt($ch, CURLOPT_NOSIGNAL,1); curl_setopt($ch, CURLOPT_TIMEOUT_MS,120000); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr); if( !curl_errno($ch)) { $result = json_decode(curl_exec($ch)); } // 释放资源 curl_close($ch); }elseif($type=='PUT'){ $data = json_encode($arr); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr); $result = json_decode(curl_exec($ch)); curl_close($ch); } } return $result; } }