MagicController.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. <?php
  2. /**
  3. *
  4. * 词汇宝
  5. *
  6. */
  7. class MagicController extends Controller
  8. {
  9. /**
  10. * 英语词汇宝列表
  11. */
  12. public function actionIndex(){
  13. Url::clean();
  14. $data = array();
  15. $printName = Req::get("name");
  16. $classId = Req::get("classId");
  17. $grade = (int)Req::get("grade");
  18. $newCondition = array();
  19. if($grade){
  20. $newCondition[] = 'er.grade='.$grade;
  21. }
  22. if($printName){
  23. $newCondition[] = 'er.name like "%'.$printName.'%"';
  24. }
  25. if($classId){
  26. $newCondition[] = 'er.class_id='.$classId;
  27. }
  28. $newCondition[] = "ers.product_type = 33";
  29. $newCondition[] = "er.semester_id = '{$this->semesterId}'";
  30. $magicWordModel = new SEnglishMagicWord();
  31. $resultList = $magicWordModel->getMagicWord($newCondition,array('er.create_time desc','er.mw_id desc'),9);
  32. $printList = array();
  33. if($resultList["rs"]){
  34. foreach ($resultList['rs'] as $k=>$v) {
  35. $printList[$k]=$v;
  36. }
  37. }
  38. if (empty($grade)) {
  39. $grade = 'ALL';
  40. }
  41. $header=array('X-Basic-V:2',"schoolId:{$this->schoolId}");
  42. $cgi=Yii::app()->params['cgi'];
  43. $postParam=array();
  44. $username=$cgi['username'];
  45. $password=$cgi['password'];
  46. $url = $cgi['domain'].'teacher/paper/word-group/can-use-new';//是否可以创建新版词汇组
  47. $rs = $this->CrmApiPost($url,$postParam,$username,$password,'POST',$header);
  48. //是否可以试用 生成词汇宝(新)
  49. $isTrial=false;
  50. if(isset($rs->errCode) && $rs->errCode =='00' && isset($rs->data) && $rs->data)
  51. {
  52. $isTrial=true;
  53. }
  54. $classes = $this->schoolManager->getClasses($grade);
  55. $data['pages'] = $resultList['pager'];
  56. $data['page_total'] = $resultList['pager']->rowsCount;
  57. $data['printList'] = $printList;
  58. $data["printName"] = $printName;
  59. $data["classes"] = $classes;
  60. $data["classId"] = $classId;
  61. $data["grade"] = $grade;
  62. $data['printType'] = 'mw';
  63. $data['isTrial']=$isTrial;
  64. // debug($printList);
  65. $this->render('index',$data);
  66. }
  67. /**
  68. * 词汇宝选择学生
  69. */
  70. public function actionStu(){
  71. $data = array();
  72. $sname = (string)Req::get("sname"); //学生名字
  73. $mw_id = (string)Req::get("mw_id");
  74. if(!$mw_id){
  75. Yii::app()->jump->error('参数错误!');
  76. }
  77. //获取班级名称以及周后推送名称
  78. $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}'";
  79. $names = $this->sConn->createCommand($sql)->queryRow();
  80. if(!$names){
  81. $names = array();
  82. $names['name'] = '';
  83. $names['class_name'] = '';
  84. $names['grade'] = 0;
  85. }else{
  86. $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:'';
  87. }
  88. $sql = "select student_id,is_week_pdf,is_card_pdf from english_magic_word_student where mw_id = '{$mw_id}'";
  89. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  90. $studentIds = array();
  91. $stuIsPdf = array();
  92. $cardPdf = array();
  93. if($relateStudent){
  94. foreach ($relateStudent as $studentInfo) {
  95. $studentIds[] = (string)$studentInfo['student_id'];
  96. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
  97. $cardPdf[(string)$studentInfo['student_id']] = $studentInfo['is_card_pdf'];
  98. }
  99. }
  100. if($studentIds){
  101. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  102. $markingStudents = SEnglishMagicWordMarking::model()->getStuMarkingStatus($studentIds,$mw_id);
  103. if($studentNames){
  104. if($sname){
  105. $i = 1;
  106. foreach($studentNames as $k=>$v){
  107. if(strpos($v,$sname) !== false){
  108. $data['list'][$i]['stu_id'] = (string)$k;
  109. $data['list'][$i]['stu_name'] = $v;
  110. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  111. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  112. $data['list'][$i]['is_card_pdf'] = isset($cardPdf[(string)$k])?$cardPdf[(string)$k]:0;
  113. $data['list'][$i]['is_marking'] = isset($markingStudents[(string)$k])?$markingStudents[(string)$k]:0;
  114. $i++;
  115. }
  116. }
  117. }else{
  118. $i = 1;
  119. foreach($studentNames as $k=>$v){
  120. $data['list'][$i]['stu_id'] = (string)$k;
  121. $data['list'][$i]['stu_name'] = $v;
  122. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  123. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  124. $data['list'][$i]['is_card_pdf'] = isset($cardPdf[(string)$k])?$cardPdf[(string)$k]:0;
  125. $data['list'][$i]['is_marking'] = isset($markingStudents[(string)$k])?$markingStudents[(string)$k]:0;
  126. $i++;
  127. }
  128. }
  129. }
  130. }
  131. $Sem=new SSemester();
  132. $code= $Sem->conn->createQuery()
  133. ->from('semester')
  134. ->where("semester_id = '".$names['semester_id']."'")
  135. ->limit(1)
  136. ->query()
  137. ->read();
  138. $intarr=array(
  139. "schoolId"=>$this->schoolId,
  140. "clazzId"=>$names['class_id'],
  141. "semester"=>$code['refer_code'],
  142. "grade"=>$names['grade'],
  143. "students"=>$studentIds,
  144. "examTime"=>$names['create_time'],
  145. "classify"=>11,
  146. "subject"=>8
  147. );
  148. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  149. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  150. if(!$rs){
  151. Yii::app()->jump->error("接口错误");
  152. }
  153. if($rs->errCode!="00"){
  154. Yii::app()->jump->error($rs->errMsg);
  155. }
  156. if(!empty($rs->data)){
  157. $data['limitstu']=$rs->data;
  158. }
  159. $data['mw_id'] = $mw_id;
  160. $data['sname'] = $sname;
  161. $data['printType'] = 'magic_word';
  162. $this->render('stu',$data);
  163. }
  164. /**
  165. * 英语词汇宝设置
  166. */
  167. public function actionSetting(){
  168. $data = array();
  169. //新老版本 1-旧版本 2-新版本
  170. $type=(int)Req::get('type')?(int)Req::get('type'):1;
  171. $data['year'] = $year = date("Y");
  172. $data['month'] = $month = (int)date("m");
  173. $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  174. $textboookTree = new MongodbEnglishTree();
  175. $criteria = new EMongoCriteria();
  176. if($type==1) {
  177. $textbookData = $textboookTree->find($criteria, array());
  178. if ($textbookData) {
  179. foreach ($textbookData as $doc) {
  180. foreach ($doc->attributes as $key => $value) {
  181. if ($key !== '_id') {
  182. if (isset($value['textbook_id']) && isset($value['name'])) {
  183. $data['textbookNames'][$value['textbook_id']] = $value['name'];
  184. if (!isset($textbookId)) {
  185. $textbookId = $value['textbook_id'];
  186. }
  187. if ($textbookId == $value['textbook_id']) {
  188. if (isset($value['module']) && $value['module']) {
  189. foreach ($value['module'] as $kk => $vv) {
  190. $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
  191. if (!isset($moduleId)) {
  192. $moduleId = $vv['textbook_module_id'];
  193. }
  194. if ($moduleId == $vv['textbook_module_id']) {
  195. if (isset($vv['unit']) && $vv['unit']) {
  196. foreach ($vv['unit'] as $kkk => $vvv) {
  197. $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. $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();
  210. }else{
  211. //$textbookResult=$this->apiPost('all_textbook/textbook',array('subject_id'=>8,'query_type'=>2));
  212. $textbookResult=$this->apiPost('all_textbook/vocabularyTextbook',array('subject_id'=>8,'query_type'=>2));
  213. $textbookResult=json_decode(json_encode($textbookResult),true);
  214. $textbooks=$modules=$units=$chapters=array();
  215. if(isset($textbookResult['status']) && $textbookResult['status'] && isset($textbookResult['data']) && $textbookResult['data']){
  216. $textbookResult=$textbookResult['data'];
  217. foreach($textbookResult as $textbookKey=>$textbookItem){
  218. $textbooks[]=array('textbook_id'=>$textbookItem['textbook_id'],'textbook_name'=>$textbookItem['textbook_name']);
  219. if($textbookKey==0 && isset($textbookItem['child']) && $textbookItem['child']){
  220. foreach($textbookItem['child'] as $moduleKey=>$moduleItem){
  221. $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']);
  222. if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){
  223. foreach($moduleItem['child'] as $unitKey=>$unitItem){
  224. $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
  225. if( $unitKey==0 && isset($unitItem['child']) && $unitItem['child']){
  226. foreach($unitItem['child'] as $chapterItem){
  227. $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']);
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
  235. }
  236. $data['textbooks']=$textbooks;//版本
  237. $data['modules']=$modules;//模块
  238. $data['units']=$units;//单元
  239. $data['chapters']=$chapters;//节
  240. $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();
  241. }
  242. //最近一次设置选项
  243. $data['setting'] = $this->getDbConnection()->createCommand("select * from english_magic_word_setting order by create_time desc")->queryRow();
  244. $data['printType'] = 'setting';
  245. $http = http('order/goods-type/open-time/'.$this->schoolId, 'GET', $this->authUsername);
  246. $response = formatResponse($http);
  247. $data['isWhole'] = isset($response['data']) && !empty($response['data']) ? (strtotime($response['data'])<1653926400 ? true : false) : false;
  248. if($type==1) {
  249. $this->render('setting', $data);
  250. }else{
  251. $this->render('setting2', $data);
  252. }
  253. }
  254. /**
  255. * 设置英语词汇宝
  256. */
  257. public function actionAjaxSaveSetting(){
  258. $error = array();
  259. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  260. $error[] = '错误的来源!';
  261. }else{
  262. $grade=(int)Req::post('grade');
  263. $unitIds = (array)Req::post('unitIds');
  264. $translateType = (int)Req::post('translateType');
  265. $practiceType = (int)Req::post('practiceType');
  266. $wordCount = (int)Req::post('wordCount');
  267. $cardWordCount = (int)Req::post('cardWord_count');
  268. $isClassCommon = (int)Req::post('isClassCommon');
  269. $classIds = Req::post('selectClassIds');
  270. $isAnswerSeparate = (int)Req::post('isAnswerSeparate');
  271. $cardWordSource = (int)Req::post('cardWordSource');
  272. $wordGroupId = (string)Req::post('wordGroupId');
  273. $scanType = (int)Req::post('scanType');
  274. $isNewVersion = (int)Req::post('is_new_version')?(int)Req::post('is_new_version'):0;
  275. $correctingModel = (int)Req::post('correcting_model')?(int)Req::post('correcting_model'):1;
  276. $cardChineseRange = (int)Req::post('card_chinese_range')?(int)Req::post('card_chinese_range'):1;
  277. $cardCountJson=Req::post('card_count_json');
  278. $cardCountJson = str_replace('&quot;', '"', $cardCountJson);
  279. $deriveJson = Req::post('derive_json');
  280. $deriveJson = str_replace('&quot;', '"', $deriveJson);
  281. $cardCount = $derive = array();
  282. if ($cardWordSource==1 && $isNewVersion) {
  283. $cardCount=json_decode($cardCountJson, true);
  284. if(!$cardCount){
  285. $error[] = '请检查检测卡词语数量结构';
  286. }else{
  287. $reg="/^[0-9]*$/";
  288. 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'])){
  289. $error[] = '检测卡词语数量结构不全';
  290. }
  291. 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'])){
  292. $error[] = '检测卡词语数量只能为大于等于0的整数';
  293. }else {
  294. $word=intval($cardCount['word']);
  295. $word_chinese_english=intval($cardCount['word_chinese_english']);
  296. $word_english_chinese=intval($cardCount['word_english_chinese']);
  297. $phrase=intval($cardCount['phrase']);
  298. $phrase_chinese_english=intval($cardCount['phrase_chinese_english']);
  299. $phrase_english_chinese=intval($cardCount['phrase_english_chinese']);
  300. if($word_chinese_english+$word_english_chinese>$word){
  301. $error[] = '单词汉译英和英译汉数量超过单词数量总数';
  302. }
  303. if($phrase_chinese_english+$phrase_english_chinese>$phrase){
  304. $error[] = '单词汉译英和英译汉数量超过短语数量总数';
  305. }
  306. $cardTotal=$word_chinese_english+$word_english_chinese+$phrase_chinese_english+$phrase_english_chinese;
  307. if($cardTotal<10 || $cardTotal>400){
  308. $error[] = '词汇检测卡词语数量最多400个最少10个';
  309. }
  310. }
  311. }
  312. }
  313. if($isNewVersion) {
  314. $unitIdData=array();
  315. $chapterIds=$unitIds;
  316. if($chapterIds){
  317. foreach($chapterIds as $chapterId){
  318. $unitId=substr($chapterId,0,strrpos($chapterId,"_"));
  319. $unitIdData[$unitId][]=$chapterId;
  320. }
  321. }
  322. if(in_array($grade,array(1,2))){
  323. if(empty($chapterIds)){$error[] = '请选择小节';}
  324. if(count($unitIdData)>1){$error[] = '已选单元超出限制';}
  325. }
  326. if($grade == 3){
  327. if(empty($chapterIds)){$error[] = '请选择小节';}
  328. if(count($unitIdData)>3){$error[] = '已选单元超出限制';}
  329. }
  330. $derive=json_decode($deriveJson, true);
  331. if (!$derive) {
  332. $error[] = '请检查派生结构';
  333. } else {
  334. if (!isset($derive['word_english_chinese']) || !isset($derive['word_chinese_english'])) {
  335. $error[] = '派生结构不全';
  336. }
  337. }
  338. }else{
  339. if(in_array($grade,array(1,2))){
  340. if(empty($unitIds)){$error[] = '请选择单元';}
  341. if(count($unitIds)>1){$error[] = '已选单元超出限制';}
  342. }
  343. if($grade == 3){
  344. if(empty($unitIds)){$error[] = '请选择单元';}
  345. if(count($unitIds)>3){$error[] = '已选单元超出限制';}
  346. }
  347. }
  348. if($cardWordSource == 1 && $cardWordCount<=0 && !$isNewVersion){
  349. $error[] = '请填写检测卡词语数量';
  350. }
  351. if($cardWordSource == 2 && empty($wordGroupId)){
  352. $error[] = '请选择教师端词汇组';
  353. }
  354. if(!$grade){
  355. $error[] = '请选择年级';
  356. }
  357. if(!$classIds){
  358. $error[] = '请选择班级';
  359. }
  360. if($practiceType == 2){
  361. foreach ($classIds as $classId){
  362. $class = ClassModel::model()->findByPk($classId);
  363. $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";
  364. $rs = $this->sConn->createCommand($sql)->queryRow();
  365. if(empty($rs)){
  366. $error[] = $class->class_name.'请先录入考试成绩';
  367. }
  368. }
  369. }
  370. }
  371. if(!$error){
  372. $time = time();
  373. $week = date("W");
  374. $year = date("Y");
  375. $strModel = new SStudentClassRelation();
  376. $transaction = $this->sConn->beginTransaction();
  377. try{
  378. $groupId = getUniqueId($this->schoolId);
  379. //新版本为1,旧版本默认为0
  380. $isAllHtml=$isNewVersion?1:0;
  381. $mwIds=array();
  382. if ($grade == 3) {
  383. $productName = '高三' . date('Y') . '年第' . date('W') . '周词汇宝';
  384. }elseif($grade == 2){
  385. $productName = '高二' . date('Y') . '年第' . date('W') . '周词汇宝';
  386. }else{
  387. $productName = '高一' . date('Y') . '年第' . date('W') . '周词汇宝';
  388. }
  389. $this->sConn->createCommand()->insert('english_magic_word_setting',array(
  390. 'mw_group_id'=>$groupId,
  391. 'grade' => $grade,
  392. 'semester_id' => $this->semesterId,
  393. 'node_ids' => implode(',',$unitIds),
  394. 'words_count' => $wordCount,
  395. 'practice_type' => $practiceType,
  396. 'translate_type' => $translateType,
  397. 'is_class_common' => $isClassCommon,
  398. 'card_word_count' => $cardWordCount,
  399. 'create_time' => $time,
  400. 'is_answer_separate'=>$isAnswerSeparate,
  401. 'card_word_source' => $cardWordSource,
  402. 'word_group_id' => $cardWordSource == 1 ? 0 : $wordGroupId,
  403. 'scan_type' => $scanType,
  404. 'is_new_version'=>$isNewVersion,
  405. 'card_count_json'=>empty($cardCount)?'':json_encode($cardCount),
  406. 'correcting_model'=>$correctingModel,
  407. 'card_chinese_range'=>$cardChineseRange,
  408. 'derive' => empty($derive) ? '' : json_encode($derive),
  409. ));
  410. foreach($classIds as $k=>$v){
  411. $weekId = getUniqueId($this->schoolId);
  412. $mwIds[]=$weekId;
  413. $this->sConn->createCommand()->insert('english_magic_word',array(
  414. 'mw_group_id' => $groupId,
  415. 'mw_id' => $weekId,
  416. 'name' => $productName,
  417. 'class_id' => $v,
  418. 'grade' => $grade,
  419. 'semester_id' => $this->semesterId,
  420. 'year_num' => $year,
  421. 'week_num' => $week,
  422. 'create_time' => $time,
  423. 'is_all_html' => $isAllHtml,
  424. ));
  425. //获取班级学生
  426. $stuData = $strModel->getRelationsByClassId_Status_0($v);
  427. if($stuData){
  428. foreach($stuData as $kk=>$vv){
  429. $this->sConn->createCommand()->insert('english_magic_word_student',array(
  430. 'mw_id' => $weekId,
  431. 'student_id' => $vv['student_id'],
  432. ));
  433. }
  434. }
  435. }
  436. $transaction->commit();
  437. }catch(Exception $e){
  438. $transaction->rollBack();
  439. if (YII_ENV == 'production') {
  440. $error[] = '系统错误[SQL]';
  441. } else {
  442. $error[] = $e->getMessage();
  443. }
  444. }
  445. }
  446. if($error){
  447. echo json_encode(array('status'=>0,'error'=>$error));exit;
  448. }else{
  449. if($isNewVersion){
  450. $kafkaData=array(
  451. 'school_id'=>$this->schoolId,
  452. 'msg_type'=>1,//90:重置 1:新设置
  453. 'grade'=>$grade,
  454. 'subject_id'=>8,
  455. 'send_type'=>'english_magic_word',
  456. 'product_type'=>array(1),
  457. 'gp_group_id'=>$groupId,
  458. 'gp_ids'=>array_unique($mwIds),
  459. );
  460. sendDataToKafka("php-product-english-magic-word-html",$kafkaData);
  461. }
  462. echo json_encode(array('status'=>1));exit;
  463. }
  464. }
  465. //获取词汇宝产品班级
  466. public function actionAjaxGetClasses(){
  467. $result = array();
  468. $grade=(int)Req::post('grade');
  469. $year = date("Y");
  470. $month = (int)date("m");
  471. $week = date("W");
  472. //获取班级
  473. $hasSettingClassIds = array();
  474. $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";
  475. $data = $this->sConn->createCommand($sql)->queryAll();
  476. if($data){
  477. foreach($data as $k=>$v){
  478. if($v['count'] > 0){
  479. $hasSettingClassIds[$v['class_id']] = $v['count'];
  480. }
  481. }
  482. }
  483. $classIds = array();
  484. $setting = $this->getDbConnection()->createCommand("select * from english_magic_word_setting order by create_time desc")->queryRow();
  485. if($setting) {
  486. $classIds = $this->sConn->createCommand("select class_id from english_magic_word where mw_group_id={$setting['mw_group_id']}")->queryColumn();
  487. }
  488. if($grade){
  489. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
  490. $data = $this->sConn->createCommand($sql)->queryAll();
  491. if($data){
  492. $i = 0;
  493. foreach($data as $k => $v){
  494. $sql = "select count(student_id) count from student_class_relation where class_id = '{$v['class_id']}' and status = 0";
  495. $class_student = $this->sConn->createCommand($sql)->queryRow();
  496. if($class_student && $class_student['count']>0){
  497. $result[$i]['class_id'] = $v['class_id'];
  498. $result[$i]['class_name'] = $v['class_name'];
  499. $result[$i]['status'] = isset($hasSettingClassIds[$v['class_id']])&&$hasSettingClassIds[$v['class_id']]>=5?1:0;
  500. $result[$i]['count'] = isset($hasSettingClassIds[$v['class_id']])?$hasSettingClassIds[$v['class_id']]:0;
  501. $result[$i]['selected'] = in_array($v['class_id'], $classIds) ? true : false;
  502. $i++;
  503. }
  504. }
  505. }
  506. }
  507. echo json_encode($result);exit;
  508. }
  509. //单元的短语和词汇数量
  510. public function actionAjaxWordCount()
  511. {
  512. $unitId = Req::post('ids');
  513. $grade = Req::post('grade');
  514. if(empty($unitId) || empty($grade)){
  515. echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
  516. }
  517. $sql = "select single_word,phrase from en_unit_single_phrase where id='{$unitId}'";
  518. $rs = Yii::app()->enStuffDb->createCommand($sql)->queryRow();
  519. $wordCount = 0;
  520. if($rs){
  521. $words = isset($rs['single_word']) && !empty($rs['single_word']) ? json_decode($rs['single_word'],true) : array();
  522. }
  523. if(isset($words) && !empty($words)){
  524. $wordsStr = implode(',',$words);
  525. $wordSql = "select count(*) from en_single_word WHERE single_word_id in ($wordsStr)";
  526. $wordCount = Yii::app()->enStuffDb->createCommand($wordSql)->queryScalar();
  527. }
  528. $data = array('wordCount'=>(int)$wordCount);
  529. echo json_encode(array('status'=>1,'data'=>$data));
  530. exit;
  531. }
  532. //全学科题库里的单元的短语和词汇数量
  533. public function actionAjaxNewWordCount()
  534. {
  535. $unitIds = Req::post('ids');
  536. if(empty($unitIds) || !is_array($unitIds)){
  537. echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
  538. }
  539. foreach($unitIds as $item){
  540. $itemArr=explode('_',$item);
  541. $textbooks[]=$itemArr[count($itemArr) -1];
  542. }
  543. $textbooks=array_unique($textbooks);
  544. $countResult=$this->apiPost('all_library/getWordCouByUnit',array('textbook'=>$textbooks,'is_unit'=>false));
  545. $countResult=json_decode(json_encode($countResult),true);
  546. $wordCou=$phraseCou=0;
  547. if(isset($countResult['status']) && $countResult['status'] && isset($countResult['data']) && $countResult['data']){
  548. $wordCou=isset($countResult['data']['word_cou'])?$countResult['data']['word_cou']:0;
  549. $phraseCou=isset($countResult['data']['phrase_cou'])?$countResult['data']['phrase_cou']:0;
  550. }
  551. $data=array(
  552. 'wordCount'=>$wordCou,
  553. 'phraseCount'=>$phraseCou,
  554. );
  555. exit(json_encode(array('status'=>1,'data'=>$data)));
  556. }
  557. //确认完成检测卡上传
  558. public function actionConfirmUpload()
  559. {
  560. $mw_id = (string)Req::get("mw_id");
  561. $mw_group_id = (string)Req::get("mw_group_id");
  562. if(empty($mw_id) || empty($mw_group_id)){
  563. echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
  564. }
  565. $sql = "select count(distinct student_id) as count from english_magic_word_marking where mw_id={$mw_id};";
  566. $rs = $this->sConn->createCommand($sql)->queryRow();
  567. $markCount= isset($rs['count']) ? $rs['count'] : 0;
  568. $scoreSql = "select count(distinct student_id) as count from english_magic_word_score where mw_id={$mw_id};";
  569. $scoreRs = $this->sConn->createCommand($scoreSql)->queryRow();
  570. $scoreCount = isset($scoreRs['count']) ? $scoreRs['count'] : 0;
  571. if($scoreCount!=$markCount){
  572. echo json_encode(array('status'=>0,'message'=>'部分学生未批改完成!'));exit;
  573. }
  574. $result=$this->sConn->createCommand()->update("english_magic_word", array("marking_status" => 1), "mw_id = '{$mw_id}'");
  575. if($result){
  576. $sql = "select mw_group_id,is_new_version,grade from english_magic_word_setting where mw_group_id={$mw_group_id};";
  577. $rs = $this->sConn->createCommand($sql)->queryRow();
  578. $isNewVersion= isset($rs['is_new_version']) ? $rs['is_new_version'] : 0;
  579. if($isNewVersion){
  580. $grade= isset($rs['grade']) ? $rs['grade'] : 0;
  581. $kafkaData=array(
  582. 'school_id'=>$this->schoolId,
  583. 'msg_type'=>1,//90:重置 1:新设置
  584. 'grade'=>$grade,
  585. 'subject_id'=>8,
  586. 'send_type'=>'english_magic_word',
  587. 'product_type'=>array(2),
  588. 'gp_group_id'=>$mw_group_id,
  589. 'gp_ids'=>array($mw_id)
  590. );
  591. sendDataToKafka("php-product-english-magic-word-html",$kafkaData);
  592. }
  593. }
  594. echo json_encode(array('status'=>1));exit;
  595. }
  596. //恢复上传
  597. public function actionResumeUpload()
  598. {
  599. $mw_id = (string)Req::get("mw_id");
  600. if(empty($mw_id)){
  601. echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
  602. }
  603. $transaction = $this->sConn->beginTransaction();
  604. try {
  605. $this->sConn->createCommand()->update("english_magic_word", array("marking_status" => 0, "is_marking_all_html" => 0), "mw_id = '{$mw_id}'");
  606. $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}'");
  607. $transaction->commit();
  608. }catch (\Exception $e){
  609. $transaction->rollBack();
  610. echo json_encode(array('status'=>0,'message'=>$e->getMessage()));exit;
  611. }
  612. echo json_encode(array('status'=>1));exit;
  613. }
  614. /**
  615. * 英语词汇宝教师版下载
  616. * @throws CException
  617. */
  618. public function actionTeacherWeek(){
  619. set_time_limit(0);
  620. $mwId = safe_replace(Yii::app()->request->getQuery('mwId'));
  621. $isPrint=safe_replace(Yii::app()->request->getQuery('isPrint'));
  622. $sql = "select * from teacher_magic_word where mw_id = '{$mwId}'";
  623. $week_info = $this->sConn->createCommand($sql)->queryAll();
  624. $teacher_extend_arr = array();
  625. foreach($week_info as $info)
  626. {
  627. $content = $info['content'];
  628. $content = json_decode($content,true);
  629. $teacher_extend_arr[$info['type']] = $content;
  630. }
  631. $sql = "select grade,mw_group_id,teacher_general_pdf_path,class_id,semester_id from english_magic_word where mw_id = '{$mwId}'";
  632. $week_info = $this->sConn->createCommand($sql)->queryRow();
  633. $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']}'";
  634. $week_setting_info = $this->sConn->createCommand($sql)->queryRow();
  635. if($week_setting_info && $week_setting_info['practice_type'] == 2){ //1共性 2个性
  636. Yii::app()->jump->error('学生个性化词汇宝无教师版!');
  637. }
  638. $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";
  639. $arr = $this->sConn->createCommand($sql)->queryRow();
  640. $sql = $arr ? "select custom_config from product_setting where ps_id={$arr['ps_id']}" : "select custom_config from product_setting where product_type=8";
  641. $product_setting = $this->sConn->createCommand($sql)->queryRow();
  642. $product_setting = $product_setting ? $product_setting['custom_config'] : '';
  643. $setting = array(
  644. 'moduleName'=>'词汇宝',
  645. 'moduleType'=>'english_5',
  646. 'setting'=>array(
  647. 'training' => array( //a-词汇集训
  648. 'wordReview' => 1, //词汇回顾
  649. 'wordExplain' => 1, // 词汇精讲
  650. 'practiceExact' => array( // 精准训练
  651. 'translate' => 1, //英汉互译
  652. 'wordApply' => 1, //词汇运用
  653. 'discourse' => 1, //语篇训练
  654. ) //
  655. ),
  656. 'checkCard' => 1, //词汇集训检测卡
  657. 'wrongPractice' => 1, //错词再练
  658. 'wrongPracticeTimes' => 3, //第几次推送错词再练
  659. )
  660. );
  661. $product_setting = $product_setting ? json_decode($product_setting, true) : $setting;
  662. $sql = "select * from english_magic_word_student where mw_id = '{$mwId}'";
  663. $h5_generate_time = $this->sConn->createCommand($sql)->queryRow();
  664. $h5_generate_time = $h5_generate_time ? explode('-',date('Y-m-d',$h5_generate_time['week_html_time'])) : '';
  665. $h5_year = $h5_generate_time ? $h5_generate_time[0] : 0;
  666. $h5_month = $h5_generate_time ? $h5_generate_time[1] : 0;
  667. $h5_day = $h5_generate_time ? $h5_generate_time[2] : 0;
  668. // if(YII_ENV != 'production'){
  669. // $h5_url = 'http://zsyapi.testing.xueping.com/uploads/magic_word/html/'.$this->schoolId.'/'.$h5_year.'/'.$h5_month.'/'.$h5_day.'/'.$mwId.'/h5/0.html';
  670. // }else{
  671. // $h5_url = Yii::app()->params['static_url'][$this->schoolGroupId].'/magic_word/html/'.$this->schoolId.'/'.$h5_year.'/'.$h5_month.'/'.$h5_day.'/'.$mwId.'/h5/0.html';
  672. // }
  673. if(!$week_setting_info['is_new_version']){
  674. $h5_url = Yii::app()->params['static_url'][$this->schoolGroupId].'/magic_word/html/'.$this->schoolId.'/'.$h5_year.'/'.$h5_month.'/'.$h5_day.'/'.$mwId.'/0_h5.html';
  675. }else{
  676. $h5_url = Yii::app()->params['static_url'][$this->schoolGroupId].'/zxhx_exam_html/english/english_magic_word/'. date('Y-m-d') .'/'.$mwId.'/0_h5.html';
  677. }
  678. $h5_img = $this->qrcode64($h5_url);
  679. $topic_type_ids = $topic_type_k_v = array();
  680. if($week_setting_info['is_new_version']){
  681. if(YII_ENV != 'production'){
  682. //语篇训练
  683. $topic_type_k_v = array('choice_cloze'=>41,'reading_comprehension'=>42,'sentence_cloze'=>44,'grammar_gap_filling'=>278);
  684. $topic_type_ids = array(41=>'Choice Cloze (完形填空)', 42=>'Reading Comprehension (阅读理解)', 44=>'Sentence Cloze (七选五)', 278=>'Grammar Gap Filling (语法填空)');
  685. }else{
  686. //语篇训练
  687. $topic_type_k_v = array('choice_cloze'=>41,'reading_comprehension'=>42,'sentence_cloze'=>44,'grammar_gap_filling'=>278);
  688. $topic_type_ids = array(41=>'Choice Cloze (完形填空)', 42=>'Reading Comprehension (阅读理解)', 44=>'Sentence Cloze (七选五)', 278=>'Grammar Gap Filling (语法填空)');
  689. }
  690. //新版检测卡根据word_type归类
  691. $check_card = array();
  692. $check_card_detail = isset($teacher_extend_arr[8]) ? $teacher_extend_arr[8] : array();
  693. if($check_card_detail){
  694. $card_word_source = $week_setting_info['card_word_source'];
  695. //检测卡根据word_type归类
  696. foreach ($check_card_detail as $val){
  697. $check_card[$val['word_type']][] = $val;
  698. }
  699. if(isset($check_card[1])){
  700. if($card_word_source == 1){ //学管端设置
  701. $arr = array();
  702. foreach($check_card[1] as $key => $val){
  703. if(isset($val['derive']) || $val['is_derivative']){
  704. $arr[] = $val;
  705. unset($check_card[1][$key]);
  706. }
  707. }
  708. $c = array_merge($check_card[1], $arr);
  709. $check_card[1] = $this->sort($c);
  710. }else{ //教师端设置
  711. $check_card[1] = $this->sort($check_card[1]);
  712. }
  713. }
  714. if(isset($check_card[2])){
  715. if($card_word_source == 1){ //学管端设置
  716. $arr = array();
  717. foreach($check_card[2] as $key => $val){
  718. if(isset($val['derive']) || $val['is_derivative']){
  719. $arr[] = $val;
  720. unset($check_card[2][$key]);
  721. }
  722. }
  723. $c = array_merge($check_card[2], $arr);
  724. $check_card[2] = $this->sort($c);
  725. }else{ //教师端设置
  726. $check_card[2] = $this->sort($check_card[2]);
  727. }
  728. }
  729. }
  730. }else{
  731. $check_card = isset($teacher_extend_arr[8]) ? $teacher_extend_arr[8] : array();
  732. }
  733. $html_data = array(
  734. 'cur_grade' => $week_info['grade'],
  735. 'title' => isset($teacher_extend_arr[0]) ? $teacher_extend_arr[0] : array(),
  736. 'word_review' => isset($teacher_extend_arr[1]) ? $teacher_extend_arr[1] : array(),
  737. 'word_phase' => isset($teacher_extend_arr[2]) ? $teacher_extend_arr[2] : array(),
  738. 'translates' => isset($teacher_extend_arr[3]) ? $teacher_extend_arr[3] : array(),
  739. 'word_apply_ids' => isset($teacher_extend_arr[4]) ? $teacher_extend_arr[4] : array(),
  740. 'word_apply_content'=> isset($teacher_extend_arr[5]) ? $teacher_extend_arr[5] : array(),
  741. 'card_topic_ids' => isset($teacher_extend_arr[6]) ? current($teacher_extend_arr[6]) : array(),
  742. 'card_topic_content' => isset($teacher_extend_arr[7]) ? $teacher_extend_arr[7] : array(),
  743. 'check_card' => $check_card,
  744. 'card_title' => isset($teacher_extend_arr[9]) ? $teacher_extend_arr[9] : (isset($teacher_extend_arr[0]) ? $teacher_extend_arr[0] : array()),
  745. 'product_setting' => $product_setting['setting'],
  746. 'setting' => $week_setting_info,
  747. 'h5_image' =>$h5_img,
  748. 'topic_type_ids' => $topic_type_ids,
  749. 'topic_type_k_v' => $topic_type_k_v
  750. );
  751. //debug($check_card);
  752. if($week_setting_info['is_new_version']){
  753. $cardPage = 0;
  754. }else{
  755. $cardPage = isset($teacher_extend_arr[8]) ? 2 : 0;
  756. }
  757. // //检测卡根据word_type归类
  758. // $check_card = $answer_check_card = [];
  759. // foreach ($html_data_arr['marking_words'] as $val){
  760. // $check_card[$val['word_type']][] = $val;
  761. // }
  762. // foreach ($html_data_arr['check_card'] as $val){
  763. // $answer_check_card[$val['word_type']][] = $val;
  764. // }
  765. // if(isset($check_card[1])){
  766. // $_marking_word = [];
  767. // foreach ($check_card[1] as $val){
  768. // $_marking_word[$val['single_word_id']][] = $val;
  769. // }
  770. // $check_card[1] = $_marking_word;
  771. // foreach($check_card[1] as $single_word=>$val){
  772. // for($i=0;$i<count($val);$i+=2){
  773. // $_check_card[] = array_slice($val,$i,2);
  774. // }
  775. // }
  776. // $check_card[1] = $_check_card;
  777. // unset($_check_card);
  778. // }
  779. // if(isset($check_card[2])){
  780. // $_marking_word = [];
  781. // foreach ($check_card[2] as $val){
  782. // $_marking_word[$val['single_word_id']][] = $val;
  783. // }
  784. // $check_card[2] = $_marking_word;
  785. // foreach($check_card[2] as $single_word=>$val){
  786. // for($i=0;$i<count($val);$i+=2){
  787. // $_check_card[] = array_slice($val,$i,2);
  788. // }
  789. // }
  790. // $check_card[2] = $_check_card;
  791. // unset($_check_card);
  792. // }
  793. if (empty($week_info['teacher_general_pdf_path'])) {
  794. $sql = "select mw_id from teacher_magic_word where mw_id = '{$mwId}' order by mw_id desc";
  795. $topic_info = $this->sConn->createCommand($sql)->queryAll();
  796. if (empty($topic_info)) {
  797. Yii::app()->jump->error('词汇宝教师版尚未生成');
  798. } else {
  799. if(!$week_setting_info['is_new_version']){
  800. $html_name = 'english_magic_word_teacher';
  801. }else{
  802. $html_name = 'english_magic_word_teacher_new';
  803. }
  804. // $this->render("{$html_name}", $html_data);exit;
  805. $html = $this->renderPartial("{$html_name}", $html_data,true);
  806. unset($html_data);
  807. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
  808. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
  809. $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/";
  810. if (!is_dir($htmlpath)) {
  811. if (!mkdir($htmlpath, 0777, true)) {
  812. exit('Create directory fail: ' . $htmlpath);
  813. }
  814. }
  815. if (!is_dir($pdfpath)) {
  816. if (!mkdir($pdfpath, 0777, true)) {
  817. exit('Create directory fail1: ' . $pdfpath);
  818. }
  819. }
  820. $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
  821. $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
  822. $classId = $week_info['class_id'];
  823. $sql = "select class_name from class where class_id = '{$classId}'";
  824. $classInfo = $this->sConn->createCommand($sql)->queryRow();
  825. $className = $classInfo ? $classInfo['class_name'] : '';
  826. $htmlpath .= $mwId . ".html";
  827. $f = fopen($htmlpath, "w");
  828. fwrite($f, $html);
  829. fclose($f);
  830. $htmlurl = '/upload/tmpDir/reading/' . $mwId . ".html"; //访问HTML的路径
  831. $locale='en_US.UTF-8';
  832. setlocale(LC_ALL,$locale);
  833. putenv('LC_ALL='.$locale);
  834. if (Yii::app()->basePath == 'D:\xampp\htdocs\zsy-as2-php\protected') {//本地的basePath
  835. $htmlurl = " http://192.168.1.48:8077/upload/tmpDir/reading" . '/' . $mwId . '.html';
  836. $pdffname = $mwId . ".pdf";
  837. $pdfpath = $pdfpath . $pdffname;
  838. $pdfurl = $pdfurl . $pdffname;
  839. $commond = Yii::app()->params['phantomjs'] . " "
  840. . Yii::app()->params['html2_card_pdf'] . " "
  841. . " {$htmlurl}"
  842. . " {$pdfpath}"
  843. . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"';
  844. } else {
  845. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  846. $pdffname = $mwId . ".pdf";
  847. $pdfpath = $pdfpath . $pdffname;
  848. $pdfurl = $pdfurl . $pdffname;
  849. $commond = Yii::app()->params['phantomjs_server'] . " "
  850. . Yii::app()->basePath . '/../js/html2pdf_enCard.js' . " "
  851. . " {$htmlurl}"
  852. . " {$pdfpath}"
  853. // . ' 176mm*250mm "'.date('Y-m-d',time()).'|||123456|||'.$grade.' '.$className.'|||'.$cardPage.'"';
  854. . ' 176mm*250mm "'.$grade.'|||词汇宝|||'.date('Y-m-d',time()).'|||'.$grade.' '.$className.'|||'.$cardPage.'"';
  855. }
  856. // $stu_name . "|||" . (subtext($week_name, 30)) . "|||" .$product_name."|||". Params::$params['cur_subject_id']."|||".$card_page,
  857. exec($commond, $res, $code);
  858. if(isset($res[0])){
  859. $isBool = false;
  860. foreach ($res as $msg) {
  861. if (strpos($msg, 'succeed') !== false) {
  862. $isBool = true;
  863. }
  864. }
  865. if ($isBool) {//命令返回成功
  866. if (file_exists($pdfpath) && file_exists($htmlpath)) {
  867. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  868. $repdf = $mwId . ".pdf";
  869. $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
  870. $rehtml = $mwId . ".html";
  871. $reHtmlName = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $rehtml;
  872. $ucloud = new Qcloud();
  873. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  874. $uploadHtmlInfo = $ucloud->putFile($reHtmlName, $htmlpath);
  875. if ($uploadInfo['status'] == 0 && $uploadHtmlInfo['status'] == 0) {
  876. $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
  877. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  878. //echo $pdfurl;
  879. $this->sConn->createCommand()->update("english_magic_word", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path" => $htmlurl), "mw_id = '{$mwId}'");
  880. $week_info['teacher_general_pdf_path'] = $pdfurl;
  881. }else{
  882. $pdfurl = $uploadInfo['url'];
  883. $htmlurl = $uploadHtmlInfo['url'];
  884. //echo $pdfurl;
  885. $this->sConn->createCommand()->update("english_magic_word", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path" => $htmlurl), "mw_id = '{$mwId}'");
  886. $week_info['teacher_general_pdf_path'] = $pdfurl;
  887. @unlink($pdfpath);
  888. }
  889. @unlink($htmlpath);
  890. } else {
  891. @unlink($htmlpath);
  892. echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
  893. exit;
  894. }
  895. } else {
  896. @unlink($htmlpath);
  897. echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
  898. exit;
  899. }
  900. } else {
  901. echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
  902. exit;
  903. }
  904. }
  905. }
  906. if($week_info['teacher_general_pdf_path']){
  907. $url = $week_info['teacher_general_pdf_path'];
  908. if($isPrint){
  909. $printData['typeId'] = 18;
  910. $printData['productType']=20011;
  911. $printData['params'] = array(
  912. 'classIds' => array($week_info['class_id']),
  913. 'url' => $url,
  914. 'name' => '词汇宝教师版',
  915. 'subjectId' => $this->subjectId,
  916. 'examGroupId' => $mwId,
  917. );
  918. echo json_encode(array("success" => 1, "message" => "success","data"=>$printData));exit();
  919. }else{
  920. header('Content-Description: File Transfer');
  921. header('Content-Type: application/vnd.android.package-archive');
  922. header('Content-Disposition: attachment; filename=' . $this->filter_file_name('词汇宝教师版') . ".pdf");
  923. header('Content-Transfer-Encoding: binary');
  924. header('Expires: 0');
  925. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  926. header('Pragma: public');
  927. $ch = curl_init();
  928. curl_setopt($ch, CURLOPT_URL, $url);
  929. curl_setopt($ch, CURLOPT_HEADER, 0);
  930. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  931. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  932. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  933. echo $buffer;
  934. return strlen($buffer);
  935. });
  936. curl_exec($ch);
  937. curl_close($ch);
  938. }
  939. }else{
  940. Yii::app()->jump->error('尚未生成PDF');
  941. }
  942. }
  943. public function filter_file_name($filename){
  944. return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
  945. array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
  946. , $filename);
  947. }
  948. public function qrcode64($code_str, $level = 'L', $size = 10, $margin = 1){
  949. $QRcode = new \QRcode();
  950. ob_start();//开启缓冲区
  951. $QRcode::pngNoHeader($code_str, false, 'L', 10, 1);//生成二维码
  952. $img = ob_get_contents();//获取缓冲区内容
  953. ob_end_clean();//清除缓冲区内容
  954. $imgInfo = 'data:png;base64,' . chunk_split(base64_encode($img));//转base64
  955. //ob_flush();
  956. return $imgInfo;
  957. }
  958. //词汇宝班级重置页面
  959. public function actionClasses(){
  960. $mwGroupId = Req::get('mw_group_id');
  961. $mwName = Req::get('mw_name');
  962. if(empty($mwGroupId) || empty($mwName)){
  963. Yii::app()->jump->error('参数异常');
  964. }
  965. $newCondition[] = 'er.mw_group_id='.$mwGroupId;
  966. $magicWordModel = new SEnglishMagicWord();
  967. $rs = $magicWordModel->getMagicWord($newCondition,array('er.create_time desc'),100);
  968. if(!isset($rs['rs'])){
  969. Yii::app()->jump->error('获取班级数据失败');
  970. }
  971. $data['resultList'] = $rs['rs'];
  972. $data['resetCount'] = 0;
  973. $data['mwName'] = $mwName;
  974. $data['currentWeek'] = date('W');
  975. $data['mw_group_id'] = $mwGroupId;
  976. $this->render('reset', $data);
  977. }
  978. //重置操作
  979. public function actionReset(){
  980. $mwIds = Req::post('classExam');
  981. $mwGroupId = Req::post('mwGroupId');
  982. if(!$mwIds || !is_array($mwIds) || !$mwGroupId){
  983. echo json_encode(array("status" => 0, "message" => "参数错误!"));exit;
  984. }
  985. $transaction = $this->sConn->beginTransaction();
  986. try {
  987. $sql = "select is_new_version,grade from english_magic_word_setting where mw_group_id='{$mwGroupId}'";
  988. $magicWordSetting= $this->sConn->createCommand($sql)->queryRow();
  989. if(empty($magicWordSetting)){
  990. throw new \Exception('词汇宝设置数据不存在');
  991. }
  992. $isNewVersion=$magicWordSetting['is_new_version'];
  993. $grade=$magicWordSetting['grade'];
  994. foreach ($mwIds as $mwId) {
  995. if($isNewVersion){
  996. $this->sConn->createCommand()->update("english_magic_word", array( 'reset_times' => new CDbExpression('reset_times+1')), "mw_id = '{$mwId}'");
  997. }else {
  998. $this->sConn->createCommand()->update("english_magic_word", array("is_all_html" => 0, 'reset_times' => new CDbExpression('reset_times+1')), "mw_id = '{$mwId}'");
  999. }
  1000. $this->sConn->createCommand()->update("english_magic_word_student", array("is_week_html" => 0,"is_week_pdf"=>0), "mw_id = '{$mwId}'");
  1001. }
  1002. $transaction->commit();
  1003. }catch (\Exception $e){
  1004. $transaction->rollBack();
  1005. echo json_encode(array('status'=>0,'message'=>$e->getMessage()));exit;
  1006. }
  1007. if($isNewVersion){
  1008. $kafkaData=array(
  1009. 'school_id'=>$this->schoolId,
  1010. 'msg_type'=>90,//90:重置 1:新设置
  1011. 'grade'=>$grade,
  1012. 'subject_id'=>8,
  1013. 'send_type'=>'english_magic_word',
  1014. 'product_type'=>array(1),
  1015. 'gp_group_id'=>$mwGroupId,
  1016. 'gp_ids'=>array_unique($mwIds),
  1017. );
  1018. sendDataToKafka("php-product-english-magic-word-html",$kafkaData);
  1019. }
  1020. echo json_encode(array('status'=>1));exit;
  1021. }
  1022. //统计excel下载
  1023. public function actionDownExcel()
  1024. {
  1025. $mwId = Req::get('mwId');
  1026. $classId = Req::get('classId');
  1027. if(!$mwId || !$classId){
  1028. Yii::app()->jump->error('参数错误');
  1029. }
  1030. $wordArr = array(
  1031. array('right_rate'=>'正确率', 'right_count'=>'正确人数', 'no'=>'题号', 'right_answer'=>'答案', 'wrong_list'=>'错误学生和OCR识别结果'),
  1032. );
  1033. $className = SClass::model()->getClassName($classId);
  1034. $magicList = SEnglishMagicWordMarking::model()->getWordList($mwId);
  1035. $wordArr = array_merge($wordArr,$magicList);
  1036. $obpe = new PHPExcel();
  1037. $obpe->setactivesheetindex(0);
  1038. $obpe->getActiveSheet()->setTitle('每词统计');
  1039. $obpe->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  1040. $obpe->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  1041. foreach($wordArr as $k=>$v){
  1042. $k = $k+1;
  1043. /* @func 设置列 */
  1044. $obpe->getactivesheet()->setcellvalue('A'.$k, $v['right_rate']);
  1045. $obpe->getactivesheet()->setcellvalue('B'.$k, !empty($v['right_count'])?$v['right_count']:0);
  1046. $obpe->getactivesheet()->setcellvalue('C'.$k, $v['no']);
  1047. $obpe->getactivesheet()->setcellvalue('D'.$k, $v['right_answer']);
  1048. $obpe->getactivesheet()->setcellvalue('E'.$k, $v['wrong_list']);
  1049. }
  1050. //创建一个新sheet
  1051. $obpe->createSheet();
  1052. $obpe->setactivesheetindex(1);
  1053. $obpe->getActiveSheet()->setTitle('每个学生统计');
  1054. $studentArr = array(
  1055. array('right_rate'=>'正确率','student_name'=>'学生','no'=>'学生序号','wrong_count'=>'错误空数', 'rate_change'=>'相较上次')
  1056. );
  1057. $studentList = SEnglishMagicWordMarking::model()->getStudentRateList($mwId,$classId);
  1058. $studentArr = array_merge($studentArr, $studentList);
  1059. foreach($studentArr as $k=>$v){
  1060. $k = $k+1;
  1061. /* @func 设置列 */
  1062. $obpe->getactivesheet()->setcellvalue('A'.$k, $v['right_rate']);
  1063. $obpe->getactivesheet()->setcellvalue('B'.$k, $v['student_name']);
  1064. $obpe->getactivesheet()->setcellvalue('C'.$k, $v['no']);
  1065. $obpe->getactivesheet()->setcellvalue('D'.$k, $v['wrong_count']);
  1066. $obpe->getactivesheet()->setcellvalue('E'.$k, $v['rate_change']);
  1067. }
  1068. //写入类容
  1069. $obwrite = PHPExcel_IOFactory::createWriter($obpe, 'Excel5');
  1070. ob_end_clean();
  1071. //保存文件
  1072. //$obwrite->save('mulit_sheet.xls');
  1073. //直接在浏览器输出
  1074. header("Accept-Ranges:bytes");
  1075. header('Content-Type:application/vnd.ms-excel');
  1076. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  1077. header("Content-Disposition:attachment;filename={$className}统计结果.xls");
  1078. header('Cache-Control:max-age=0');
  1079. $obwrite->save('php://output');
  1080. }
  1081. public function CrmApiPost($url, $arr, $username,$password,$type='POST',$header=array())
  1082. {
  1083. $ch = @curl_init();
  1084. $result = FALSE;
  1085. if ($ch)
  1086. {
  1087. $data = json_encode($arr);
  1088. $headerArr=array(
  1089. 'Content-Type: application/json',
  1090. 'Content-Length: '. strlen($data),
  1091. 'Connection: false',
  1092. 'Expect:'
  1093. );
  1094. if($header){
  1095. $headerArr=array_merge($headerArr,$header);
  1096. }
  1097. if($type=='POST'){
  1098. // Digest认证
  1099. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  1100. curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
  1101. // 不输出头部
  1102. curl_setopt($ch, CURLOPT_HEADER, 0);
  1103. // curl_exec 获取到的内容不直接输出, 而是返回
  1104. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1105. curl_setopt($ch, CURLOPT_TIMEOUT,120);
  1106. curl_setopt($ch, CURLOPT_NOSIGNAL,1);
  1107. curl_setopt($ch, CURLOPT_TIMEOUT_MS,120000);
  1108. // 请求重启路由器的地址 传参 进行重启
  1109. curl_setopt($ch, CURLOPT_URL, $url);
  1110. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  1111. curl_setopt($ch, CURLOPT_POST, 1);
  1112. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1113. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
  1114. if( !curl_errno($ch))
  1115. {
  1116. $result = json_decode(curl_exec($ch));
  1117. }
  1118. // 释放资源
  1119. curl_close($ch);
  1120. }elseif($type=='PUT'){
  1121. $data = json_encode($arr);
  1122. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  1123. curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
  1124. curl_setopt($ch, CURLOPT_HEADER, 0);
  1125. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1126. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  1127. curl_setopt($ch, CURLOPT_URL, $url);
  1128. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  1129. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1130. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
  1131. $result = json_decode(curl_exec($ch));
  1132. curl_close($ch);
  1133. }
  1134. }
  1135. return $result;
  1136. }
  1137. /**
  1138. * 英语词汇宝单词排序(含派生)
  1139. * @param $marking_word
  1140. * @return array
  1141. */
  1142. protected function sort($marking_word)
  1143. {
  1144. if(!$marking_word) return array();
  1145. $_marking_word = array();
  1146. foreach ($marking_word as $val){
  1147. $_marking_word[$val['single_word_id']][] = $val;
  1148. }
  1149. $arr = array();
  1150. $xyz = 0;
  1151. foreach($_marking_word as $k=>$v){
  1152. foreach($v as $key=>$val){
  1153. $cou = isset($arr[$xyz]) ? count($arr[$xyz]) : 0;
  1154. 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']))){
  1155. $cou = 2;
  1156. }
  1157. if($cou < 2){
  1158. $arr[$xyz][] = $val;
  1159. }else{
  1160. $xyz++;
  1161. $arr[$xyz][] = $val;
  1162. }
  1163. }
  1164. }
  1165. return $arr;
  1166. }
  1167. }