SpecialController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. /**
  3. *
  4. * 专题宝
  5. *
  6. */
  7. class SpecialController extends Controller
  8. {
  9. //产品内容 关联方法配置id
  10. const METHOD_CONFIG_ID_TEST = 276;
  11. //const METHOD_CONFIG_ID_TEST = 303;
  12. const METHOD_CONFIG_ID_PROD = 276;
  13. /**
  14. * 产品列表
  15. */
  16. public function actionIndex()
  17. {
  18. Url::clean();
  19. $data = array();
  20. $printName = Req::get("name");
  21. $classId = Req::get("classId");
  22. $newCondition=array();
  23. $newCondition[] = 'g.product_type=' . ProductDownload::PRODUCT_TYPE_SPECIAL;
  24. if ($printName) {
  25. $newCondition[] = 'p.name like "%' . $printName . '%"';
  26. }
  27. if ($classId) {
  28. $newCondition[] = 'p.class_id=' . $classId;
  29. }
  30. $newCondition[] = "p.semester_id = '{$this->semesterId}'";
  31. $magicWordModel = new SGeneralProductSetting();
  32. $resultList = $magicWordModel->getList($newCondition, array('p.create_time desc'), 9);
  33. $printList = array();
  34. if ($resultList["rs"]) {
  35. foreach ($resultList['rs'] as $k => $v) {
  36. $printList[$k] = $v;
  37. $printList[$k]['is_cloud_print'] = Yii::app()->cache->getValue(sprintf("cloud_print_task:general_product:%s:%s:%s", $this->schoolId,$v['class_id'],$v['gp_id']));
  38. }
  39. }
  40. $type = ProductDownload::PRODUCT_TYPE_SPECIAL;
  41. $productDesc = ProductDownload::$desc;
  42. $desc = isset($productDesc[$type]) ? $productDesc[$type]: "";
  43. $classes = $this->schoolManager->getClasses(3);
  44. $data['pages'] = $resultList['pager'];
  45. $data['page_total'] = $resultList['pager']->rowsCount;
  46. $data['printList'] = $printList;
  47. $data["printName"] = $printName;
  48. $data["classes"] = $classes;
  49. $data["classId"] = $classId;
  50. $data["grade"] = 3;
  51. $data['printType'] = 'special';
  52. $data['subjectId'] = $this->subjectId;
  53. $data['desc'] = $desc;
  54. $data['type'] = $type;
  55. // debug($printList);
  56. $this->render('index', $data);
  57. }
  58. /**
  59. * 学生列表
  60. */
  61. public function actionStu()
  62. {
  63. $data = array();
  64. $sname = (string)Req::get("sname"); //学生名字
  65. $gpId = (string)Req::get("gp_id");
  66. if (!$gpId) {
  67. Yii::app()->jump->error('参数错误!');
  68. }
  69. //获取班级名称以及产品名称
  70. $sql = "select g.name,c.class_name,g.class_id,g.create_time,g.semester_id from general_product g join class c on g.class_id = c.class_id where g.gp_id = '{$gpId}'";
  71. $names = $this->sConn->createCommand($sql)->queryRow();
  72. if (empty($names)) {
  73. Yii::app()->jump->error('数据错误!');
  74. }
  75. $names['grade'] = 3;
  76. $data['name'] = isset($names['name']) && isset($names['class_name']) ? $names['class_name'] . $names['name'] : '';
  77. $sql = "select student_id,is_create_pdf from general_product_student where gp_id = '{$gpId}'";
  78. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  79. $studentIds = array();
  80. $stuIsPdf = array();
  81. if ($relateStudent) {
  82. foreach ($relateStudent as $studentInfo) {
  83. $studentIds[] = (string)$studentInfo['student_id'];
  84. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_create_pdf'];
  85. }
  86. }
  87. if ($studentIds) {
  88. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  89. if ($studentNames) {
  90. if ($sname) {
  91. $i = 1;
  92. foreach ($studentNames as $k => $v) {
  93. if (strpos($v, $sname) !== false) {
  94. $data['list'][$i]['stu_id'] = (string)$k;
  95. $data['list'][$i]['stu_name'] = $v;
  96. $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
  97. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
  98. $i++;
  99. }
  100. }
  101. } else {
  102. $i = 1;
  103. foreach ($studentNames as $k => $v) {
  104. $data['list'][$i]['stu_id'] = (string)$k;
  105. $data['list'][$i]['stu_name'] = $v;
  106. $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
  107. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(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" => 31,
  128. "subject" => 3
  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['gp_id'] = $gpId;
  142. $data['class_id'] = $names['class_id'];
  143. $data['sname'] = $sname;
  144. $data['type'] = ProductDownload::PRODUCT_TYPE_SPECIAL;
  145. $data['printType'] = 'general_product';
  146. $this->render('stu', $data);
  147. }
  148. /**
  149. * 专题宝设置
  150. */
  151. public function actionSetting()
  152. {
  153. $rs = $this->apiPost('/product/studentProductMenu', array(
  154. 'product_id' => 17
  155. ));
  156. if ($rs->status != 1 && !empty($rs->error)) {
  157. Yii::app()->jump->error($rs->error);
  158. }
  159. //顶级节点即专题数据
  160. $data = array();
  161. if ($rs->data) {
  162. $data['topNode'] = $rs->data;
  163. } else {
  164. Yii::app()->jump->error('brain接口异常!');
  165. }
  166. $this->render('setting', $data);
  167. }
  168. //获取专题下讲列表和试卷列表
  169. public function actionAjaxSpecialChild()
  170. {
  171. $pcId = (string)Req::post("pc_id");
  172. if (!$pcId) {
  173. Yii::app()->jump->error('参数错误!');
  174. }
  175. $rs = $this->apiPost('/product/studentProductMenu', array(
  176. 'product_id' => 17
  177. ));
  178. if ($rs->status != 1 && !empty($rs->error)) {
  179. echo json_encode(array("status" => 0, "message" => $rs->error));
  180. exit();
  181. }
  182. $lectureList = array();
  183. if ($rs->data) {
  184. foreach ($rs->data as $item) {
  185. if ($item->pc_id == $pcId) {
  186. $lectureList = $item->child;
  187. }
  188. }
  189. }
  190. $paper = $this->apiPost('/all_content/detail', array(
  191. 'catalogIds' => array($pcId)
  192. ));
  193. if ($paper->status != 1 && !empty($paper->error)) {
  194. echo json_encode(array("status" => 0, "message" => $paper->error));
  195. exit();
  196. }
  197. $paperList = array();
  198. if($paper->data) {
  199. foreach ($paper->data as $item){
  200. if($item->paper_id){
  201. array_push($paperList,array('paper_id'=>$item->paper_id,'paper_name'=>isset($item->paper_name)?$item->paper_name:"试卷".$item->paper_id));
  202. }
  203. }
  204. }
  205. echo json_encode(array('status' => 1, 'data' => array('lectureList' => $lectureList,'paperList'=>$paperList)));
  206. exit;
  207. }
  208. //获取每一讲下面方法列表
  209. public function actionAjaxMethod()
  210. {
  211. $pcId = (string)Req::post("pc_id");
  212. if (!$pcId) {
  213. Yii::app()->jump->error('参数错误!');
  214. }
  215. $rs = $this->apiPost('/all_content/detail', array(
  216. 'catalogIds' => array($pcId)
  217. ));
  218. if ($rs->status != 1 && !empty($rs->error)) {
  219. echo json_encode(array("status" => 0, "message" => $rs->error));
  220. exit();
  221. }
  222. $methodConfigId = YII_ENV == 'pro' || YII_ENV == 'production' ? self::METHOD_CONFIG_ID_PROD : self::METHOD_CONFIG_ID_TEST;
  223. $methodList = array();
  224. if ($rs->data) {
  225. foreach ($rs->data as $item) {
  226. if ($item->column_id == $methodConfigId) {
  227. array_push($methodList, array('method_id' => $item->tag_extend_id, 'method_name' => $item->tag_extend_name));
  228. }
  229. }
  230. }
  231. echo json_encode(array('status' => 1, 'data' => array('methodList' => $methodList)));
  232. exit;
  233. }
  234. private function getMethodList($pcId){
  235. $rs = $this->apiPost('/all_content/detail', array(
  236. 'catalogIds' => array($pcId)
  237. ));
  238. if ($rs->status != 1 && !empty($rs->error)) {
  239. echo json_encode(array("status" => 0, "message" => $rs->error));
  240. exit();
  241. }
  242. $methodConfigId = YII_ENV == 'pro' || YII_ENV == 'production' ? self::METHOD_CONFIG_ID_PROD : self::METHOD_CONFIG_ID_TEST;
  243. $methodList = array();
  244. if ($rs->data) {
  245. foreach ($rs->data as $item) {
  246. if ($item->column_id == $methodConfigId) {
  247. array_push($methodList, array('method_id' => $item->tag_extend_id, 'method_name' => $item->tag_extend_name));
  248. }
  249. }
  250. }
  251. return $methodList;
  252. }
  253. /**
  254. * 生成设置保存
  255. */
  256. public function actionAjaxSaveSetting()
  257. {
  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. $specialIds = (array)Req::post('specialIds');
  265. $createType = (int)Req::post('createType');
  266. $isAnswerMerge = (int)Req::post('isAnswerMerge');
  267. //$trainPushType = (int)Req::post('trainPushType');
  268. $classIds = (array)Req::post('selectClassIds');
  269. $names = (array)Req::post('names');
  270. $specialNames = (array)Req::post('specialNames');
  271. $specialNodeId = 0;
  272. $paperIds = (array)Req::post('paperIds');
  273. $paperNames = (array)Req::post('paperNames');
  274. $pcIds = array();
  275. $existMethodIds = array();
  276. if ($createType == 1) {
  277. foreach ($specialIds as $key => $specialId) {
  278. $specialNodeId = $specialId;
  279. //array_push($pcIds, array('pc_id' => $specialId, 'pc_name' => $specialNames[$key], 'parent_id' => 0, 'children' => array()));
  280. $rs = $this->apiPost('/product/studentProductMenu', array(
  281. 'product_id' => 17
  282. ));
  283. //专题下的讲列表
  284. if ($rs->data) {
  285. foreach ($rs->data as $item) {
  286. if ($item->pc_id == $specialId) {
  287. $lectureList = $item->child;
  288. if($lectureList) {
  289. foreach ($lectureList as $lecture) {
  290. $methodList = $this->getMethodList($lecture->pc_id);
  291. $_methodIds = _array_column($methodList,'method_id');
  292. $methodIds = array();
  293. foreach ($_methodIds as $_methodId){
  294. if(!in_array($_methodId,$existMethodIds)){
  295. $methodIds[] = $_methodId;
  296. array_push($existMethodIds,$_methodId);
  297. }
  298. }
  299. $pcItem = array('pc_id' => $specialId, 'pc_name' => $specialNames[$key], 'parent_id' => 0, 'children' => array(
  300. 'pc_id' => $lecture->pc_id, 'pc_name' => $lecture->pc_name, 'parent_id' => $specialId, 'method_ids' => $methodIds
  301. ));
  302. array_push($pcIds, $pcItem);
  303. }
  304. }
  305. }
  306. }
  307. }
  308. //专题下所有试卷 FIXME 220104
  309. $paper = $this->apiPost('/all_content/detail', array(
  310. 'catalogIds' => array($specialId)
  311. ));
  312. if ($paper->status != 1 && !empty($paper->error)) {
  313. echo json_encode(array("status" => 0, "message" => $paper->error));
  314. exit();
  315. }
  316. if($paper->data) {
  317. foreach ($paper->data as $item){
  318. if($item->paper_id){
  319. array_push($paperIds, $item->paper_id);
  320. }
  321. }
  322. }
  323. }
  324. if (count($specialIds) > 1) {
  325. echo json_encode(array('status' => 0, 'error' => '专题选择超出限制'));
  326. exit;
  327. }
  328. } else {
  329. $lectures = array();
  330. $pcIds = array();
  331. $specialID = array();
  332. $pcArr = array();
  333. foreach ($unitIds as $key => $unitId) {
  334. $ids = explode('_', $unitId);
  335. $specialID[$ids[0]] = $ids[0];
  336. $specialNodeId = $ids[0];
  337. $nameArr = explode('_', $names[$key]);
  338. $lectures[$ids[0]][$ids[1]]['pc_id'] = $ids[1];
  339. $lectures[$ids[0]][$ids[1]]['pc_name'] = $nameArr[1];
  340. $lectures[$ids[0]][$ids[1]]['parent_id'] = $ids[0];
  341. if(!isset($lectures[$ids[0]][$ids[1]]['method_ids'])){
  342. $lectures[$ids[0]][$ids[1]]['method_ids'] = array();
  343. }
  344. if(!in_array($ids[2],$existMethodIds)){
  345. $lectures[$ids[0]][$ids[1]]['method_ids'][] = $ids[2];
  346. array_push($existMethodIds,$ids[2]);
  347. }
  348. $specialNames[] = $nameArr[0];
  349. $pcArr = array('pc_id' => $ids[0], 'pc_name' => $nameArr[0], 'parent_id' => 0);
  350. }
  351. if (count($specialID) > 1) {
  352. echo json_encode(array('status' => 0, 'error' => '专题选择超出限制'));
  353. exit;
  354. }
  355. foreach ($lectures as $key=>$lecture){
  356. foreach ($lecture as $item){
  357. $pcArr['children'] = $item;
  358. array_push($pcIds, $pcArr);
  359. }
  360. }
  361. }
  362. if($createType==1 && empty($pcIds)){
  363. echo json_encode(array('status'=>0, 'error'=> '专题内容无数据!'));exit;
  364. }
  365. $limit = SGeneralProductSetting::model()->classHistory($specialNodeId, 29, implode(',',$classIds));
  366. if($limit){
  367. echo json_encode(array('status'=>0, 'error'=> implode(',',$limit).'该专题生成次数超出限制'));exit;
  368. }
  369. $setting = array(
  370. 'product_id' => 17,
  371. 'pc_ids' => empty($pcIds) ? array(array("pc_id"=>$specialIds[0],"pc_name"=>$specialNames[0],"parent_id"=>0,"children"=>null)) : $pcIds,
  372. 'paper_ids' => $paperIds, //TODO 试卷
  373. 'create_type' => $createType,
  374. 'is_answer_merge' => $isAnswerMerge ? false : true,
  375. //'train_push_type' => $trainPushType,
  376. );
  377. $time = time();
  378. $transaction = $this->sConn->beginTransaction();
  379. try {
  380. $groupId = getUniqueId($this->schoolId);
  381. $strModel = new SStudentClassRelation();
  382. $this->sConn->createCommand()->insert('general_product_setting', array(
  383. 'gp_group_id' => $groupId,
  384. 'grade' => $grade,
  385. 'product_type' => 29,
  386. 'subject_id' => $this->subjectId,
  387. 'semester_id' => $this->semesterId,
  388. 'setting' => json_encode($setting, true),
  389. 'create_time' => $time,
  390. 'update_time' => $time,
  391. ));
  392. $gpIds = array();
  393. foreach ($classIds as $classId) {
  394. $gpId = getUniqueId($this->schoolId);
  395. $this->sConn->createCommand()->insert('general_product', array(
  396. 'gp_id' => $gpId,
  397. 'gp_group_id' => $groupId,
  398. 'class_id' => $classId,
  399. 'grade' => 3,
  400. 'name' => $specialNames ? implode(',',array_unique($specialNames)).date('YmdHis',$time) : implode(',',array_unique($paperNames)).date('YmdHis',$time),
  401. 'subject_id' => $this->subjectId,
  402. 'semester_id' => $this->semesterId,
  403. 'create_time' => $time,
  404. 'update_time' => $time,
  405. ));
  406. //获取班级学生
  407. $stuData = $strModel->getRelationsByClassId_Status_0($classId);
  408. foreach ($stuData as $kk => $vv) {
  409. $this->sConn->createCommand()->insert('general_product_student', array(
  410. 'gp_id' => $gpId,
  411. 'student_id' => $vv['student_id'],
  412. ));
  413. }
  414. //插入一条学生id为0的作为教师产品
  415. $this->sConn->createCommand()->insert('general_product_student', array(
  416. 'gp_id' => $gpId,
  417. 'student_id' => 0,
  418. 'is_teaching_pdf' => 1,
  419. ));
  420. array_push($gpIds, $gpId);
  421. }
  422. //发送消息
  423. //{"school_id":"599","msg_type":90,"subject_id":3,"send_type":"special","product_type":29,"gp_group_id":"780620754713923584","gp_ids":["780620755246600192","780620755766693888"]}
  424. $sendMsg=array(
  425. 'school_id'=>$this->schoolId,
  426. 'msg_type'=>1,
  427. 'subject_id'=>$this->subjectId,
  428. 'send_type'=>'special',
  429. 'product_type'=>29,
  430. 'gp_group_id'=>$groupId,
  431. 'gp_ids'=>$gpIds
  432. );
  433. $transaction->commit();
  434. sendDataToKafka('php-product-html',$sendMsg);
  435. } catch (Exception $e) {
  436. $transaction->rollBack();
  437. if (YII_ENV == 'production') {
  438. $error[] = '系统错误[SQL]';
  439. } else {
  440. $error[] = $e->getMessage();
  441. }
  442. }
  443. }
  444. if ($error) {
  445. echo json_encode(array('status' => 0, 'error' => $error));
  446. exit;
  447. } else {
  448. echo json_encode(array('status' => 1));
  449. exit;
  450. }
  451. }
  452. //获取专题宝产品班级
  453. public function actionAjaxGetClasses()
  454. {
  455. $result = array();
  456. $grade = (int)Req::post('grade');
  457. if ($grade) {
  458. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
  459. $data = $this->sConn->createCommand($sql)->queryAll();
  460. if ($data) {
  461. $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  462. $Sem = new SSemester();
  463. $code = $Sem->conn->createQuery()
  464. ->from('semester')
  465. ->where("semester_id = '" . $this->semesterId . "'")
  466. ->limit(1)
  467. ->query()
  468. ->read();
  469. foreach ($data as $k => $v) {
  470. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($v['class_id']);
  471. if($studentIds) {
  472. $intarr = array(
  473. "schoolId" => $this->schoolId,
  474. "clazzId" => $v['class_id'],
  475. "semester" => $code['refer_code'],
  476. "grade" => 3,
  477. "students" => $studentIds,
  478. "examTime" => time(),
  479. "classify" => 31,
  480. "subject" => 3
  481. );
  482. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  483. if (!$rs) {
  484. echo json_encode(array('status' => 0, 'error' => '接口错误'));
  485. exit;
  486. }
  487. if ($rs->errCode != "00") {
  488. echo json_encode(array('status' => 0, 'error' => $rs->errMsg));
  489. exit;
  490. }
  491. if (!empty($rs->data)) {
  492. array_push($result, array('class_id' => $v['class_id'], 'class_name' => $v['class_name']));
  493. }
  494. }
  495. }
  496. }
  497. }
  498. echo json_encode($result);
  499. exit;
  500. }
  501. //专题宝班级重置页面
  502. public function actionClasses()
  503. {
  504. $groupId = Req::get('gp_group_id');
  505. $name = Req::get('name');
  506. if (empty($groupId) || empty($name)) {
  507. Yii::app()->jump->error('参数异常');
  508. }
  509. $newCondition[] = 'g.gp_group_id=' . $groupId;
  510. $model = new SGeneralProductSetting();
  511. $rs = $model->getList($newCondition, array('g.create_time desc'), 100);
  512. if (!isset($rs['rs'])) {
  513. Yii::app()->jump->error('获取班级数据失败');
  514. }
  515. $resetTotal=3;//学管重置总次数
  516. foreach($rs['rs'] as $key=>$item){
  517. //学管剩余重置次数
  518. $item['learn_tube_reset_residue_count']=$resetTotal>$item['learn_tube_reset_count']?$resetTotal-$item['learn_tube_reset_count']:0;
  519. //学管30分钟内只能重置一次
  520. $item['is_cool_down']=time()-$item['learn_tube_reset_time']<=1800?0:1;
  521. //冷却文字提示 30分钟内并且剩余次数大于0
  522. $item['is_cool_down_prompt']=!$item['is_cool_down'] && $item['learn_tube_reset_residue_count']?true:false;
  523. $rs['rs'][$key]=$item;
  524. }
  525. //是不是技术支持
  526. $isTechnicalSupport=1;
  527. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
  528. $isTechnicalSupport=0;
  529. }
  530. $data['resultList'] = $rs['rs'];
  531. $data['productName'] = $name;
  532. $data['currentWeek'] = date('W');
  533. $data['is_technical_support']=$isTechnicalSupport;
  534. $this->render('reset', $data);
  535. }
  536. //重置操作
  537. public function actionReset()
  538. {
  539. $gpIds = Req::post('classExam');
  540. if (!$gpIds || !is_array($gpIds)) {
  541. echo json_encode(array("status" => 0, "message" => "参数错误!"));
  542. exit;
  543. }
  544. $transaction = $this->sConn->beginTransaction();
  545. try {
  546. $gpIdsStr=implode(',',$gpIds);
  547. $sql="select gp_id,reset_times,learn_tube_reset_count from general_product where gp_id in ({$gpIdsStr})";
  548. $generalProducts=$this->sConn->createCommand($sql)->queryAll();
  549. $learnTubeResetCounts=_array_column($generalProducts,'learn_tube_reset_count','gp_id');
  550. foreach ($gpIds as $gpId) {
  551. $this->sConn->createCommand()->update("general_product_student", array(
  552. 'is_create_html' => 90,
  553. 'is_create_pdf' => 90,
  554. 'is_download' => 0,
  555. 'pdf_page_num' => 0,
  556. 'pdf_sheet_num' => 0,), "gp_id = '{$gpId}'");
  557. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ) {
  558. if(!isset($learnTubeResetCounts[$gpId])){
  559. continue;
  560. }
  561. $learnTubeResetCount=$learnTubeResetCounts[$gpId]+1;
  562. $this->sConn->createCommand()->update("general_product", array('reset_times' => new CDbExpression('reset_times+1'),'learn_tube_reset_count'=>$learnTubeResetCount,'learn_tube_reset_time'=>time()), "gp_id = '{$gpId}'");
  563. }else{
  564. $this->sConn->createCommand()->update("general_product", array('reset_times' => new CDbExpression('reset_times+1')), "gp_id = '{$gpId}'");
  565. }
  566. }
  567. //发送消息
  568. $groupModel = SGeneralProduct::model()->find('gp_id=:gp_id',array('gp_id'=>$gpIds[0]));
  569. if(!$groupModel){
  570. echo json_encode(array("status" => 0, "message" => "数据异常!"));
  571. exit;
  572. }
  573. // setting更新补提信息
  574. $this->sConn->createCommand()->update("general_product_setting", array('status' =>1), "gp_group_id = '{$groupModel['gp_group_id']}'");
  575. $sendMsg=array(
  576. 'school_id'=>$this->schoolId,
  577. 'msg_type'=>90,
  578. 'subject_id'=>$this->subjectId,
  579. 'send_type'=>'special',
  580. 'product_type'=>29,
  581. 'gp_group_id'=>$groupModel['gp_group_id'],
  582. 'gp_ids'=>$gpIds
  583. );
  584. $transaction->commit();
  585. sendDataToKafka('php-product-html',$sendMsg);
  586. } catch (\Exception $e) {
  587. $transaction->rollBack();
  588. echo json_encode(array('status' => 0, 'message' => $e->getMessage()));
  589. exit;
  590. }
  591. echo json_encode(array('status' => 1));
  592. exit;
  593. }
  594. //专题宝教师版
  595. public function actionTeaching()
  596. {
  597. $gpId = Req::get('gpId');
  598. if (!$gpId) {
  599. echo json_encode(array("status" => 0, "message" => "参数错误!"));
  600. exit;
  601. }
  602. $rs = SGeneralProductStudent::model()->find('gp_id=:gp_id and is_teaching_pdf=1 and is_create_pdf=1',array('gp_id'=>$gpId));
  603. if(empty($rs) && empty($rs['pdf_path'])){
  604. echo json_encode(array("status" => 0, "message" => "pdf未生成"));
  605. exit;
  606. }
  607. if($rs['pdf_create_time']<(time()-604800)){
  608. echo json_encode(array("status" => 0, "message" => "pdf已失效,请重新生成!"));
  609. exit;
  610. }
  611. echo json_encode(array('status'=>1, 'url'=>Yii::app()->params['static_url'][$this->schoolGroupId].$rs['pdf_path']));exit;
  612. }
  613. public function actionDownloadDir(){
  614. $filename= dirname(dirname(dirname(__FILE__))).'/assets/data/special_method.pdf';
  615. if (FALSE!== ($handler = fopen($filename, 'r')))
  616. {
  617. header('Content-Description: File Transfer');
  618. header('Content-Type: application/octet-stream');
  619. header('Content-Disposition: attachment; filename=专题宝方法对应目录.pdf');
  620. header('Content-Transfer-Encoding: chunked'); //changed to chunked
  621. header('Expires: 0');
  622. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  623. header('Pragma: public');
  624. while (!feof($handler)) {
  625. file_put_contents("php://output", fread($handler, 4096));
  626. }
  627. fclose($handler);
  628. }
  629. }
  630. }