1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270 |
- <?php
- /**
- *
- * 词汇宝
- *
- */
- class MagicController 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[] = 'er.grade='.$grade;
- }
- if($printName){
- $newCondition[] = 'er.name like "%'.$printName.'%"';
- }
- if($classId){
- $newCondition[] = 'er.class_id='.$classId;
- }
- $newCondition[] = "ers.product_type = 33";
- $newCondition[] = "er.semester_id = '{$this->semesterId}'";
- $magicWordModel = new SEnglishMagicWord();
- $resultList = $magicWordModel->getMagicWord($newCondition,array('er.create_time desc','er.mw_id desc'),9);
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k]=$v;
- }
- }
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $header=array('X-Basic-V:2',"schoolId:{$this->schoolId}");
- $cgi=Yii::app()->params['cgi'];
- $postParam=array();
- $username=$cgi['username'];
- $password=$cgi['password'];
- $url = $cgi['domain'].'teacher/paper/word-group/can-use-new';//是否可以创建新版词汇组
- $rs = $this->CrmApiPost($url,$postParam,$username,$password,'POST',$header);
- //是否可以试用 生成词汇宝(新)
- $isTrial=false;
- if(isset($rs->errCode) && $rs->errCode =='00' && isset($rs->data) && $rs->data)
- {
- $isTrial=true;
- }
- $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'] = 'mw';
- $data['isTrial']=$isTrial;
- // debug($printList);
- $this->render('index',$data);
- }
- /**
- * 词汇宝选择学生
- */
- public function actionStu(){
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $mw_id = (string)Req::get("mw_id");
- if(!$mw_id){
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及周后推送名称
- $sql = "select er.name,c.class_name,er.grade,er.class_id,er.create_time,er.semester_id from english_magic_word er join class c on er.class_id = c.class_id where er.mw_id = '{$mw_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,is_card_pdf from english_magic_word_student where mw_id = '{$mw_id}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- $cardPdf = array();
- if($relateStudent){
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
- $cardPdf[(string)$studentInfo['student_id']] = $studentInfo['is_card_pdf'];
- }
- }
- if($studentIds){
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- $markingStudents = SEnglishMagicWordMarking::model()->getStuMarkingStatus($studentIds,$mw_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_card_pdf'] = isset($cardPdf[(string)$k])?$cardPdf[(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_card_pdf'] = isset($cardPdf[(string)$k])?$cardPdf[(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"=>11,
- "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['mw_id'] = $mw_id;
- $data['sname'] = $sname;
- $data['printType'] = 'magic_word';
- $this->render('stu',$data);
- }
- /**
- * 英语词汇宝设置
- */
- public function actionSetting(){
- $data = array();
- //新老版本 1-旧版本 2-新版本
- $type=(int)Req::get('type')?(int)Req::get('type'):1;
- $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;
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- if($type==1) {
- $textbookData = $textboookTree->find($criteria, array());
- if ($textbookData) {
- foreach ($textbookData as $doc) {
- foreach ($doc->attributes as $key => $value) {
- if ($key !== '_id') {
- if (isset($value['textbook_id']) && isset($value['name'])) {
- $data['textbookNames'][$value['textbook_id']] = $value['name'];
- if (!isset($textbookId)) {
- $textbookId = $value['textbook_id'];
- }
- if ($textbookId == $value['textbook_id']) {
- if (isset($value['module']) && $value['module']) {
- foreach ($value['module'] as $kk => $vv) {
- $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
- if (!isset($moduleId)) {
- $moduleId = $vv['textbook_module_id'];
- }
- if ($moduleId == $vv['textbook_module_id']) {
- if (isset($vv['unit']) && $vv['unit']) {
- foreach ($vv['unit'] as $kkk => $vvv) {
- $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- $data['groupList'] = $this->getDbConnection()->createCommand("select g.word_group_id,g.`name`,g.create_time,COUNT(w.word_id)as word_count from word_group_word w INNER JOIN word_group g on w.word_group_id=g.word_group_id where g.is_new=0 and g.effective=1 GROUP BY g.word_group_id ORDER BY g.create_time DESC;")->queryAll();
- }else{
- //$textbookResult=$this->apiPost('all_textbook/textbook',array('subject_id'=>8,'query_type'=>2));
- $textbookResult=$this->apiPost('all_textbook/vocabularyTextbook',array('subject_id'=>8,'query_type'=>2));
- $textbookResult=json_decode(json_encode($textbookResult),true);
- $textbooks=$modules=$units=$chapters=array();
- 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']);
- }
- }
- }
- }
- }
- }
- }
- }
- $data['textbooks']=$textbooks;//版本
- $data['modules']=$modules;//模块
- $data['units']=$units;//单元
- $data['chapters']=$chapters;//节
- $data['groupList'] = $this->getDbConnection()->createCommand("select g.word_group_id,g.`name`,g.create_time,COUNT(w.word_id)as word_count from word_group_word w INNER JOIN word_group g on w.word_group_id=g.word_group_id where g.is_new=1 and g.effective=1 GROUP BY g.word_group_id ORDER BY g.create_time DESC;")->queryAll();
- }
- //最近一次设置选项
- $data['setting'] = $this->getDbConnection()->createCommand("select * from english_magic_word_setting order by create_time desc")->queryRow();
- $data['printType'] = 'setting';
- $http = http('order/goods-type/open-time/'.$this->schoolId, 'GET', $this->authUsername);
- $response = formatResponse($http);
- $data['isWhole'] = isset($response['data']) && !empty($response['data']) ? (strtotime($response['data'])<1653926400 ? true : false) : false;
- if($type==1) {
- $this->render('setting', $data);
- }else{
- $this->render('setting2', $data);
- }
- }
- /**
- * 设置英语词汇宝
- */
- public function actionAjaxSaveSetting(){
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $grade=(int)Req::post('grade');
- $unitIds = (array)Req::post('unitIds');
- $translateType = (int)Req::post('translateType');
- $practiceType = (int)Req::post('practiceType');
- $wordCount = (int)Req::post('wordCount');
- $cardWordCount = (int)Req::post('cardWord_count');
- $isClassCommon = (int)Req::post('isClassCommon');
- $classIds = Req::post('selectClassIds');
- $isAnswerSeparate = (int)Req::post('isAnswerSeparate');
- $cardWordSource = (int)Req::post('cardWordSource');
- $wordGroupId = (string)Req::post('wordGroupId');
- $scanType = (int)Req::post('scanType');
- $isNewVersion = (int)Req::post('is_new_version')?(int)Req::post('is_new_version'):0;
- $correctingModel = (int)Req::post('correcting_model')?(int)Req::post('correcting_model'):1;
- $cardChineseRange = (int)Req::post('card_chinese_range')?(int)Req::post('card_chinese_range'):1;
- $cardCountJson=Req::post('card_count_json');
- $cardCountJson = str_replace('"', '"', $cardCountJson);
- $deriveJson = Req::post('derive_json');
- $deriveJson = str_replace('"', '"', $deriveJson);
- $cardCount = $derive = array();
- if ($cardWordSource==1 && $isNewVersion) {
- $cardCount=json_decode($cardCountJson, true);
- if(!$cardCount){
- $error[] = '请检查检测卡词语数量结构';
- }else{
- $reg="/^[0-9]*$/";
- if(!isset($cardCount['word']) || !isset($cardCount['word_chinese_english']) || !isset($cardCount['word_english_chinese']) || !isset($cardCount['phrase'])|| !isset($cardCount['phrase_chinese_english'])|| !isset($cardCount['phrase_english_chinese'])){
- $error[] = '检测卡词语数量结构不全';
- }
- elseif(!preg_match($reg, $cardCount['word']) || !preg_match($reg, $cardCount['word_chinese_english']) || !preg_match($reg, $cardCount['word_english_chinese']) || !preg_match($reg, $cardCount['phrase']) || !preg_match($reg, $cardCount['phrase_chinese_english']) || !preg_match($reg, $cardCount['phrase_english_chinese'])){
- $error[] = '检测卡词语数量只能为大于等于0的整数';
- }else {
- $word=intval($cardCount['word']);
- $word_chinese_english=intval($cardCount['word_chinese_english']);
- $word_english_chinese=intval($cardCount['word_english_chinese']);
- $phrase=intval($cardCount['phrase']);
- $phrase_chinese_english=intval($cardCount['phrase_chinese_english']);
- $phrase_english_chinese=intval($cardCount['phrase_english_chinese']);
- if($word_chinese_english+$word_english_chinese>$word){
- $error[] = '单词汉译英和英译汉数量超过单词数量总数';
- }
- if($phrase_chinese_english+$phrase_english_chinese>$phrase){
- $error[] = '单词汉译英和英译汉数量超过短语数量总数';
- }
- $cardTotal=$word_chinese_english+$word_english_chinese+$phrase_chinese_english+$phrase_english_chinese;
- if($cardTotal<10 || $cardTotal>400){
- $error[] = '词汇检测卡词语数量最多400个最少10个';
- }
- }
- }
- }
- if($isNewVersion) {
- $unitIdData=array();
- $chapterIds=$unitIds;
- if($chapterIds){
- foreach($chapterIds as $chapterId){
- $unitId=substr($chapterId,0,strrpos($chapterId,"_"));
- $unitIdData[$unitId][]=$chapterId;
- }
- }
- if(in_array($grade,array(1,2))){
- if(empty($chapterIds)){$error[] = '请选择小节';}
- if(count($unitIdData)>1){$error[] = '已选单元超出限制';}
- }
- if($grade == 3){
- if(empty($chapterIds)){$error[] = '请选择小节';}
- if(count($unitIdData)>3){$error[] = '已选单元超出限制';}
- }
- $derive=json_decode($deriveJson, true);
- if (!$derive) {
- $error[] = '请检查派生结构';
- } else {
- if (!isset($derive['word_english_chinese']) || !isset($derive['word_chinese_english'])) {
- $error[] = '派生结构不全';
- }
- }
- }else{
- if(in_array($grade,array(1,2))){
- if(empty($unitIds)){$error[] = '请选择单元';}
- if(count($unitIds)>1){$error[] = '已选单元超出限制';}
- }
- if($grade == 3){
- if(empty($unitIds)){$error[] = '请选择单元';}
- if(count($unitIds)>3){$error[] = '已选单元超出限制';}
- }
- }
- if($cardWordSource == 1 && $cardWordCount<=0 && !$isNewVersion){
- $error[] = '请填写检测卡词语数量';
- }
- if($cardWordSource == 2 && empty($wordGroupId)){
- $error[] = '请选择教师端词汇组';
- }
- if(!$grade){
- $error[] = '请选择年级';
- }
- if(!$classIds){
- $error[] = '请选择班级';
- }
- if($practiceType == 2){
- foreach ($classIds as $classId){
- $class = ClassModel::model()->findByPk($classId);
- $sql = "select c.class_name from exam e inner join student_paper_relation r on e.exam_id=r.exam_id inner join class c on c.class_id=e.class_id where e.subject_id=8 and e.semester_id='{$this->semesterId}' and e.class_id = '{$classId}' and e.status = 1 and r.is_complete=1";
- $rs = $this->sConn->createCommand($sql)->queryRow();
- if(empty($rs)){
- $error[] = $class->class_name.'请先录入考试成绩';
- }
- }
- }
- }
- if(!$error){
- $time = time();
- $week = date("W");
- $year = date("Y");
- $strModel = new SStudentClassRelation();
- $transaction = $this->sConn->beginTransaction();
- try{
- $groupId = getUniqueId($this->schoolId);
- //新版本为1,旧版本默认为0
- $isAllHtml=$isNewVersion?1:0;
- $mwIds=array();
- 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_magic_word_setting',array(
- 'mw_group_id'=>$groupId,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'node_ids' => implode(',',$unitIds),
- 'words_count' => $wordCount,
- 'practice_type' => $practiceType,
- 'translate_type' => $translateType,
- 'is_class_common' => $isClassCommon,
- 'card_word_count' => $cardWordCount,
- 'create_time' => $time,
- 'is_answer_separate'=>$isAnswerSeparate,
- 'card_word_source' => $cardWordSource,
- 'word_group_id' => $cardWordSource == 1 ? 0 : $wordGroupId,
- 'scan_type' => $scanType,
- 'is_new_version'=>$isNewVersion,
- 'card_count_json'=>empty($cardCount)?'':json_encode($cardCount),
- 'correcting_model'=>$correctingModel,
- 'card_chinese_range'=>$cardChineseRange,
- 'derive' => empty($derive) ? '' : json_encode($derive),
- ));
- foreach($classIds as $k=>$v){
- $weekId = getUniqueId($this->schoolId);
- $mwIds[]=$weekId;
- $this->sConn->createCommand()->insert('english_magic_word',array(
- 'mw_group_id' => $groupId,
- 'mw_id' => $weekId,
- 'name' => $productName,
- 'class_id' => $v,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'year_num' => $year,
- 'week_num' => $week,
- 'create_time' => $time,
- 'is_all_html' => $isAllHtml,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($v);
- if($stuData){
- foreach($stuData as $kk=>$vv){
- $this->sConn->createCommand()->insert('english_magic_word_student',array(
- 'mw_id' => $weekId,
- 'student_id' => $vv['student_id'],
- ));
- }
- }
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- }
- if($error){
- echo json_encode(array('status'=>0,'error'=>$error));exit;
- }else{
- if($isNewVersion){
- $kafkaData=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>1,//90:重置 1:新设置
- 'grade'=>$grade,
- 'subject_id'=>8,
- 'send_type'=>'english_magic_word',
- 'product_type'=>array(1),
- 'gp_group_id'=>$groupId,
- 'gp_ids'=>array_unique($mwIds),
- );
- sendDataToKafka("php-product-english-magic-word-html",$kafkaData);
- }
- echo json_encode(array('status'=>1));exit;
- }
- }
- //获取词汇宝产品班级
- public function actionAjaxGetClasses(){
- $result = array();
- $grade=(int)Req::post('grade');
- $year = date("Y");
- $month = (int)date("m");
- $week = date("W");
- //获取班级
- $hasSettingClassIds = array();
- $sql = "select class_id,count(*) count from english_magic_word emw left join english_magic_word_setting emws on emws.mw_group_id=emw.mw_group_id where emws.product_type=33 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_magic_word_setting order by create_time desc")->queryRow();
- if($setting) {
- $classIds = $this->sConn->createCommand("select class_id from english_magic_word where mw_group_id={$setting['mw_group_id']}")->queryColumn();
- }
- 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";
- $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 actionAjaxWordCount()
- {
- $unitId = Req::post('ids');
- $grade = Req::post('grade');
- if(empty($unitId) || empty($grade)){
- echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
- }
- $sql = "select single_word,phrase from en_unit_single_phrase where id='{$unitId}'";
- $rs = Yii::app()->enStuffDb->createCommand($sql)->queryRow();
- $wordCount = 0;
- if($rs){
- $words = isset($rs['single_word']) && !empty($rs['single_word']) ? json_decode($rs['single_word'],true) : array();
- }
- if(isset($words) && !empty($words)){
- $wordsStr = implode(',',$words);
- $wordSql = "select count(*) from en_single_word WHERE single_word_id in ($wordsStr)";
- $wordCount = Yii::app()->enStuffDb->createCommand($wordSql)->queryScalar();
- }
- $data = array('wordCount'=>(int)$wordCount);
- echo json_encode(array('status'=>1,'data'=>$data));
- exit;
- }
- //全学科题库里的单元的短语和词汇数量
- public function actionAjaxNewWordCount()
- {
- $unitIds = Req::post('ids');
- if(empty($unitIds) || !is_array($unitIds)){
- echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
- }
- foreach($unitIds as $item){
- $itemArr=explode('_',$item);
- $textbooks[]=$itemArr[count($itemArr) -1];
- }
- $textbooks=array_unique($textbooks);
- $countResult=$this->apiPost('all_library/getWordCouByUnit',array('textbook'=>$textbooks,'is_unit'=>false));
- $countResult=json_decode(json_encode($countResult),true);
- $wordCou=$phraseCou=0;
- if(isset($countResult['status']) && $countResult['status'] && isset($countResult['data']) && $countResult['data']){
- $wordCou=isset($countResult['data']['word_cou'])?$countResult['data']['word_cou']:0;
- $phraseCou=isset($countResult['data']['phrase_cou'])?$countResult['data']['phrase_cou']:0;
- }
- $data=array(
- 'wordCount'=>$wordCou,
- 'phraseCount'=>$phraseCou,
- );
- exit(json_encode(array('status'=>1,'data'=>$data)));
- }
- //确认完成检测卡上传
- public function actionConfirmUpload()
- {
- $mw_id = (string)Req::get("mw_id");
- $mw_group_id = (string)Req::get("mw_group_id");
- if(empty($mw_id) || empty($mw_group_id)){
- echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
- }
- $sql = "select count(distinct student_id) as count from english_magic_word_marking where mw_id={$mw_id};";
- $rs = $this->sConn->createCommand($sql)->queryRow();
- $markCount= isset($rs['count']) ? $rs['count'] : 0;
- $scoreSql = "select count(distinct student_id) as count from english_magic_word_score where mw_id={$mw_id};";
- $scoreRs = $this->sConn->createCommand($scoreSql)->queryRow();
- $scoreCount = isset($scoreRs['count']) ? $scoreRs['count'] : 0;
- if($scoreCount!=$markCount){
- echo json_encode(array('status'=>0,'message'=>'部分学生未批改完成!'));exit;
- }
- $result=$this->sConn->createCommand()->update("english_magic_word", array("marking_status" => 1), "mw_id = '{$mw_id}'");
- if($result){
- $sql = "select mw_group_id,is_new_version,grade from english_magic_word_setting where mw_group_id={$mw_group_id};";
- $rs = $this->sConn->createCommand($sql)->queryRow();
- $isNewVersion= isset($rs['is_new_version']) ? $rs['is_new_version'] : 0;
- if($isNewVersion){
- $grade= isset($rs['grade']) ? $rs['grade'] : 0;
- $kafkaData=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>1,//90:重置 1:新设置
- 'grade'=>$grade,
- 'subject_id'=>8,
- 'send_type'=>'english_magic_word',
- 'product_type'=>array(2),
- 'gp_group_id'=>$mw_group_id,
- 'gp_ids'=>array($mw_id)
- );
- sendDataToKafka("php-product-english-magic-word-html",$kafkaData);
- }
- }
- echo json_encode(array('status'=>1));exit;
- }
- //恢复上传
- public function actionResumeUpload()
- {
- $mw_id = (string)Req::get("mw_id");
- if(empty($mw_id)){
- echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- $this->sConn->createCommand()->update("english_magic_word", array("marking_status" => 0, "is_marking_all_html" => 0), "mw_id = '{$mw_id}'");
- $this->sConn->createCommand()->update("english_magic_word_student", array("is_card_html" => 0,"card_html_path"=>'',"card_pdf_path"=>'', "is_card_pdf"=>0), "mw_id = '{$mw_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);
- $mwId = safe_replace(Yii::app()->request->getQuery('mwId'));
- $isPrint=safe_replace(Yii::app()->request->getQuery('isPrint'));
- $sql = "select * from teacher_magic_word where mw_id = '{$mwId}'";
- $week_info = $this->sConn->createCommand($sql)->queryAll();
- $teacher_extend_arr = array();
- foreach($week_info as $info)
- {
- $content = $info['content'];
- $content = json_decode($content,true);
- $teacher_extend_arr[$info['type']] = $content;
- }
- $sql = "select grade,mw_group_id,teacher_general_pdf_path,class_id,semester_id from english_magic_word where mw_id = '{$mwId}'";
- $week_info = $this->sConn->createCommand($sql)->queryRow();
- $sql = "select words_count,practice_type,translate_type,is_class_common,card_word_count,card_word_source,is_new_version from english_magic_word_setting where mw_group_id='{$week_info['mw_group_id']}'";
- $week_setting_info = $this->sConn->createCommand($sql)->queryRow();
- if($week_setting_info && $week_setting_info['practice_type'] == 2){ //1共性 2个性
- Yii::app()->jump->error('学生个性化词汇宝无教师版!');
- }
- $sql = "select ps_id from product_class_relation where class_id={$week_info['class_id']} and semester_id={$week_info['semester_id']} and set_type=8 order by ps_id desc limit 1";
- $arr = $this->sConn->createCommand($sql)->queryRow();
- $sql = $arr ? "select custom_config from product_setting where ps_id={$arr['ps_id']}" : "select custom_config from product_setting where product_type=8";
- $product_setting = $this->sConn->createCommand($sql)->queryRow();
- $product_setting = $product_setting ? $product_setting['custom_config'] : '';
- $setting = array(
- 'moduleName'=>'词汇宝',
- 'moduleType'=>'english_5',
- 'setting'=>array(
- 'training' => array( //a-词汇集训
- 'wordReview' => 1, //词汇回顾
- 'wordExplain' => 1, // 词汇精讲
- 'practiceExact' => array( // 精准训练
- 'translate' => 1, //英汉互译
- 'wordApply' => 1, //词汇运用
- 'discourse' => 1, //语篇训练
- ) //
- ),
- 'checkCard' => 1, //词汇集训检测卡
- 'wrongPractice' => 1, //错词再练
- 'wrongPracticeTimes' => 3, //第几次推送错词再练
- )
- );
- $product_setting = $product_setting ? json_decode($product_setting, true) : $setting;
- $sql = "select * from english_magic_word_student where mw_id = '{$mwId}'";
- $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;
- // if(YII_ENV != 'production'){
- // $h5_url = 'http://zsyapi.testing.xueping.com/uploads/magic_word/html/'.$this->schoolId.'/'.$h5_year.'/'.$h5_month.'/'.$h5_day.'/'.$mwId.'/h5/0.html';
- // }else{
- // $h5_url = Yii::app()->params['static_url'][$this->schoolGroupId].'/magic_word/html/'.$this->schoolId.'/'.$h5_year.'/'.$h5_month.'/'.$h5_day.'/'.$mwId.'/h5/0.html';
- // }
- if(!$week_setting_info['is_new_version']){
- $h5_url = Yii::app()->params['static_url'][$this->schoolGroupId].'/magic_word/html/'.$this->schoolId.'/'.$h5_year.'/'.$h5_month.'/'.$h5_day.'/'.$mwId.'/0_h5.html';
- }else{
- $h5_url = Yii::app()->params['static_url'][$this->schoolGroupId].'/zxhx_exam_html/english/english_magic_word/'. date('Y-m-d') .'/'.$mwId.'/0_h5.html';
- }
- $h5_img = $this->qrcode64($h5_url);
- $topic_type_ids = $topic_type_k_v = array();
- if($week_setting_info['is_new_version']){
- if(YII_ENV != 'production'){
- //语篇训练
- $topic_type_k_v = array('choice_cloze'=>41,'reading_comprehension'=>42,'sentence_cloze'=>44,'grammar_gap_filling'=>278);
- $topic_type_ids = array(41=>'Choice Cloze (完形填空)', 42=>'Reading Comprehension (阅读理解)', 44=>'Sentence Cloze (七选五)', 278=>'Grammar Gap Filling (语法填空)');
- }else{
- //语篇训练
- $topic_type_k_v = array('choice_cloze'=>41,'reading_comprehension'=>42,'sentence_cloze'=>44,'grammar_gap_filling'=>278);
- $topic_type_ids = array(41=>'Choice Cloze (完形填空)', 42=>'Reading Comprehension (阅读理解)', 44=>'Sentence Cloze (七选五)', 278=>'Grammar Gap Filling (语法填空)');
- }
- //新版检测卡根据word_type归类
- $check_card = array();
- $check_card_detail = isset($teacher_extend_arr[8]) ? $teacher_extend_arr[8] : array();
- if($check_card_detail){
- $card_word_source = $week_setting_info['card_word_source'];
- //检测卡根据word_type归类
- foreach ($check_card_detail as $val){
- $check_card[$val['word_type']][] = $val;
- }
- if(isset($check_card[1])){
- if($card_word_source == 1){ //学管端设置
- $arr = array();
- foreach($check_card[1] as $key => $val){
- if(isset($val['derive']) || $val['is_derivative']){
- $arr[] = $val;
- unset($check_card[1][$key]);
- }
- }
- $c = array_merge($check_card[1], $arr);
- $check_card[1] = $this->sort($c);
- }else{ //教师端设置
- $check_card[1] = $this->sort($check_card[1]);
- }
- }
- if(isset($check_card[2])){
- if($card_word_source == 1){ //学管端设置
- $arr = array();
- foreach($check_card[2] as $key => $val){
- if(isset($val['derive']) || $val['is_derivative']){
- $arr[] = $val;
- unset($check_card[2][$key]);
- }
- }
- $c = array_merge($check_card[2], $arr);
- $check_card[2] = $this->sort($c);
- }else{ //教师端设置
- $check_card[2] = $this->sort($check_card[2]);
- }
- }
- }
- }else{
- $check_card = isset($teacher_extend_arr[8]) ? $teacher_extend_arr[8] : array();
- }
- $html_data = array(
- 'cur_grade' => $week_info['grade'],
- 'title' => isset($teacher_extend_arr[0]) ? $teacher_extend_arr[0] : array(),
- 'word_review' => isset($teacher_extend_arr[1]) ? $teacher_extend_arr[1] : array(),
- 'word_phase' => isset($teacher_extend_arr[2]) ? $teacher_extend_arr[2] : array(),
- 'translates' => isset($teacher_extend_arr[3]) ? $teacher_extend_arr[3] : array(),
- 'word_apply_ids' => isset($teacher_extend_arr[4]) ? $teacher_extend_arr[4] : array(),
- 'word_apply_content'=> isset($teacher_extend_arr[5]) ? $teacher_extend_arr[5] : array(),
- 'card_topic_ids' => isset($teacher_extend_arr[6]) ? current($teacher_extend_arr[6]) : array(),
- 'card_topic_content' => isset($teacher_extend_arr[7]) ? $teacher_extend_arr[7] : array(),
- 'check_card' => $check_card,
- 'card_title' => isset($teacher_extend_arr[9]) ? $teacher_extend_arr[9] : (isset($teacher_extend_arr[0]) ? $teacher_extend_arr[0] : array()),
- 'product_setting' => $product_setting['setting'],
- 'setting' => $week_setting_info,
- 'h5_image' =>$h5_img,
- 'topic_type_ids' => $topic_type_ids,
- 'topic_type_k_v' => $topic_type_k_v
- );
- //debug($check_card);
- if($week_setting_info['is_new_version']){
- $cardPage = 0;
- }else{
- $cardPage = isset($teacher_extend_arr[8]) ? 2 : 0;
- }
- // //检测卡根据word_type归类
- // $check_card = $answer_check_card = [];
- // foreach ($html_data_arr['marking_words'] as $val){
- // $check_card[$val['word_type']][] = $val;
- // }
- // foreach ($html_data_arr['check_card'] as $val){
- // $answer_check_card[$val['word_type']][] = $val;
- // }
- // if(isset($check_card[1])){
- // $_marking_word = [];
- // foreach ($check_card[1] as $val){
- // $_marking_word[$val['single_word_id']][] = $val;
- // }
- // $check_card[1] = $_marking_word;
- // foreach($check_card[1] as $single_word=>$val){
- // for($i=0;$i<count($val);$i+=2){
- // $_check_card[] = array_slice($val,$i,2);
- // }
- // }
- // $check_card[1] = $_check_card;
- // unset($_check_card);
- // }
- // if(isset($check_card[2])){
- // $_marking_word = [];
- // foreach ($check_card[2] as $val){
- // $_marking_word[$val['single_word_id']][] = $val;
- // }
- // $check_card[2] = $_marking_word;
- // foreach($check_card[2] as $single_word=>$val){
- // for($i=0;$i<count($val);$i+=2){
- // $_check_card[] = array_slice($val,$i,2);
- // }
- // }
- // $check_card[2] = $_check_card;
- // unset($_check_card);
- // }
- if (empty($week_info['teacher_general_pdf_path'])) {
- $sql = "select mw_id from teacher_magic_word where mw_id = '{$mwId}' order by mw_id desc";
- $topic_info = $this->sConn->createCommand($sql)->queryAll();
- if (empty($topic_info)) {
- Yii::app()->jump->error('词汇宝教师版尚未生成');
- } else {
- if(!$week_setting_info['is_new_version']){
- $html_name = 'english_magic_word_teacher';
- }else{
- $html_name = 'english_magic_word_teacher_new';
- }
- // $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 .= $mwId . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- fclose($f);
- $htmlurl = '/upload/tmpDir/reading/' . $mwId . ".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" . '/' . $mwId . '.html';
- $pdffname = $mwId . ".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 = $mwId . ".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 "'.$grade.'|||词汇宝|||'.date('Y-m-d',time()).'|||'.$grade.' '.$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) && file_exists($htmlpath)) {
- // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
- $repdf = $mwId . ".pdf";
- $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
- $rehtml = $mwId . ".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 && $uploadHtmlInfo['status'] == 0) {
- $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- //echo $pdfurl;
- $this->sConn->createCommand()->update("english_magic_word", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path" => $htmlurl), "mw_id = '{$mwId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- }else{
- $pdfurl = $uploadInfo['url'];
- $htmlurl = $uploadHtmlInfo['url'];
- //echo $pdfurl;
- $this->sConn->createCommand()->update("english_magic_word", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path" => $htmlurl), "mw_id = '{$mwId}'");
- $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']=20011;
- $printData['params'] = array(
- 'classIds' => array($week_info['class_id']),
- 'url' => $url,
- 'name' => '词汇宝教师版',
- 'subjectId' => $this->subjectId,
- 'examGroupId' => $mwId,
- );
- 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(){
- $mwGroupId = Req::get('mw_group_id');
- $mwName = Req::get('mw_name');
- if(empty($mwGroupId) || empty($mwName)){
- Yii::app()->jump->error('参数异常');
- }
- $newCondition[] = 'er.mw_group_id='.$mwGroupId;
- $magicWordModel = new SEnglishMagicWord();
- $rs = $magicWordModel->getMagicWord($newCondition,array('er.create_time desc'),100);
- if(!isset($rs['rs'])){
- Yii::app()->jump->error('获取班级数据失败');
- }
- $data['resultList'] = $rs['rs'];
- $data['resetCount'] = 0;
- $data['mwName'] = $mwName;
- $data['currentWeek'] = date('W');
- $data['mw_group_id'] = $mwGroupId;
- $this->render('reset', $data);
- }
- //重置操作
- public function actionReset(){
- $mwIds = Req::post('classExam');
- $mwGroupId = Req::post('mwGroupId');
- if(!$mwIds || !is_array($mwIds) || !$mwGroupId){
- echo json_encode(array("status" => 0, "message" => "参数错误!"));exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- $sql = "select is_new_version,grade from english_magic_word_setting where mw_group_id='{$mwGroupId}'";
- $magicWordSetting= $this->sConn->createCommand($sql)->queryRow();
- if(empty($magicWordSetting)){
- throw new \Exception('词汇宝设置数据不存在');
- }
- $isNewVersion=$magicWordSetting['is_new_version'];
- $grade=$magicWordSetting['grade'];
- foreach ($mwIds as $mwId) {
- if($isNewVersion){
- $this->sConn->createCommand()->update("english_magic_word", array( 'reset_times' => new CDbExpression('reset_times+1')), "mw_id = '{$mwId}'");
- }else {
- $this->sConn->createCommand()->update("english_magic_word", array("is_all_html" => 0, 'reset_times' => new CDbExpression('reset_times+1')), "mw_id = '{$mwId}'");
- }
- $this->sConn->createCommand()->update("english_magic_word_student", array("is_week_html" => 0,"is_week_pdf"=>0), "mw_id = '{$mwId}'");
- }
- $transaction->commit();
- }catch (\Exception $e){
- $transaction->rollBack();
- echo json_encode(array('status'=>0,'message'=>$e->getMessage()));exit;
- }
- if($isNewVersion){
- $kafkaData=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>90,//90:重置 1:新设置
- 'grade'=>$grade,
- 'subject_id'=>8,
- 'send_type'=>'english_magic_word',
- 'product_type'=>array(1),
- 'gp_group_id'=>$mwGroupId,
- 'gp_ids'=>array_unique($mwIds),
- );
- sendDataToKafka("php-product-english-magic-word-html",$kafkaData);
- }
- echo json_encode(array('status'=>1));exit;
- }
- //统计excel下载
- public function actionDownExcel()
- {
- $mwId = Req::get('mwId');
- $classId = Req::get('classId');
- if(!$mwId || !$classId){
- Yii::app()->jump->error('参数错误');
- }
- $wordArr = array(
- array('right_rate'=>'正确率', 'right_count'=>'正确人数', 'no'=>'题号', 'right_answer'=>'答案', 'wrong_list'=>'错误学生和OCR识别结果'),
- );
- $className = SClass::model()->getClassName($classId);
- $magicList = SEnglishMagicWordMarking::model()->getWordList($mwId);
- $wordArr = array_merge($wordArr,$magicList);
- $obpe = new PHPExcel();
- $obpe->setactivesheetindex(0);
- $obpe->getActiveSheet()->setTitle('每词统计');
- $obpe->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
- $obpe->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
- foreach($wordArr as $k=>$v){
- $k = $k+1;
- /* @func 设置列 */
- $obpe->getactivesheet()->setcellvalue('A'.$k, $v['right_rate']);
- $obpe->getactivesheet()->setcellvalue('B'.$k, !empty($v['right_count'])?$v['right_count']:0);
- $obpe->getactivesheet()->setcellvalue('C'.$k, $v['no']);
- $obpe->getactivesheet()->setcellvalue('D'.$k, $v['right_answer']);
- $obpe->getactivesheet()->setcellvalue('E'.$k, $v['wrong_list']);
- }
- //创建一个新sheet
- $obpe->createSheet();
- $obpe->setactivesheetindex(1);
- $obpe->getActiveSheet()->setTitle('每个学生统计');
- $studentArr = array(
- array('right_rate'=>'正确率','student_name'=>'学生','no'=>'学生序号','wrong_count'=>'错误空数', 'rate_change'=>'相较上次')
- );
- $studentList = SEnglishMagicWordMarking::model()->getStudentRateList($mwId,$classId);
- $studentArr = array_merge($studentArr, $studentList);
- foreach($studentArr as $k=>$v){
- $k = $k+1;
- /* @func 设置列 */
- $obpe->getactivesheet()->setcellvalue('A'.$k, $v['right_rate']);
- $obpe->getactivesheet()->setcellvalue('B'.$k, $v['student_name']);
- $obpe->getactivesheet()->setcellvalue('C'.$k, $v['no']);
- $obpe->getactivesheet()->setcellvalue('D'.$k, $v['wrong_count']);
- $obpe->getactivesheet()->setcellvalue('E'.$k, $v['rate_change']);
- }
- //写入类容
- $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');
- }
- 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;
- }
- /**
- * 英语词汇宝单词排序(含派生)
- * @param $marking_word
- * @return array
- */
- protected function sort($marking_word)
- {
- if(!$marking_word) return array();
- $_marking_word = array();
- foreach ($marking_word as $val){
- $_marking_word[$val['single_word_id']][] = $val;
- }
- $arr = array();
- $xyz = 0;
- foreach($_marking_word as $k=>$v){
- foreach($v as $key=>$val){
- $cou = isset($arr[$xyz]) ? count($arr[$xyz]) : 0;
- if((isset($arr[$xyz][0]) && (isset($val['derive']) && $val['derive'])) || (isset($arr[$xyz][0]) && (isset($arr[$xyz][0]['is_derivative']) && $arr[$xyz][0]['is_derivative']) && (isset($val['is_derivative']) && !$val['is_derivative']))){
- $cou = 2;
- }
- if($cou < 2){
- $arr[$xyz][] = $val;
- }else{
- $xyz++;
- $arr[$xyz][] = $val;
- }
- }
- }
- return $arr;
- }
- }
|