WritingController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <?php
  2. /**
  3. *
  4. * 词汇宝
  5. *
  6. */
  7. class WritingController 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[] = 'ew.grade='.$grade;
  21. }
  22. if($printName){
  23. $newCondition[] = 'ew.name like "%'.$printName.'%"';
  24. }
  25. if($classId){
  26. $newCondition[] = 'ew.class_id='.$classId;
  27. }
  28. $newCondition[] = "ew.semester_id = '{$this->semesterId}'";
  29. $newCondition[] = "ews.product_type = 32";
  30. $magicWordModel = new SEnglishWriting();
  31. $resultList = $magicWordModel->getWritingList($newCondition,array('ew.create_time desc','ew.ew_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. $classes = $this->schoolManager->getClasses($grade);
  42. $data['pages'] = $resultList['pager'];
  43. $data['page_total'] = $resultList['pager']->rowsCount;
  44. $data['printList'] = $printList;
  45. $data["printName"] = $printName;
  46. $data["classes"] = $classes;
  47. $data["classId"] = $classId;
  48. $data["grade"] = $grade;
  49. $data['printType'] = 'english_writing';
  50. // debug($printList);
  51. $this->render('index',$data);
  52. }
  53. /**
  54. * 写作宝选择学生
  55. */
  56. public function actionStu(){
  57. $data = array();
  58. $sname = (string)Req::get("sname"); //学生名字
  59. $ew_id = (string)Req::get("ew_id");
  60. if(!$ew_id){
  61. Yii::app()->jump->error('参数错误!');
  62. }
  63. //获取班级名称以及产品名称
  64. $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from english_writing ew join class c on ew.class_id = c.class_id where ew.ew_id = '{$ew_id}'";
  65. $names = $this->sConn->createCommand($sql)->queryRow();
  66. if(!$names){
  67. $names = array();
  68. $names['name'] = '';
  69. $names['class_name'] = '';
  70. $names['grade'] = 0;
  71. }else{
  72. $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:'';
  73. }
  74. $sql = "select student_id,is_week_pdf from english_writing_student where ew_id = '{$ew_id}'";
  75. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  76. $studentIds = array();
  77. $stuIsPdf = array();
  78. if($relateStudent){
  79. foreach ($relateStudent as $studentInfo) {
  80. $studentIds[] = (string)$studentInfo['student_id'];
  81. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
  82. }
  83. }
  84. if($studentIds){
  85. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  86. $markingStudents = SEnglishWritingMarking::model()->getStuMarkingStatus($studentIds,$ew_id);
  87. if($studentNames){
  88. if($sname){
  89. $i = 1;
  90. foreach($studentNames as $k=>$v){
  91. if(strpos($v,$sname) !== false){
  92. $data['list'][$i]['stu_id'] = (string)$k;
  93. $data['list'][$i]['stu_name'] = $v;
  94. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  95. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  96. $data['list'][$i]['is_marking'] = isset($markingStudents[(string)$k])?$markingStudents[(string)$k]:0;
  97. $i++;
  98. }
  99. }
  100. }else{
  101. $i = 1;
  102. foreach($studentNames as $k=>$v){
  103. $data['list'][$i]['stu_id'] = (string)$k;
  104. $data['list'][$i]['stu_name'] = $v;
  105. $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
  106. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
  107. $data['list'][$i]['is_marking'] = isset($markingStudents[(string)$k])?$markingStudents[(string)$k]:0;
  108. $i++;
  109. }
  110. }
  111. }
  112. }
  113. $Sem=new SSemester();
  114. $code= $Sem->conn->createQuery()
  115. ->from('semester')
  116. ->where("semester_id = '".$names['semester_id']."'")
  117. ->limit(1)
  118. ->query()
  119. ->read();
  120. $intarr=array(
  121. "schoolId"=>$this->schoolId,
  122. "clazzId"=>$names['class_id'],
  123. "semester"=>$code['refer_code'],
  124. "grade"=>$names['grade'],
  125. "students"=>$studentIds,
  126. "examTime"=>$names['create_time'],
  127. "classify"=>32,
  128. "subject"=>8
  129. );
  130. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  131. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  132. if(!$rs){
  133. Yii::app()->jump->error("接口错误");
  134. }
  135. if($rs->errCode!="00"){
  136. Yii::app()->jump->error($rs->errMsg);
  137. }
  138. if(!empty($rs->data)){
  139. $data['limitstu']=$rs->data;
  140. }
  141. $data['ew_id'] = $ew_id;
  142. $data['sname'] = $sname;
  143. $data['printType'] = 'english_writing';
  144. $this->render('stu',$data);
  145. }
  146. /**
  147. * 英语词汇宝设置
  148. */
  149. public function actionSetting(){
  150. $data = array();
  151. $data['year'] = $year = date("Y");
  152. $data['month'] = $month = (int)date("m");
  153. $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
  154. //写作指导
  155. $data['groupList'] = $this->getDbConnection()->createCommand("select g.ewg_id,g.`name`,g.create_time,t.teacher_name,g.topic_type from english_writing_guidance g
  156. inner join teacher t on t.teacher_id=g.teacher_id where g.is_delete=0
  157. order by g.create_time DESC;")->queryAll();
  158. //最近一次设置选项
  159. $data['printType'] = 'setting';
  160. $this->render('setting',$data);
  161. }
  162. /**
  163. * 设置英语写作宝
  164. */
  165. public function actionAjaxSaveSetting(){
  166. $error = array();
  167. if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
  168. $error[] = '错误的来源!';
  169. }else{
  170. $grade=(int)Req::post('grade');
  171. $classIds = Req::post('selectClassIds');
  172. $ewgId = (string)Req::post('ewg_id');
  173. $scanType=(int)Req::post('scan_type');
  174. $writingType=(int)Req::post('writing_type');
  175. if(empty($ewgId)){
  176. $error[] = '请选择教师端写作指导';
  177. }
  178. if(!$grade){
  179. $error[] = '请选择年级';
  180. }
  181. if(!$classIds){
  182. $error[] = '请选择班级';
  183. }
  184. }
  185. if(!$error){
  186. $time = time();
  187. $week = date("W");
  188. $year = date("Y");
  189. $strModel = new SStudentClassRelation();
  190. $transaction = $this->sConn->beginTransaction();
  191. try{
  192. $groupId = getUniqueId($this->schoolId);
  193. if ($grade == 3) {
  194. $productName = '高三' . date('Y') . '年第' . date('W') . '周写作宝';
  195. }elseif($grade == 2){
  196. $productName = '高二' . date('Y') . '年第' . date('W') . '周写作宝';
  197. }else{
  198. $productName = '高一' . date('Y') . '年第' . date('W') . '周写作宝';
  199. }
  200. $this->sConn->createCommand()->insert('english_writing_setting',array(
  201. 'ew_group_id'=>$groupId,
  202. 'name' => $productName,
  203. 'grade' => $grade,
  204. 'topic_no' => date('mdHis',$time),
  205. 'semester_id' => $this->semesterId,
  206. 'create_time' => $time,
  207. 'ewg_id' => $ewgId,
  208. 'scan_type'=>$scanType,
  209. 'writing_type'=>$writingType,
  210. 'product_type'=>32
  211. ));
  212. $gpIds = array();
  213. foreach($classIds as $k=>$v){
  214. $weekId = getUniqueId($this->schoolId);
  215. $this->sConn->createCommand()->insert('english_writing',array(
  216. 'ew_group_id' => $groupId,
  217. 'ew_id' => $weekId,
  218. 'name' => $productName,
  219. 'class_id' => $v,
  220. 'grade' => $grade,
  221. 'semester_id' => $this->semesterId,
  222. 'year_num' => $year,
  223. 'week_num' => $week,
  224. 'create_time' => $time,
  225. ));
  226. //获取班级学生
  227. $stuData = $strModel->getRelationsByClassId_Status_0($v);
  228. if($stuData){
  229. foreach($stuData as $kk=>$vv){
  230. $this->sConn->createCommand()->insert('english_writing_student',array(
  231. 'ew_id' => $weekId,
  232. 'student_id' => $vv['student_id'],
  233. ));
  234. }
  235. }
  236. array_push($gpIds, $weekId);
  237. }
  238. //更新写作卡使用次数
  239. //$this->sConn->createCommand()->update("english_writing_guidance", array("writing_card_num" => new CDbExpression('writing_card_num+1')), "ewg_id = '{$ewgId}'");
  240. // //发送消息
  241. // $sendMsg=array(
  242. // 'school_id'=>$this->schoolId,
  243. // 'subject_id'=>$this->subjectId,
  244. // 'msg_type'=>1,
  245. // 'grade'=>$grade,
  246. // 'send_type'=>'english_writing',
  247. // 'product_type'=>array(1),
  248. // 'gp_group_id'=>$groupId,
  249. // 'gp_ids'=>$gpIds
  250. // );
  251. // sendDataToKafka('php-product-html',$sendMsg);
  252. $transaction->commit();
  253. }catch(Exception $e){
  254. $transaction->rollBack();
  255. if (YII_ENV == 'production') {
  256. $error[] = '系统错误[SQL]';
  257. } else {
  258. $error[] = $e->getMessage();
  259. }
  260. }
  261. //发送消息
  262. $sendMsg=array(
  263. 'school_id'=>$this->schoolId,
  264. 'subject_id'=>$this->subjectId,
  265. 'msg_type'=>1,
  266. 'grade'=>$grade,
  267. 'send_type'=>'english_writing',
  268. 'product_type'=>array(1),
  269. 'gp_group_id'=>$groupId,
  270. 'gp_ids'=>$gpIds
  271. );
  272. sendDataToKafka('php-product-html',$sendMsg);
  273. }
  274. if($error){
  275. echo json_encode(array('status'=>0,'error'=>$error));exit;
  276. }else{
  277. echo json_encode(array('status'=>1));exit;
  278. }
  279. }
  280. //获取词汇宝产品班级
  281. public function actionAjaxGetClasses(){
  282. $result = array();
  283. $grade=(int)Req::post('grade');
  284. $year = date("Y");
  285. $week = date("W");
  286. //获取班级
  287. $hasSettingClassIds = array();
  288. $sql="select class_id,count(*) count from english_writing ew left join english_writing_setting ews on ews.ew_group_id=ew.ew_group_id where product_type=32 and year_num = {$year} and week_num = {$week} group by class_id";
  289. $data = $this->sConn->createCommand($sql)->queryAll();
  290. if($data){
  291. foreach($data as $k=>$v){
  292. if($v['count'] > 0){
  293. $hasSettingClassIds[$v['class_id']] = $v['count'];
  294. }
  295. }
  296. }
  297. $classIds = array();
  298. $setting = $this->getDbConnection()->createCommand("select * from english_writing_setting order by create_time desc")->queryRow();
  299. if($setting) {
  300. $classIds = $this->sConn->createCommand("select class_id from english_writing where ew_group_id={$setting['ew_group_id']}")->queryColumn();
  301. }
  302. if($grade){
  303. $zouban_sql = "select * from classified where subject_id = 8 and semester_id = '{$this->semesterId}' and grade = {$grade} and `status` = 1";
  304. $classified_data = $this->sConn->createCommand($zouban_sql)->queryRow();
  305. if($classified_data){
  306. $sql = "select c.class_id,c.class_name "
  307. . "from class c join class_subject_relation csr on c.class_id=csr.class_id "
  308. . "where c.semester_id='{$this->semesterId}' and csr.subject_id = 8 and c.grade = {$grade} and c.class_type = 2 and c.is_hide=0 group by c.class_id";
  309. }else{
  310. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
  311. }
  312. $data = $this->sConn->createCommand($sql)->queryAll();
  313. if($data){
  314. $i = 0;
  315. foreach($data as $k => $v){
  316. $sql = "select count(student_id) count from student_class_relation where class_id = '{$v['class_id']}' and status = 0";
  317. $class_student = $this->sConn->createCommand($sql)->queryRow();
  318. if($class_student && $class_student['count']>0){
  319. $result[$i]['class_id'] = $v['class_id'];
  320. $result[$i]['class_name'] = $v['class_name'];
  321. $result[$i]['status'] = isset($hasSettingClassIds[$v['class_id']])&&$hasSettingClassIds[$v['class_id']]>=5?1:0;
  322. $result[$i]['count'] = isset($hasSettingClassIds[$v['class_id']])?$hasSettingClassIds[$v['class_id']]:0;
  323. $result[$i]['selected'] = in_array($v['class_id'], $classIds) ? true : false;
  324. $i++;
  325. }
  326. }
  327. }
  328. }
  329. echo json_encode($result);exit;
  330. }
  331. //确认完成写作卡上传
  332. public function actionConfirmUpload()
  333. {
  334. $ew_id = (string)Req::get("ew_id");
  335. if(empty($ew_id)){
  336. echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
  337. }
  338. $model = SEnglishWriting::model()->find("ew_id=:ew_id", array(':ew_id'=>$ew_id));
  339. $this->sConn->createCommand()->update("english_writing", array("marking_status" => 1), "ew_id = '{$ew_id}'");
  340. //发送消息
  341. $sendMsg=array(
  342. 'school_id'=>$this->schoolId,
  343. 'msg_type'=>1,
  344. 'grade' => $model['grade'],
  345. 'subject_id'=>$this->subjectId,
  346. 'send_type'=>'english_writing',
  347. 'product_type'=>array(2),
  348. 'gp_group_id'=>$model['ew_group_id'],
  349. 'gp_ids'=>array($ew_id)
  350. );
  351. sendDataToKafka('php-product-html',$sendMsg);
  352. echo json_encode(array('status'=>1));exit;
  353. }
  354. //恢复上传
  355. public function actionResumeUpload()
  356. {
  357. $ew_id = (string)Req::get("ew_id");
  358. if(empty($ew_id)){
  359. echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
  360. }
  361. $transaction = $this->sConn->beginTransaction();
  362. try {
  363. $this->sConn->createCommand()->update("english_writing", array("marking_status" => 0, "is_marking_all_html" => 0), "ew_id = '{$ew_id}'");
  364. $this->sConn->createCommand()->update("english_writing_student", array("is_card_html" => 0), "ew_id = '{$ew_id}'");
  365. $transaction->commit();
  366. }catch (\Exception $e){
  367. $transaction->rollBack();
  368. echo json_encode(array('status'=>0,'message'=>$e->getMessage()));exit;
  369. }
  370. echo json_encode(array('status'=>1));exit;
  371. }
  372. /**
  373. * 英语写作宝教师版下载
  374. * @throws CException
  375. */
  376. public function actionTeacherWeek(){
  377. set_time_limit(0);
  378. $ewId = safe_replace(Yii::app()->request->getQuery('mwId'));
  379. $isPrint = safe_replace(Yii::app()->request->getQuery('isPrint'));
  380. $sql = "select * from teacher_writing where ew_id = '{$ewId}'";
  381. $week_info = $this->sConn->createCommand($sql)->queryAll();
  382. $teacher_extend_arr = array();
  383. foreach($week_info as $info)
  384. {
  385. $content = stripslashes($info['content']);
  386. $content = substr($content,1,-1);
  387. $content = json_decode($content,true);
  388. $teacher_extend_arr[$info['type']] = $content;
  389. }
  390. $sql = "select grade,ew_group_id,teacher_general_pdf_path,class_id,semester_id from english_writing where ew_id = '{$ewId}'";
  391. $week_info = $this->sConn->createCommand($sql)->queryRow();
  392. $sql = "select * from english_writing_student where ew_id = '{$ewId}'";
  393. $h5_generate_time = $this->sConn->createCommand($sql)->queryRow();
  394. $h5_generate_time = $h5_generate_time ? explode('-',date('Y-m-d',$h5_generate_time['week_html_time'])) : '';
  395. $h5_year = $h5_generate_time ? $h5_generate_time[0] : 0;
  396. $h5_month = $h5_generate_time ? $h5_generate_time[1] : 0;
  397. $h5_day = $h5_generate_time ? $h5_generate_time[2] : 0;
  398. $html_data = array(
  399. 'cur_grade' => $week_info['grade'],
  400. 'writing' => isset($teacher_extend_arr[0]) ? $teacher_extend_arr[0] : array(),
  401. 'third' => isset($teacher_extend_arr[1]) ? $teacher_extend_arr[1] : array(),
  402. );
  403. $taskName = (isset($teacher_extend_arr[0]['task_name'])) ? ($teacher_extend_arr[0]['task_name']) : (isset($teacher_extend_arr[1]['task_name']) ? $teacher_extend_arr[1]['task_name'] : '');
  404. //debug($html_data);
  405. $cardPage = isset($teacher_extend_arr[8]) ? 2 : 0;
  406. if (empty($week_info['teacher_general_pdf_path'])) {
  407. $sql = "select ew_id from teacher_writing where ew_id = '{$ewId}' order by ew_id desc";
  408. $topic_info = $this->sConn->createCommand($sql)->queryAll();
  409. if (empty($topic_info)) {
  410. Yii::app()->jump->error('写作宝教师版尚未生成');
  411. } else {
  412. $html_name = 'english_writing_teacher';
  413. //$this->render("{$html_name}", $html_data);exit;
  414. $html = $this->renderPartial("{$html_name}", $html_data,true);
  415. unset($html_data);
  416. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
  417. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
  418. $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/";
  419. if (!is_dir($htmlpath)) {
  420. if (!mkdir($htmlpath, 0777, true)) {
  421. exit('Create directory fail: ' . $htmlpath);
  422. }
  423. }
  424. if (!is_dir($pdfpath)) {
  425. if (!mkdir($pdfpath, 0777, true)) {
  426. exit('Create directory fail1: ' . $pdfpath);
  427. }
  428. }
  429. $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
  430. $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
  431. $classId = $week_info['class_id'];
  432. $sql = "select class_name from class where class_id = '{$classId}'";
  433. $classInfo = $this->sConn->createCommand($sql)->queryRow();
  434. $className = $classInfo ? $classInfo['class_name'] : '';
  435. $htmlpath .= $ewId . ".html";
  436. $f = fopen($htmlpath, "w");
  437. fwrite($f, $html);
  438. fclose($f);
  439. $htmlurl = '/upload/tmpDir/reading/' . $ewId . ".html"; //访问HTML的路径
  440. $locale='en_US.UTF-8';
  441. setlocale(LC_ALL,$locale);
  442. putenv('LC_ALL='.$locale);
  443. if (Yii::app()->basePath == 'D:\xampp\htdocs\zsy-as2-php\protected') {//本地的basePath
  444. $htmlurl = " http://192.168.1.48:8077/upload/tmpDir/reading" . '/' . $ewId . '.html';
  445. $pdffname = $ewId . ".pdf";
  446. $pdfpath = $pdfpath . $pdffname;
  447. $pdfurl = $pdfurl . $pdffname;
  448. $commond = Yii::app()->params['phantomjs'] . " "
  449. . Yii::app()->params['html2_card_pdf'] . " "
  450. . " {$htmlurl}"
  451. . " {$pdfpath}"
  452. . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"';
  453. } else {
  454. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  455. $pdffname = $ewId . ".pdf";
  456. $pdfpath = $pdfpath . $pdffname;
  457. $pdfurl = $pdfurl . $pdffname;
  458. $commond = Yii::app()->params['phantomjs_server'] . " "
  459. . Yii::app()->basePath . '/../js/html2pdf_enCard.js' . " "
  460. . " {$htmlurl}"
  461. . " {$pdfpath}"
  462. // . ' 176mm*250mm "'.date('Y-m-d',time()).'|||123456|||'.$grade.' '.$className.'|||'.$cardPage.'"';
  463. . ' 176mm*250mm "'.$className.'|||'.$taskName.'|||'.date('Y-m-d',time()).' 写作宝-教师版|||'.$className.' '.$className.'|||'.$cardPage.'"';
  464. }
  465. // $stu_name . "|||" . (subtext($week_name, 30)) . "|||" .$product_name."|||". Params::$params['cur_subject_id']."|||".$card_page,
  466. exec($commond, $res, $code);
  467. if(isset($res[0])){
  468. $isBool = false;
  469. foreach ($res as $msg) {
  470. if (strpos($msg, 'succeed') !== false) {
  471. $isBool = true;
  472. }
  473. }
  474. if ($isBool) {//命令返回成功
  475. if (file_exists($pdfpath)) {
  476. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  477. $repdf = $ewId . ".pdf";
  478. $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
  479. $rehtml = $ewId . ".html";
  480. $reHtmlName = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $rehtml;
  481. $ucloud = new Qcloud();
  482. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  483. $uploadHtmlInfo = $ucloud->putFile($reHtmlName, $htmlpath);
  484. if ($uploadInfo['status'] == 0) {
  485. $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
  486. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  487. //echo $pdfurl;
  488. $this->sConn->createCommand()->update("english_writing", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$htmlurl), "ew_id = '{$ewId}'");
  489. $week_info['teacher_general_pdf_path'] = $pdfurl;
  490. }else{
  491. $pdfurl = $uploadInfo['url'];
  492. $htmlurl = $uploadHtmlInfo['url'];
  493. //echo $pdfurl;
  494. $this->sConn->createCommand()->update("english_writing", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$htmlurl), "ew_id = '{$ewId}'");
  495. $week_info['teacher_general_pdf_path'] = $pdfurl;
  496. @unlink($pdfpath);
  497. }
  498. @unlink($htmlpath);
  499. } else {
  500. @unlink($htmlpath);
  501. echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
  502. exit;
  503. }
  504. } else {
  505. @unlink($htmlpath);
  506. echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
  507. exit;
  508. }
  509. } else {
  510. echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
  511. exit;
  512. }
  513. }
  514. }
  515. if($week_info['teacher_general_pdf_path']){
  516. $url = $week_info['teacher_general_pdf_path'];
  517. if($isPrint){
  518. $printData['typeId'] = 18;
  519. $printData['productType']=20032;
  520. $printData['params'] = array(
  521. 'classIds' => array($week_info['class_id']),
  522. 'url' => $url,
  523. 'name' => '写作宝教师版',
  524. 'subjectId' => $this->subjectId,
  525. 'examGroupId' => $ewId,
  526. );
  527. echo json_encode(array("success" => 1, "message" => "success","data"=>$printData));exit();
  528. }else{
  529. header('Content-Description: File Transfer');
  530. header('Content-Type: application/vnd.android.package-archive');
  531. header('Content-Disposition: attachment; filename=' . $this->filter_file_name('写作宝教师版') . ".pdf");
  532. header('Content-Transfer-Encoding: binary');
  533. header('Expires: 0');
  534. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  535. header('Pragma: public');
  536. $ch = curl_init();
  537. curl_setopt($ch, CURLOPT_URL, $url);
  538. curl_setopt($ch, CURLOPT_HEADER, 0);
  539. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  540. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  541. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  542. echo $buffer;
  543. return strlen($buffer);
  544. });
  545. curl_exec($ch);
  546. curl_close($ch);
  547. }
  548. }else{
  549. Yii::app()->jump->error('尚未生成PDF');
  550. }
  551. }
  552. public function filter_file_name($filename){
  553. return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
  554. array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
  555. , $filename);
  556. }
  557. public function qrcode64($code_str, $level = 'L', $size = 10, $margin = 1){
  558. $QRcode = new \QRcode();
  559. ob_start();//开启缓冲区
  560. $QRcode::pngNoHeader($code_str, false, 'L', 10, 1);//生成二维码
  561. $img = ob_get_contents();//获取缓冲区内容
  562. ob_end_clean();//清除缓冲区内容
  563. $imgInfo = 'data:png;base64,' . chunk_split(base64_encode($img));//转base64
  564. //ob_flush();
  565. return $imgInfo;
  566. }
  567. //写作宝班级重置页面
  568. public function actionClasses(){
  569. $ewGroupId = Req::get('ew_group_id');
  570. $ewName = Req::get('ew_name');
  571. if(empty($ewGroupId) || empty($ewName)){
  572. Yii::app()->jump->error('参数异常');
  573. }
  574. $newCondition[] = 'ew.ew_group_id='.$ewGroupId;
  575. $model = new SEnglishWriting();
  576. $rs = $model->getWritingList($newCondition,array('ew.create_time desc'),100);
  577. if(!isset($rs['rs'])){
  578. Yii::app()->jump->error('获取班级数据失败');
  579. }
  580. $data['resultList'] = $rs['rs'];
  581. $data['resetCount'] = 0;
  582. $data['ewName'] = $ewName;
  583. $data['currentWeek'] = date('W');
  584. $this->render('reset', $data);
  585. }
  586. //重置操作
  587. public function actionReset(){
  588. $ewIds = Req::post('classExam');
  589. if(!$ewIds || !is_array($ewIds)){
  590. echo json_encode(array("status" => 0, "message" => "参数错误!"));exit;
  591. }
  592. $transaction = $this->sConn->beginTransaction();
  593. try {
  594. foreach ($ewIds as $ewId) {
  595. $this->sConn->createCommand()->update("english_writing", array("is_all_html" => 0,'reset_times' =>new CDbExpression('reset_times+1')), "ew_id = '{$ewId}'");
  596. $this->sConn->createCommand()->update("english_writing_student", array("is_week_html" => 0,"week_html_path"=>"","week_pdf_path"=>"","is_week_pdf"=>0), "ew_id = '{$ewId}'");
  597. }
  598. $model = SEnglishWriting::model()->find("ew_id=:ew_id", array(':ew_id'=>$ewIds[0]));
  599. if(isset($model['ew_group_id']) && $ewIds){
  600. //发送消息
  601. $sendMsg=array(
  602. 'school_id'=>$this->schoolId,
  603. 'msg_type'=>90,
  604. 'grade' => $model['grade'],
  605. 'subject_id'=>$this->subjectId,
  606. 'send_type'=>'english_writing',
  607. 'product_type'=>array(1),
  608. 'gp_group_id'=>$model['ew_group_id'],
  609. 'gp_ids'=>$ewIds
  610. );
  611. sendDataToKafka('php-product-html',$sendMsg);
  612. }
  613. $transaction->commit();
  614. }catch (\Exception $e){
  615. $transaction->rollBack();
  616. echo json_encode(array('status'=>0,'message'=>$e->getMessage()));exit;
  617. }
  618. echo json_encode(array('status'=>1));exit;
  619. }
  620. //统计excel下载
  621. public function actionDownExcel()
  622. {
  623. $ewId = Req::get('ewId');
  624. $classId = Req::get('classId');
  625. if(!$ewId || !$classId){
  626. Yii::app()->jump->error('参数错误');
  627. }
  628. $className = SClass::model()->getClassName($classId);
  629. $obpe = new PHPExcel();
  630. //创建一个新sheet
  631. $obpe->setactivesheetindex(0);
  632. $obpe->getActiveSheet()->setTitle('学生得分');
  633. $studentArr = array(
  634. array('score'=>'AI打分','student_name'=>'学生','composition_ocr'=>'OCR识别结果')
  635. );
  636. $studentList = SEnglishWritingMarking::model()->getStudentRateList($ewId);
  637. $studentArr = array_merge($studentArr, $studentList);
  638. foreach($studentArr as $k=>$v){
  639. $k = $k+1;
  640. /* @func 设置列 */
  641. $obpe->getactivesheet()->setcellvalue('A'.$k, $v['score']);
  642. $obpe->getactivesheet()->setcellvalue('B'.$k, $v['student_name']);
  643. $obpe->getactivesheet()->setcellvalue('C'.$k, strip_tags($v['composition_ocr']));
  644. }
  645. //写入类容
  646. $obwrite = PHPExcel_IOFactory::createWriter($obpe, 'Excel5');
  647. ob_end_clean();
  648. //保存文件
  649. //$obwrite->save('mulit_sheet.xls');
  650. //直接在浏览器输出
  651. header("Accept-Ranges:bytes");
  652. header('Content-Type:application/vnd.ms-excel');
  653. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  654. header("Content-Disposition:attachment;filename={$className}批改后统计结果.xls");
  655. header('Cache-Control:max-age=0');
  656. $obwrite->save('php://output');
  657. }
  658. }