123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- <?php
- /**
- *
- * 词汇宝
- *
- */
- class WritingController extends Controller
- {
- /**
- * 英语写作宝列表
- */
- public function actionIndex(){
- Url::clean();
- $data = array();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $grade = (int)Req::get("grade");
- $newCondition = array();
- if($grade){
- $newCondition[] = 'ew.grade='.$grade;
- }
- if($printName){
- $newCondition[] = 'ew.name like "%'.$printName.'%"';
- }
- if($classId){
- $newCondition[] = 'ew.class_id='.$classId;
- }
- $newCondition[] = "ew.semester_id = '{$this->semesterId}'";
- $newCondition[] = "ews.product_type = 32";
- $magicWordModel = new SEnglishWriting();
- $resultList = $magicWordModel->getWritingList($newCondition,array('ew.create_time desc','ew.ew_id desc'),9);
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k]=$v;
- }
- }
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $classes = $this->schoolManager->getClasses($grade);
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data['printList'] = $printList;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data['printType'] = 'english_writing';
- // debug($printList);
- $this->render('index',$data);
- }
- /**
- * 写作宝选择学生
- */
- public function actionStu(){
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $ew_id = (string)Req::get("ew_id");
- if(!$ew_id){
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及产品名称
- $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from english_writing ew join class c on ew.class_id = c.class_id where ew.ew_id = '{$ew_id}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if(!$names){
- $names = array();
- $names['name'] = '';
- $names['class_name'] = '';
- $names['grade'] = 0;
- }else{
- $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:'';
- }
- $sql = "select student_id,is_week_pdf from english_writing_student where ew_id = '{$ew_id}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if($relateStudent){
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
- }
- }
- if($studentIds){
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- $markingStudents = SEnglishWritingMarking::model()->getStuMarkingStatus($studentIds,$ew_id);
- if($studentNames){
- if($sname){
- $i = 1;
- foreach($studentNames as $k=>$v){
- if(strpos($v,$sname) !== false){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $data['list'][$i]['is_marking'] = isset($markingStudents[(string)$k])?$markingStudents[(string)$k]:0;
- $i++;
- }
- }
- }else{
- $i = 1;
- foreach($studentNames as $k=>$v){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $data['list'][$i]['is_marking'] = isset($markingStudents[(string)$k])?$markingStudents[(string)$k]:0;
- $i++;
- }
- }
- }
- }
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$names['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$names['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$names['grade'],
- "students"=>$studentIds,
- "examTime"=>$names['create_time'],
- "classify"=>32,
- "subject"=>8
- );
- $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){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- Yii::app()->jump->error($rs->errMsg);
- }
- if(!empty($rs->data)){
- $data['limitstu']=$rs->data;
- }
- $data['ew_id'] = $ew_id;
- $data['sname'] = $sname;
- $data['printType'] = 'english_writing';
- $this->render('stu',$data);
- }
- /**
- * 英语词汇宝设置
- */
- public function actionSetting(){
- $data = array();
- $data['year'] = $year = date("Y");
- $data['month'] = $month = (int)date("m");
- $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- //写作指导
- $data['groupList'] = $this->getDbConnection()->createCommand("select g.ewg_id,g.`name`,g.create_time,t.teacher_name,g.topic_type from english_writing_guidance g
- inner join teacher t on t.teacher_id=g.teacher_id where g.is_delete=0
- order by g.create_time DESC;")->queryAll();
- //最近一次设置选项
- $data['printType'] = 'setting';
- $this->render('setting',$data);
- }
- /**
- * 设置英语写作宝
- */
- public function actionAjaxSaveSetting(){
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $grade=(int)Req::post('grade');
- $classIds = Req::post('selectClassIds');
- $ewgId = (string)Req::post('ewg_id');
- $scanType=(int)Req::post('scan_type');
- $writingType=(int)Req::post('writing_type');
-
- if(empty($ewgId)){
- $error[] = '请选择教师端写作指导';
- }
- if(!$grade){
- $error[] = '请选择年级';
- }
- if(!$classIds){
- $error[] = '请选择班级';
- }
- }
- if(!$error){
- $time = time();
- $week = date("W");
- $year = date("Y");
- $strModel = new SStudentClassRelation();
- $transaction = $this->sConn->beginTransaction();
- try{
- $groupId = getUniqueId($this->schoolId);
- if ($grade == 3) {
- $productName = '高三' . date('Y') . '年第' . date('W') . '周写作宝';
- }elseif($grade == 2){
- $productName = '高二' . date('Y') . '年第' . date('W') . '周写作宝';
- }else{
- $productName = '高一' . date('Y') . '年第' . date('W') . '周写作宝';
- }
- $this->sConn->createCommand()->insert('english_writing_setting',array(
- 'ew_group_id'=>$groupId,
- 'name' => $productName,
- 'grade' => $grade,
- 'topic_no' => date('mdHis',$time),
- 'semester_id' => $this->semesterId,
- 'create_time' => $time,
- 'ewg_id' => $ewgId,
- 'scan_type'=>$scanType,
- 'writing_type'=>$writingType,
- 'product_type'=>32
- ));
- $gpIds = array();
- foreach($classIds as $k=>$v){
- $weekId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('english_writing',array(
- 'ew_group_id' => $groupId,
- 'ew_id' => $weekId,
- 'name' => $productName,
- 'class_id' => $v,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'year_num' => $year,
- 'week_num' => $week,
- 'create_time' => $time,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($v);
- if($stuData){
- foreach($stuData as $kk=>$vv){
- $this->sConn->createCommand()->insert('english_writing_student',array(
- 'ew_id' => $weekId,
- 'student_id' => $vv['student_id'],
- ));
- }
- }
- array_push($gpIds, $weekId);
- }
- //更新写作卡使用次数
- //$this->sConn->createCommand()->update("english_writing_guidance", array("writing_card_num" => new CDbExpression('writing_card_num+1')), "ewg_id = '{$ewgId}'");
- // //发送消息
- // $sendMsg=array(
- // 'school_id'=>$this->schoolId,
- // 'subject_id'=>$this->subjectId,
- // 'msg_type'=>1,
- // 'grade'=>$grade,
- // 'send_type'=>'english_writing',
- // 'product_type'=>array(1),
- // 'gp_group_id'=>$groupId,
- // 'gp_ids'=>$gpIds
- // );
- // sendDataToKafka('xbkc-php-product-html',$sendMsg);
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- //发送消息
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'subject_id'=>$this->subjectId,
- 'msg_type'=>1,
- 'grade'=>$grade,
- 'send_type'=>'english_writing',
- 'product_type'=>array(1),
- 'gp_group_id'=>$groupId,
- 'gp_ids'=>$gpIds
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- }
- if($error){
- echo json_encode(array('status'=>0,'error'=>$error));exit;
- }else{
- echo json_encode(array('status'=>1));exit;
- }
- }
- //获取词汇宝产品班级
- public function actionAjaxGetClasses(){
- $result = array();
- $grade=(int)Req::post('grade');
- $year = date("Y");
- $week = date("W");
- //获取班级
- $hasSettingClassIds = array();
- $sql="select class_id,count(*) count from english_writing ew left join english_writing_setting ews on ews.ew_group_id=ew.ew_group_id where product_type=32 and year_num = {$year} and week_num = {$week} group by class_id";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- foreach($data as $k=>$v){
- if($v['count'] > 0){
- $hasSettingClassIds[$v['class_id']] = $v['count'];
- }
- }
- }
- $classIds = array();
- $setting = $this->getDbConnection()->createCommand("select * from english_writing_setting order by create_time desc")->queryRow();
- if($setting) {
- $classIds = $this->sConn->createCommand("select class_id from english_writing where ew_group_id={$setting['ew_group_id']}")->queryColumn();
- }
- if($grade){
- $zouban_sql = "select * from classified where subject_id = 8 and semester_id = '{$this->semesterId}' and grade = {$grade} and `status` = 1";
- $classified_data = $this->sConn->createCommand($zouban_sql)->queryRow();
- if($classified_data){
- $sql = "select c.class_id,c.class_name "
- . "from class c join class_subject_relation csr on c.class_id=csr.class_id "
- . "where c.semester_id='{$this->semesterId}' and csr.subject_id = 8 and c.grade = {$grade} and c.class_type = 2 and c.is_hide=0 group by c.class_id";
- }else{
- $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
- }
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- $i = 0;
- foreach($data as $k => $v){
- $sql = "select count(student_id) count from student_class_relation where class_id = '{$v['class_id']}' and status = 0";
- $class_student = $this->sConn->createCommand($sql)->queryRow();
- if($class_student && $class_student['count']>0){
- $result[$i]['class_id'] = $v['class_id'];
- $result[$i]['class_name'] = $v['class_name'];
- $result[$i]['status'] = isset($hasSettingClassIds[$v['class_id']])&&$hasSettingClassIds[$v['class_id']]>=5?1:0;
- $result[$i]['count'] = isset($hasSettingClassIds[$v['class_id']])?$hasSettingClassIds[$v['class_id']]:0;
- $result[$i]['selected'] = in_array($v['class_id'], $classIds) ? true : false;
- $i++;
- }
- }
- }
- }
- echo json_encode($result);exit;
- }
- //确认完成写作卡上传
- public function actionConfirmUpload()
- {
- $ew_id = (string)Req::get("ew_id");
- if(empty($ew_id)){
- echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
- }
- $model = SEnglishWriting::model()->find("ew_id=:ew_id", array(':ew_id'=>$ew_id));
- $this->sConn->createCommand()->update("english_writing", array("marking_status" => 1), "ew_id = '{$ew_id}'");
- //发送消息
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>1,
- 'grade' => $model['grade'],
- 'subject_id'=>$this->subjectId,
- 'send_type'=>'english_writing',
- 'product_type'=>array(2),
- 'gp_group_id'=>$model['ew_group_id'],
- 'gp_ids'=>array($ew_id)
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- echo json_encode(array('status'=>1));exit;
- }
- //恢复上传
- public function actionResumeUpload()
- {
- $ew_id = (string)Req::get("ew_id");
- if(empty($ew_id)){
- echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- $this->sConn->createCommand()->update("english_writing", array("marking_status" => 0, "is_marking_all_html" => 0), "ew_id = '{$ew_id}'");
- $this->sConn->createCommand()->update("english_writing_student", array("is_card_html" => 0), "ew_id = '{$ew_id}'");
- $transaction->commit();
- }catch (\Exception $e){
- $transaction->rollBack();
- echo json_encode(array('status'=>0,'message'=>$e->getMessage()));exit;
- }
- echo json_encode(array('status'=>1));exit;
- }
- /**
- * 英语写作宝教师版下载
- * @throws CException
- */
- public function actionTeacherWeek(){
- set_time_limit(0);
- $ewId = safe_replace(Yii::app()->request->getQuery('mwId'));
- $isPrint = safe_replace(Yii::app()->request->getQuery('isPrint'));
- $sql = "select * from teacher_writing where ew_id = '{$ewId}'";
- $week_info = $this->sConn->createCommand($sql)->queryAll();
- $teacher_extend_arr = array();
- foreach($week_info as $info)
- {
- $content = stripslashes($info['content']);
- $content = substr($content,1,-1);
- $content = json_decode($content,true);
- $teacher_extend_arr[$info['type']] = $content;
- }
- $sql = "select grade,ew_group_id,teacher_general_pdf_path,class_id,semester_id from english_writing where ew_id = '{$ewId}'";
- $week_info = $this->sConn->createCommand($sql)->queryRow();
- $sql = "select * from english_writing_student where ew_id = '{$ewId}'";
- $h5_generate_time = $this->sConn->createCommand($sql)->queryRow();
- $h5_generate_time = $h5_generate_time ? explode('-',date('Y-m-d',$h5_generate_time['week_html_time'])) : '';
- $h5_year = $h5_generate_time ? $h5_generate_time[0] : 0;
- $h5_month = $h5_generate_time ? $h5_generate_time[1] : 0;
- $h5_day = $h5_generate_time ? $h5_generate_time[2] : 0;
- $html_data = array(
- 'cur_grade' => $week_info['grade'],
- 'writing' => isset($teacher_extend_arr[0]) ? $teacher_extend_arr[0] : array(),
- 'third' => isset($teacher_extend_arr[1]) ? $teacher_extend_arr[1] : array(),
- );
- $taskName = (isset($teacher_extend_arr[0]['task_name'])) ? ($teacher_extend_arr[0]['task_name']) : (isset($teacher_extend_arr[1]['task_name']) ? $teacher_extend_arr[1]['task_name'] : '');
- //debug($html_data);
- $cardPage = isset($teacher_extend_arr[8]) ? 2 : 0;
- if (empty($week_info['teacher_general_pdf_path'])) {
- $sql = "select ew_id from teacher_writing where ew_id = '{$ewId}' order by ew_id desc";
- $topic_info = $this->sConn->createCommand($sql)->queryAll();
- if (empty($topic_info)) {
- Yii::app()->jump->error('写作宝教师版尚未生成');
- } else {
- $html_name = 'english_writing_teacher';
- //$this->render("{$html_name}", $html_data);exit;
- $html = $this->renderPartial("{$html_name}", $html_data,true);
- unset($html_data);
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
- $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/";
- if (!is_dir($htmlpath)) {
- if (!mkdir($htmlpath, 0777, true)) {
- exit('Create directory fail: ' . $htmlpath);
- }
- }
- if (!is_dir($pdfpath)) {
- if (!mkdir($pdfpath, 0777, true)) {
- exit('Create directory fail1: ' . $pdfpath);
- }
- }
- $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
- $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
- $classId = $week_info['class_id'];
- $sql = "select class_name from class where class_id = '{$classId}'";
- $classInfo = $this->sConn->createCommand($sql)->queryRow();
- $className = $classInfo ? $classInfo['class_name'] : '';
- $htmlpath .= $ewId . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- fclose($f);
- $htmlurl = '/upload/tmpDir/reading/' . $ewId . ".html"; //访问HTML的路径
- $locale='en_US.UTF-8';
- setlocale(LC_ALL,$locale);
- putenv('LC_ALL='.$locale);
- if (Yii::app()->basePath == 'D:\xampp\htdocs\zsy-as2-php\protected') {//本地的basePath
- $htmlurl = " http://192.168.1.48:8077/upload/tmpDir/reading" . '/' . $ewId . '.html';
- $pdffname = $ewId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs'] . " "
- . Yii::app()->params['html2_card_pdf'] . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"';
- } else {
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- $pdffname = $ewId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs_server'] . " "
- . Yii::app()->basePath . '/../js/html2pdf_enCard.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- // . ' 176mm*250mm "'.date('Y-m-d',time()).'|||123456|||'.$grade.' '.$className.'|||'.$cardPage.'"';
- . ' 176mm*250mm "'.$className.'|||'.$taskName.'|||'.date('Y-m-d',time()).' 写作宝-教师版|||'.$className.' '.$className.'|||'.$cardPage.'"';
- }
- // $stu_name . "|||" . (subtext($week_name, 30)) . "|||" .$product_name."|||". Params::$params['cur_subject_id']."|||".$card_page,
- exec($commond, $res, $code);
- if(isset($res[0])){
- $isBool = false;
- foreach ($res as $msg) {
- if (strpos($msg, 'succeed') !== false) {
- $isBool = true;
- }
- }
- if ($isBool) {//命令返回成功
- if (file_exists($pdfpath)) {
- // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
- $repdf = $ewId . ".pdf";
- $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
- $rehtml = $ewId . ".html";
- $reHtmlName = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $rehtml;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($rename, $pdfpath);
- $uploadHtmlInfo = $ucloud->putFile($reHtmlName, $htmlpath);
- if ($uploadInfo['status'] == 0) {
- $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- //echo $pdfurl;
- $this->sConn->createCommand()->update("english_writing", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$htmlurl), "ew_id = '{$ewId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- }else{
- $pdfurl = $uploadInfo['url'];
- $htmlurl = $uploadHtmlInfo['url'];
- //echo $pdfurl;
- $this->sConn->createCommand()->update("english_writing", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$htmlurl), "ew_id = '{$ewId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- @unlink($pdfpath);
- }
- @unlink($htmlpath);
- } else {
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
- exit;
- }
- } else {
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
- exit;
- }
- } else {
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
- exit;
- }
- }
- }
- if($week_info['teacher_general_pdf_path']){
- $url = $week_info['teacher_general_pdf_path'];
- if($isPrint){
- $printData['typeId'] = 18;
- $printData['productType']=20032;
- $printData['params'] = array(
- 'classIds' => array($week_info['class_id']),
- 'url' => $url,
- 'name' => '写作宝教师版',
- 'subjectId' => $this->subjectId,
- 'examGroupId' => $ewId,
- );
- echo json_encode(array("success" => 1, "message" => "success","data"=>$printData));exit();
- }else{
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.android.package-archive');
- header('Content-Disposition: attachment; filename=' . $this->filter_file_name('写作宝教师版') . ".pdf");
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
- echo $buffer;
- return strlen($buffer);
- });
- curl_exec($ch);
- curl_close($ch);
- }
- }else{
- Yii::app()->jump->error('尚未生成PDF');
- }
- }
- public function filter_file_name($filename){
- return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
- array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
- , $filename);
- }
- public function qrcode64($code_str, $level = 'L', $size = 10, $margin = 1){
- $QRcode = new \QRcode();
- ob_start();//开启缓冲区
- $QRcode::pngNoHeader($code_str, false, 'L', 10, 1);//生成二维码
- $img = ob_get_contents();//获取缓冲区内容
- ob_end_clean();//清除缓冲区内容
- $imgInfo = 'data:png;base64,' . chunk_split(base64_encode($img));//转base64
- //ob_flush();
- return $imgInfo;
- }
- //写作宝班级重置页面
- public function actionClasses(){
- $ewGroupId = Req::get('ew_group_id');
- $ewName = Req::get('ew_name');
- if(empty($ewGroupId) || empty($ewName)){
- Yii::app()->jump->error('参数异常');
- }
- $newCondition[] = 'ew.ew_group_id='.$ewGroupId;
- $model = new SEnglishWriting();
- $rs = $model->getWritingList($newCondition,array('ew.create_time desc'),100);
- if(!isset($rs['rs'])){
- Yii::app()->jump->error('获取班级数据失败');
- }
- $data['resultList'] = $rs['rs'];
- $data['resetCount'] = 0;
- $data['ewName'] = $ewName;
- $data['currentWeek'] = date('W');
- $this->render('reset', $data);
- }
- //重置操作
- public function actionReset(){
- $ewIds = Req::post('classExam');
- if(!$ewIds || !is_array($ewIds)){
- echo json_encode(array("status" => 0, "message" => "参数错误!"));exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- foreach ($ewIds as $ewId) {
- $this->sConn->createCommand()->update("english_writing", array("is_all_html" => 0,'reset_times' =>new CDbExpression('reset_times+1')), "ew_id = '{$ewId}'");
- $this->sConn->createCommand()->update("english_writing_student", array("is_week_html" => 0,"week_html_path"=>"","week_pdf_path"=>"","is_week_pdf"=>0), "ew_id = '{$ewId}'");
- }
- $model = SEnglishWriting::model()->find("ew_id=:ew_id", array(':ew_id'=>$ewIds[0]));
- if(isset($model['ew_group_id']) && $ewIds){
- //发送消息
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>90,
- 'grade' => $model['grade'],
- 'subject_id'=>$this->subjectId,
- 'send_type'=>'english_writing',
- 'product_type'=>array(1),
- 'gp_group_id'=>$model['ew_group_id'],
- 'gp_ids'=>$ewIds
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- }
- $transaction->commit();
- }catch (\Exception $e){
- $transaction->rollBack();
- echo json_encode(array('status'=>0,'message'=>$e->getMessage()));exit;
- }
- echo json_encode(array('status'=>1));exit;
- }
- //统计excel下载
- public function actionDownExcel()
- {
- $ewId = Req::get('ewId');
- $classId = Req::get('classId');
- if(!$ewId || !$classId){
- Yii::app()->jump->error('参数错误');
- }
- $className = SClass::model()->getClassName($classId);
- $obpe = new PHPExcel();
- //创建一个新sheet
- $obpe->setactivesheetindex(0);
- $obpe->getActiveSheet()->setTitle('学生得分');
- $studentArr = array(
- array('score'=>'AI打分','student_name'=>'学生','composition_ocr'=>'OCR识别结果')
- );
- $studentList = SEnglishWritingMarking::model()->getStudentRateList($ewId);
- $studentArr = array_merge($studentArr, $studentList);
- foreach($studentArr as $k=>$v){
- $k = $k+1;
- /* @func 设置列 */
- $obpe->getactivesheet()->setcellvalue('A'.$k, $v['score']);
- $obpe->getactivesheet()->setcellvalue('B'.$k, $v['student_name']);
- $obpe->getactivesheet()->setcellvalue('C'.$k, strip_tags($v['composition_ocr']));
- }
- //写入类容
- $obwrite = PHPExcel_IOFactory::createWriter($obpe, 'Excel5');
- ob_end_clean();
- //保存文件
- //$obwrite->save('mulit_sheet.xls');
- //直接在浏览器输出
- 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={$className}批改后统计结果.xls");
- header('Cache-Control:max-age=0');
- $obwrite->save('php://output');
- }
- }
|