GeneralproductController.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <?php
  2. /**
  3. *
  4. * 专题宝
  5. *
  6. */
  7. class GeneralproductController extends Controller
  8. {
  9. /**
  10. * 假期作业产品表
  11. */
  12. public function actionIndex()
  13. {
  14. Url::clean();
  15. $data = array();
  16. $printName = Req::get("name");
  17. $classId = Req::get("classId");
  18. $grade = Req::get("grade");
  19. $productType = (int)Req::get("productType")?(int)Req::get("productType"):ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK;//产品类型
  20. $newCondition=array(
  21. 'g.product_type=' . $productType,
  22. 'g.subject_id=' . $this->subjectId,
  23. );
  24. if ($grade) {
  25. $newCondition[] = 'p.grade='.$grade;
  26. }
  27. if ($printName) {
  28. $newCondition[] = 'p.name like "%' . $printName . '%"';
  29. }
  30. if ($classId) {
  31. $newCondition[] = 'p.class_id=' . $classId;
  32. }
  33. $generalProductSttingModel = new SGeneralProductSetting();
  34. $resultList = $generalProductSttingModel->getList($newCondition, array('p.create_time desc'), 9);
  35. $printList = array();
  36. if ($resultList["rs"]) {
  37. foreach ($resultList['rs'] as $k => $v) {
  38. $printList[$k] = $v;
  39. $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']));
  40. }
  41. }
  42. $isSetting=false;
  43. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
  44. $months=array(11,12,1,4,5,6,7);
  45. $currentMonth=(int)date('m',time());
  46. if(in_array($currentMonth,$months)){
  47. $isSetting=true;
  48. }
  49. }else{
  50. $isSetting=true;
  51. }
  52. if(in_array($productType,array(ProductDownload::PRODUCT_TYPE_WRONG_REFINE))){
  53. $isSetting = true;
  54. }
  55. $productDesc = ProductDownload::$desc;
  56. $productName = isset($productDesc[$productType]) ? $productDesc[$productType]: "";
  57. $classes = $this->schoolManager->getClasses($grade);
  58. $data['pages'] = $resultList['pager'];
  59. $data['page_total'] = $resultList['pager']->rowsCount;
  60. $data['printList'] = $printList;
  61. $data["printName"] = $printName;
  62. $data["classes"] = $classes;
  63. $data["classId"] = $classId;
  64. $data["grade"] = $grade;
  65. $data['printType'] = 'special';
  66. $data['subjectId'] = $this->subjectId;
  67. $data['productType'] = $productType;
  68. $data['productName']=$productName;//产品名称
  69. $data['isSetting']=$isSetting;//假期作业入口
  70. //debug($data['productName']);exit;
  71. $this->render('index', $data);
  72. }
  73. /**
  74. * 学生列表
  75. */
  76. public function actionStu()
  77. {
  78. $data = array();
  79. $sname = (string)Req::get("sname"); //学生名字
  80. $gpId = (string)Req::get("gp_id");
  81. $type = (int)Req::get("type");
  82. if (!$gpId || !$type) {
  83. Yii::app()->jump->error('参数错误!');
  84. }
  85. //获取班级名称以及产品名称
  86. $sql = "select g.name,c.class_name,g.class_id,g.create_time,g.semester_id,g.grade from general_product g join class c on g.class_id = c.class_id where g.gp_id = '{$gpId}'";
  87. $names = $this->sConn->createCommand($sql)->queryRow();
  88. if (empty($names)) {
  89. Yii::app()->jump->error('数据错误!');
  90. }
  91. $data['name'] = isset($names['name']) && isset($names['class_name']) ? $names['class_name'] . $names['name'] : '';
  92. $sql = "select student_id,is_create_pdf from general_product_student where gp_id = '{$gpId}'";
  93. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  94. $studentIds = array();
  95. $stuIsPdf = array();
  96. if ($relateStudent) {
  97. foreach ($relateStudent as $studentInfo) {
  98. $studentIds[] = (string)$studentInfo['student_id'];
  99. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_create_pdf'];
  100. }
  101. }
  102. if ($studentIds) {
  103. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  104. if ($studentNames) {
  105. if ($sname) {
  106. $i = 1;
  107. foreach ($studentNames as $k => $v) {
  108. if (strpos($v, $sname) !== false) {
  109. $data['list'][$i]['stu_id'] = (string)$k;
  110. $data['list'][$i]['stu_name'] = $v;
  111. $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
  112. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
  113. $i++;
  114. }
  115. }
  116. } else {
  117. $i = 1;
  118. foreach ($studentNames as $k => $v) {
  119. $data['list'][$i]['stu_id'] = (string)$k;
  120. $data['list'][$i]['stu_name'] = $v;
  121. $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
  122. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
  123. $i++;
  124. }
  125. }
  126. }
  127. }
  128. $Sem = new SSemester();
  129. $code = $Sem->conn->createQuery()
  130. ->from('semester')
  131. ->where("semester_id = '" . $names['semester_id'] . "'")
  132. ->limit(1)
  133. ->query()
  134. ->read();
  135. $intarr = array(
  136. "schoolId" => $this->schoolId,
  137. "clazzId" => $names['class_id'],
  138. "semester" => $code['refer_code'],
  139. "grade" => $names['grade'],
  140. "students" => $studentIds,
  141. "examTime" => $names['create_time'],
  142. "classify" => $type,
  143. "subject" => $this->subjectId
  144. );
  145. $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  146. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  147. if (!$rs) {
  148. Yii::app()->jump->error("接口错误");
  149. }
  150. if ($rs->errCode != "00") {
  151. Yii::app()->jump->error($rs->errMsg);
  152. }
  153. if (!empty($rs->data)) {
  154. $data['limitstu'] = $rs->data;
  155. }
  156. $productDesc = ProductDownload::$desc;
  157. $productName = isset($productDesc[$type]) ? $productDesc[$type]: "";
  158. $data['gp_id'] = $gpId;
  159. $data['class_id'] = $names['class_id'];
  160. $data['sname'] = $sname;
  161. $data['type'] = $type;
  162. $data['productName'] = $productName;
  163. $data['printType'] = 'general_product';
  164. $this->render('stu', $data);
  165. }
  166. /**
  167. * 设置
  168. */
  169. public function actionSetting()
  170. {
  171. $productType = (int)Req::get("productType")?(int)Req::get("productType"):ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK;//产品类型
  172. $productDesc = ProductDownload::$desc;
  173. $productName = isset($productDesc[$productType]) ? $productDesc[$productType]: "";
  174. $semesterModel=new Semester();
  175. $semesterName=$semesterModel->getSemesterName($this->semesterId);
  176. $data=array(
  177. 'productName'=>$productName,
  178. 'semesterName'=>$semesterName,
  179. 'productType'=>$productType,
  180. );
  181. if($productType==ProductDownload::PRODUCT_TYPE_WRONG_REFINE) {
  182. $this->render('setting_homework2',$data);
  183. }
  184. if($productType==ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK) {
  185. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$this->schoolId));
  186. $type=1;//默认新高考
  187. if(isset($schoolInfo['province_id']) && in_array($this->subjectId, array(8))){
  188. $provinceGradeIsnewResult=$this->apiPost('all_content/provinceGradeIsnew',array('subjectId'=>array($this->subjectId),'provinceId'=>$schoolInfo['province_id'],'grade'=>1));
  189. if(isset($provinceGradeIsnewResult['status']) && $provinceGradeIsnewResult['status'] && isset($provinceGradeIsnewResult['data'][0]['is_new'])){
  190. $type=$provinceGradeIsnewResult['data'][0]['is_new'];
  191. }
  192. }
  193. $data['type']=$type;
  194. if (in_array($this->subjectId, array(8))) { //英语
  195. $this->render('setting_homework',$data);
  196. } elseif (in_array($this->subjectId, array(3, 6, 51, 12))) {//物理
  197. $this->render('setting_homework2',$data);
  198. }
  199. }
  200. }
  201. /**
  202. * 假期作业设置
  203. */
  204. private function getHolidayHomeworkSetting($settingJson){
  205. $setting=array();
  206. if (in_array($this->subjectId, array(8))) { //英语
  207. if(!isset($settingJson['scoringRate']) || !isset($settingJson['examType']) || !isset($settingJson['layeredTraining']) || !isset($settingJson['isAnswerMerge'])){
  208. exit(json_encode(array('status' => 0, 'error' => '请检查参数')));
  209. }
  210. $scoringRate=$settingJson['scoringRate'];
  211. $examType=$settingJson['examType'];
  212. $layered=$settingJson['layeredTraining'];
  213. $isAnswerMerge=$settingJson['isAnswerMerge'];
  214. if(!in_array($scoringRate,array('A','B','C')) || !in_array($examType,array(1,2)) || !in_array($isAnswerMerge,array(0,1))){
  215. exit(json_encode(array('status' => 0, 'error' =>'参数不在范围内')));
  216. }
  217. $reg="/^[0-9]*$/";
  218. if(!isset($layered['hearing']) || !isset($layered['readingComprehension']) || !isset($layered['sevenChooseFive']) || !isset($layered['completionFillIn'])|| !isset($layered['grammaticalFillIn']) || !isset($layered['practicalWriting'])
  219. || ($examType==1 && !isset($layered['readingPriorWritten'])) || ($examType==2 && !isset($layered['passagesChangeWrong'])) ){
  220. exit(json_encode(array('status' => 0, 'error' => '请检查分层训练参数')));
  221. }elseif(!preg_match($reg, $layered['hearing']) || !preg_match($reg, $layered['readingComprehension']) || !preg_match($reg, $layered['sevenChooseFive']) || !preg_match($reg, $layered['completionFillIn']) || !preg_match($reg, $layered['grammaticalFillIn'])
  222. || !preg_match($reg, $layered['practicalWriting']) || ($examType==1 && !preg_match($reg, $layered['readingPriorWritten'])) || ($examType==2 && !preg_match($reg, $layered['passagesChangeWrong']))){
  223. exit(json_encode(array('status' => 0, 'error' =>'分层训练数量是等于0或者大于0的整数')));
  224. }
  225. $hearing=intval($layered['hearing']);
  226. $readingComprehension=intval($layered['readingComprehension']);
  227. $sevenChooseFive=intval($layered['sevenChooseFive']);
  228. $completionFillIn=intval($layered['completionFillIn']);
  229. $grammaticalFillIn=intval($layered['grammaticalFillIn']);
  230. $practicalWriting=intval($layered['practicalWriting']);
  231. $readingPriorWritten=$examType==1 && isset($layered['readingPriorWritten'])?intval($layered['readingPriorWritten']):0;
  232. $passagesChangeWrong=$examType==2 && isset($layered['passagesChangeWrong'])?intval($layered['passagesChangeWrong']):0;
  233. if(($hearing<0 || $hearing>1) || ($readingComprehension<0 || $readingComprehension>8) || ($sevenChooseFive<0 || $sevenChooseFive>3) || ($completionFillIn<0 || $completionFillIn>3) ||
  234. ($grammaticalFillIn<0 || $grammaticalFillIn>5) || ($practicalWriting<0 || $practicalWriting>1) ||
  235. ($examType==1 && ($readingPriorWritten<0 || $readingPriorWritten>1) ) || ($examType==2 && ($passagesChangeWrong<0 || $passagesChangeWrong>5))
  236. ){
  237. exit(json_encode(array('status' => 0, 'error' =>'请检查分层训练参数是否在限制范围内')));
  238. }
  239. $totalCount=$hearing+$readingComprehension+$sevenChooseFive+$completionFillIn+$grammaticalFillIn+$practicalWriting+$readingPriorWritten+$passagesChangeWrong;
  240. if($totalCount<3){
  241. exit(json_encode(array('status' => 0, 'error' => '分层训练题数不少于3个')));
  242. }
  243. //分层训练
  244. $layeredTraining=array(
  245. 'hearing'=>$hearing,
  246. 'reading_comprehension'=>$readingComprehension,
  247. 'seven_choose_five'=>$sevenChooseFive,
  248. 'completion_fill_in'=>$completionFillIn,
  249. 'grammatical_fill_in'=>$grammaticalFillIn,
  250. 'practical_writing'=>$practicalWriting,
  251. );
  252. if($examType==1){
  253. $layeredTraining['reading_prior_written']=$readingPriorWritten;
  254. }else{
  255. $layeredTraining['passages_change_wrong']=$passagesChangeWrong;
  256. }
  257. $setting=array(
  258. 'product_type'=>ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK,
  259. 'scoring_rate'=>$scoringRate,
  260. 'exam_type'=>$examType,
  261. 'layered_training'=>$layeredTraining,
  262. 'is_answer_merge'=>$isAnswerMerge?true:false,
  263. );
  264. } elseif (in_array($this->subjectId, array(3, 6, 51, 12))) {//数学,物理
  265. if(!isset($settingJson['scoringRate']) || !isset($settingJson['isAnswerMerge'])){
  266. exit(json_encode(array('status' => 0, 'error' => '请检查参数')));
  267. }
  268. $scoringRate=$settingJson['scoringRate'];
  269. $isAnswerMerge=$settingJson['isAnswerMerge'];
  270. if(!in_array($scoringRate,array('A','B','C')) || !in_array($isAnswerMerge,array(0,1))){
  271. exit(json_encode(array('status' => 0, 'error' => '参数不在范围内')));
  272. }
  273. $setting=array(
  274. 'product_type'=>ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK,
  275. 'scoring_rate'=>$scoringRate,
  276. 'is_answer_merge'=>$isAnswerMerge?true:false,
  277. );
  278. }
  279. return $setting;
  280. }
  281. /**
  282. * 假期作业校验成绩
  283. * @param $classIds
  284. */
  285. private function holidayHomeworkCheckScore($classIds,$subjectIds){
  286. if(in_array($subjectIds,array(3,6,51))){
  287. $subjectIds=array(3,6,51);
  288. }else{
  289. $subjectIds=array($subjectIds);
  290. }
  291. $subjectIds=implode(',',$subjectIds);
  292. $classIdsStr=implode(',',$classIds);
  293. $sql="select class_id from exam where class_id in ({$classIdsStr}) and semester_id={$this->semesterId} and status=1 and subject_id in ({$subjectIds}) group by class_id";
  294. $examInfo = $this->sConn->createCommand($sql)->queryAll();
  295. $examClassIds=_array_column($examInfo,'class_id');
  296. if(count($classIds)!=count($examClassIds)){
  297. $diff=array_diff($classIds,$examClassIds);
  298. $diffClassIdsStr=implode(',',$diff);
  299. $sql="select class_id,class_name from class where class_id in ({$diffClassIdsStr})";
  300. $classInfo=$this->sConn->createCommand($sql)->queryAll();
  301. if(!$classInfo){
  302. exit(json_encode(array('status' => 0, 'error' => '请刷新后再试!')));
  303. }
  304. $classNames=implode(',',_array_column($classInfo,'class_name'));
  305. $msg="{$classNames},班级无考试数据!<br/>无考试数据的班级,可以至试卷管理中导入一场考试数据";
  306. exit(json_encode(array('status' => 0, 'error' =>$msg)));
  307. }
  308. }
  309. /**
  310. * 生成设置保存
  311. */
  312. public function actionAjaxSaveSetting()
  313. {
  314. $error = array();
  315. if (!Yii::app()->request->isAjaxRequest OR !Yii::app()->request->isPostRequest) {
  316. $error[] = '错误的来源!';
  317. } else {
  318. $grade = (int)Req::post('grade');
  319. $textbook = (int)Req::post('textbook');
  320. $classIds = (array)Req::post('selectClassIds');
  321. $productType = (int)Req::post('productType');
  322. $settingJson = Req::post('settingJson');
  323. $settingJson = str_replace('&quot;', '"', $settingJson);
  324. $productTypeArr=array(
  325. ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK,
  326. ProductDownload::PRODUCT_TYPE_WRONG_REFINE
  327. );
  328. if(!in_array($productType,$productTypeArr)){
  329. exit(json_encode(array('status' => 0, 'error' => '请检查产品类型参数')));
  330. }
  331. if (!json_decode($settingJson, true)) {
  332. exit(json_encode(array('status' => 0, 'error' => '设置内容错误')));
  333. }
  334. $textbookArr=array(
  335. 1=>'第一册',2=>'第二册',3=>'第三册',4=>'第四册',5=>'第五册',6=>'第六册',
  336. );
  337. $settingJson=json_decode($settingJson, true);
  338. $setting=array();
  339. if($productType==ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK){
  340. $topic_name = 'php-product-holiday-work-html';
  341. $send_type = 'holiday_work';
  342. $semesterModel=new Semester();
  343. $name=$semesterModel->getSemesterName($this->semesterId);
  344. $name.='"假期作业"';
  345. $this->holidayHomeworkCheckScore($classIds,$this->subjectId);//假期作业校验成绩
  346. $setting=$this->getHolidayHomeworkSetting($settingJson);
  347. }else if($productType==ProductDownload::PRODUCT_TYPE_WRONG_REFINE){
  348. $topic_name = 'php-product-wrong-topic-refining';
  349. $send_type = 'wrong_topic_refining';
  350. $semesterModel=new Semester();
  351. $name=$semesterModel->getSemesterName($this->semesterId);
  352. $name.='"错题精练"';
  353. if($textbook && isset($textbookArr[$textbook])){
  354. $name.=$textbookArr[$textbook];
  355. }
  356. $this->holidayHomeworkCheckScore($classIds,$this->subjectId);//假期作业校验成绩
  357. //订单校验
  358. // $strModel = new SStudentClassRelation();
  359. // $intArr=array();
  360. // foreach ($classIds as $id){
  361. // $stuData = $strModel->getRelationsByClassId_Status_0($id);
  362. // if($stuData){
  363. // $studentIds=array();
  364. // foreach ($stuData as $datum){
  365. // $studentIds[]=$datum['student_id'];
  366. // }
  367. // $intArr[]=array(
  368. // "schoolId"=>$this->schoolId,
  369. // "clazzId"=>$id,
  370. // "semester"=>$this->semesterId,
  371. // "grade"=>$grade,
  372. // "students"=>$studentIds,
  373. // "examTime"=>time(),
  374. // "classify"=>$productType,
  375. // "subject"=>$this->subjectId
  376. // );
  377. //
  378. // }
  379. // }
  380. // $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  381. // $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intArr),$basic));
  382. //
  383. //
  384. // if(!$rs){
  385. // exit(json_encode(array('status' => 0, 'error' => '查询订单接口有误')));
  386. // }
  387. // if(empty($rs->data)){
  388. // $classInfo=ClassModel::model()->find($id);
  389. // exit(json_encode(array('status' => 0, 'error' => $classInfo->class_name.'班级无人开通订单')));
  390. // }
  391. $setting['product_type'] = ProductDownload::PRODUCT_TYPE_WRONG_REFINE;
  392. $setting['is_answer_merge'] = isset($settingJson['isAnswerMerge']) && $settingJson['isAnswerMerge']?true:false;
  393. }
  394. //次数限制
  395. if(!$setting){
  396. exit(json_encode(array('status' => 0, 'error' => '无生成配置数据')));
  397. }
  398. $time = time();
  399. $transaction = $this->sConn->beginTransaction();
  400. try {
  401. $groupId = getUniqueId($this->schoolId);
  402. $strModel = new SStudentClassRelation();
  403. $this->sConn->createCommand()->insert('general_product_setting', array(
  404. 'gp_group_id' => $groupId,
  405. 'grade' => $grade,
  406. 'textbook'=>$textbook,
  407. 'product_type' => $productType,
  408. 'subject_id' => $this->subjectId,
  409. 'semester_id' => $this->semesterId,
  410. 'setting' => json_encode($setting, true),
  411. 'create_time' => $time,
  412. 'update_time' => $time,
  413. ));
  414. $gpIds = array();
  415. foreach ($classIds as $classId) {
  416. $gpId = getUniqueId($this->schoolId);
  417. $this->sConn->createCommand()->insert('general_product', array(
  418. 'gp_id' => $gpId,
  419. 'gp_group_id' => $groupId,
  420. 'class_id' => $classId,
  421. 'grade' => $grade,
  422. 'name' =>$name,
  423. 'subject_id' => $this->subjectId,
  424. 'semester_id' => $this->semesterId,
  425. 'create_time' => $time,
  426. 'update_time' => $time,
  427. ));
  428. //获取班级学生
  429. $stuData = $strModel->getRelationsByClassId_Status_0($classId);
  430. foreach ($stuData as $kk => $vv) {
  431. $this->sConn->createCommand()->insert('general_product_student', array(
  432. 'gp_id' => $gpId,
  433. 'student_id' => $vv['student_id'],
  434. ));
  435. }
  436. array_push($gpIds, $gpId);
  437. }
  438. // $sendMsg=array(
  439. // 'school_id'=>$this->schoolId,
  440. // 'msg_type'=>1,
  441. // 'subject_id'=>$this->subjectId,
  442. // 'send_type'=>'holiday_work',
  443. // 'product_type'=>$productType,
  444. // 'gp_group_id'=>$groupId,
  445. // 'gp_ids'=>$gpIds
  446. // );
  447. $transaction->commit();
  448. // sendDataToKafka('php-product-holiday-work-html',$sendMsg);
  449. } catch (Exception $e) {
  450. $transaction->rollBack();
  451. if (YII_ENV == 'production') {
  452. $error[] = '系统错误[SQL]';
  453. } else {
  454. $error[] = $e->getMessage();
  455. }
  456. }
  457. }
  458. if ($error) {
  459. echo json_encode(array('status' => 0, 'error' => $error));
  460. exit;
  461. } else {
  462. $sendMsg=array(
  463. 'school_id'=>$this->schoolId,
  464. 'msg_type'=>1,
  465. 'subject_id'=>$this->subjectId,
  466. 'send_type'=>$send_type,
  467. 'product_type'=>$productType,
  468. 'gp_group_id'=>$groupId,
  469. 'gp_ids'=>$gpIds
  470. );
  471. sendDataToKafka($topic_name,$sendMsg);
  472. echo json_encode(array('status' => 1));
  473. exit;
  474. }
  475. }
  476. //产品班级
  477. public function actionAjaxGetClasses()
  478. {
  479. $result = array();
  480. $grade = (int)Req::post('grade');
  481. $productType = (int)Req::post('productType');
  482. $textbook = (int)Req::post('textbook');
  483. if ($grade && $productType) {
  484. $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
  485. $data = $this->sConn->createCommand($sql)->queryAll();
  486. if ($data) {
  487. $classIds=array();
  488. foreach ($data as $k => $v) {
  489. $classIds[]=$v['class_id'];
  490. }
  491. if($classIds){
  492. $classIds=implode(',',$classIds);
  493. if($textbook){
  494. $sql="select class_id,count(*) count from general_product_setting gps inner join general_product gp on gps.gp_group_id=gp.gp_group_id where gps.textbook='{$textbook}' and gps.semester_id ='{$this->semesterId}' and gps.product_type={$productType} and gps.grade={$grade} and gps.subject_id={$this->subjectId} and gp.class_id in ($classIds) group by class_id";
  495. }else{
  496. $sql="select class_id,count(*) count from general_product_setting gps inner join general_product gp on gps.gp_group_id=gp.gp_group_id where gps.semester_id ='{$this->semesterId}' and gps.product_type={$productType} and gps.grade={$grade} and gps.subject_id={$this->subjectId} and gp.class_id in ($classIds) group by class_id";
  497. }
  498. $classProduct = $this->sConn->createCommand($sql)->queryAll();
  499. foreach($classProduct as $key=>$item){
  500. $classProduct[$item['class_id']]=$item['count'];
  501. unset($classProduct[$key]);
  502. }
  503. foreach($data as $item){
  504. if($productType == ProductDownload::PRODUCT_TYPE_WRONG_REFINE){
  505. $item['status']=isset($classProduct[$item['class_id']]) && $classProduct[$item['class_id']] > 2 ?1:0;
  506. }else{
  507. $item['status']=isset($classProduct[$item['class_id']])?$classProduct[$item['class_id']]:0;
  508. }
  509. $result[]=$item;
  510. }
  511. }
  512. }
  513. }
  514. echo json_encode($result);
  515. exit;
  516. }
  517. //重置页面
  518. public function actionClasses()
  519. {
  520. $groupId = Req::get('gp_group_id');
  521. $name = stripslashes(Req::get('name'));
  522. $productType = Req::get('productType');
  523. if (empty($groupId) || empty($name)) {
  524. Yii::app()->jump->error('参数异常');
  525. }
  526. $newCondition[] = 'g.gp_group_id=' . $groupId;
  527. $model = new SGeneralProductSetting();
  528. $rs = $model->getList($newCondition, array('g.create_time desc'), 100);
  529. if (!isset($rs['rs'])) {
  530. Yii::app()->jump->error('获取班级数据失败');
  531. }
  532. $resetTotal=3;//学管重置总次数
  533. foreach($rs['rs'] as $key=>$item){
  534. //学管剩余重置次数
  535. $item['learn_tube_reset_residue_count']=$resetTotal>$item['learn_tube_reset_count']?$resetTotal-$item['learn_tube_reset_count']:0;
  536. //学管30分钟内只能重置一次
  537. $item['is_cool_down']=time()-$item['learn_tube_reset_time']<=1800?0:1;
  538. //冷却文字提示 30分钟内并且剩余次数大于0
  539. $item['is_cool_down_prompt']=!$item['is_cool_down'] && $item['learn_tube_reset_residue_count']?true:false;
  540. $rs['rs'][$key]=$item;
  541. }
  542. //是不是技术支持
  543. $isTechnicalSupport=1;
  544. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
  545. $isTechnicalSupport=0;
  546. }
  547. $productDesc = ProductDownload::$desc;
  548. $productName = isset($productDesc[$productType]) ? $productDesc[$productType]: "";
  549. $data['resultList'] = $rs['rs'];
  550. $data['name'] = $name;
  551. $data['productName'] = $productName;
  552. $data['currentWeek'] = date('W');
  553. $data['is_technical_support']=$isTechnicalSupport;
  554. //debug($data);exit;
  555. $this->render('reset', $data);
  556. }
  557. //重置操作
  558. public function actionReset()
  559. {
  560. $gpIds = Req::post('classExam');
  561. if (!$gpIds || !is_array($gpIds)) {
  562. echo json_encode(array("status" => 0, "message" => "参数错误!"));
  563. exit;
  564. }
  565. $sendStatus = 1;
  566. $tempProductType = 0;
  567. $transaction = $this->sConn->beginTransaction();
  568. try {
  569. $gpIdsStr=implode(',',$gpIds);
  570. $sql="select gp_id,reset_times,learn_tube_reset_count from general_product where gp_id in ({$gpIdsStr})";
  571. $generalProducts=$this->sConn->createCommand($sql)->queryAll();
  572. $learnTubeResetCounts=_array_column($generalProducts,'learn_tube_reset_count','gp_id');
  573. foreach ($gpIds as $gpId) {
  574. $this->sConn->createCommand()->update("general_product_student", array(
  575. 'is_create_html' => 90,
  576. 'is_create_pdf' => 90,
  577. 'is_download' => 0,
  578. 'pdf_page_num' => 0,
  579. 'pdf_sheet_num' => 0,), "gp_id = '{$gpId}'");
  580. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1) {
  581. if(!isset($learnTubeResetCounts[$gpId])){
  582. continue;
  583. }
  584. $learnTubeResetCount=$learnTubeResetCounts[$gpId]+1;
  585. $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}'");
  586. }else{
  587. $this->sConn->createCommand()->update("general_product", array('reset_times' => new CDbExpression('reset_times+1')), "gp_id = '{$gpId}'");
  588. }
  589. }
  590. //发送消息
  591. $groupModel = SGeneralProduct::model()->find('gp_id=:gp_id',array('gp_id'=>$gpIds[0]));
  592. if(!$groupModel){
  593. echo json_encode(array("status" => 0, "message" => "数据异常!"));
  594. exit;
  595. }
  596. if(!$tempProductType){
  597. $groupSettingModel = SGeneralProductSetting::model()->find('gp_group_id=:gp_group_id',array('gp_group_id'=>$groupModel['gp_group_id']));
  598. if(!$groupSettingModel){
  599. echo json_encode(array("status" => 0, "message" => "设置数据异常!"));
  600. exit;
  601. }else{
  602. $tempProductType = $groupSettingModel['product_type'];
  603. }
  604. }
  605. // setting更新补提信息
  606. $this->sConn->createCommand()->update("general_product_setting", array('status' =>1), "gp_group_id = '{$groupModel['gp_group_id']}'");
  607. if($tempProductType == ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK){
  608. $topicName = 'php-product-holiday-work-html';
  609. $sendType = 'holiday_work';
  610. }else if($tempProductType==ProductDownload::PRODUCT_TYPE_WRONG_REFINE){
  611. $topicName = 'php-product-wrong-topic-refining';
  612. $sendType = 'wrong_topic_refining';
  613. }else{
  614. $sendStatus = 0;
  615. }
  616. // $sendMsg=array(
  617. // 'school_id'=>$this->schoolId,
  618. // 'msg_type'=>90,
  619. // 'subject_id'=>$this->subjectId,
  620. // 'send_type'=>'holiday_work',
  621. // 'product_type'=>50,
  622. // 'gp_group_id'=>$groupModel['gp_group_id'],
  623. // 'gp_ids'=>$gpIds
  624. // );
  625. $transaction->commit();
  626. // sendDataToKafka('php-product-holiday-work-html',$sendMsg);
  627. } catch (\Exception $e) {
  628. $transaction->rollBack();
  629. echo json_encode(array('status' => 0, 'message' => $e->getMessage()));
  630. exit;
  631. }
  632. if($sendStatus && $tempProductType){
  633. $sendMsg=array(
  634. 'school_id'=>$this->schoolId,
  635. 'msg_type'=>90,
  636. 'subject_id'=>$this->subjectId,
  637. 'send_type'=>$sendType,
  638. 'product_type'=>$tempProductType,
  639. 'gp_group_id'=>$groupModel['gp_group_id'],
  640. 'gp_ids'=>$gpIds
  641. );
  642. sendDataToKafka($topicName,$sendMsg);
  643. }
  644. echo json_encode(array('status' => 1));
  645. exit;
  646. }
  647. public function apiPost($path, $arr, $type = 0)
  648. {
  649. $ch = @curl_init();
  650. $result = FALSE;
  651. if ($ch) {
  652. $data = json_encode($arr);
  653. $url = Yii::app()->params['api'][$type]['prefix'] . $path;
  654. $username = Yii::app()->params['api'][$type]['username'];
  655. $password = Yii::app()->params['api'][$type]['password'];
  656. // Digest认证
  657. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  658. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  659. // 不输出头部
  660. curl_setopt($ch, CURLOPT_HEADER, 0);
  661. // curl_exec 获取到的内容不直接输出, 而是返回
  662. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  663. // 请求重启路由器的地址 传参 进行重启
  664. curl_setopt($ch, CURLOPT_URL, $url);
  665. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  666. curl_setopt($ch, CURLOPT_POST, 1);
  667. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  668. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  669. 'Content-Type: application/json',
  670. 'Content-Length: ' . strlen($data),
  671. ));
  672. if (!curl_errno($ch)) {
  673. $result = json_decode(curl_exec($ch),1);
  674. }
  675. // 释放资源
  676. curl_close($ch);
  677. }
  678. return $result;
  679. }
  680. }