CorrectController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. <?php
  2. /**
  3. * 纠错本控制器类
  4. * @author jiangfei
  5. * @date 2015-07-22 17:50:00
  6. * @company .
  7. */
  8. class CorrectController extends Controller{
  9. //纠错本列表
  10. public function actionIndex(){
  11. $data = array();
  12. $printName = Req::get("name");
  13. $classId = Req::get("classId");
  14. $grade = (int)Req::get("grade");
  15. $newCondition = array();
  16. if($grade){
  17. $newCondition[] = 'gps.grade='.$grade;
  18. }
  19. if($printName){
  20. $newCondition[] = 'gp.name like "%'.$printName.'%"';
  21. }
  22. $newCondition[] = 'gps.product_type=66';
  23. $newCondition[] = "gps.subject_id='{$this->subjectId}'";
  24. $resultList = $this->schoolManager->getCorrect($newCondition,array('gps.create_time desc'));
  25. $printList = array();
  26. if($resultList["rs"]){
  27. foreach ($resultList['rs'] as $k=>$v) {
  28. $printList[$k]=$v;
  29. }
  30. }
  31. if (empty($grade)) {
  32. $grade = 'ALL';
  33. }
  34. $data['pages'] = $resultList['pager'];
  35. $data['page_total'] = $resultList['pager']->rowsCount;
  36. $data['printList'] = $printList;
  37. $data["printName"] = $printName;
  38. $data["grade"] = $grade;
  39. $this->render('index',$data);
  40. }
  41. //纠错本班级列表
  42. public function actionClassList(){
  43. $gpGroupId=Req::get('gpGroupId');
  44. if(!$gpGroupId){
  45. Yii::app()->jump->error('参数错误!');
  46. }
  47. $correctModel= new SGeneralProductSetting();
  48. $classList=$correctModel->getCorrectClassList($gpGroupId);
  49. $Sem=new SSemester();
  50. $code= $Sem->conn->createQuery()
  51. ->from('semester')
  52. ->where("semester_id = '".$this->semesterId."'")
  53. ->limit(1)
  54. ->query()
  55. ->read();
  56. if($classList){
  57. foreach ($classList as $key => $item){
  58. $students=$correctModel->getCorrectStudent($item['gp_id']);
  59. $studentIds=array();
  60. $createCount=0;
  61. $isDownload=0;
  62. $downloadTime=0;
  63. foreach ($students as $student){
  64. $studentIds[]=$student['student_id'];
  65. if($student['is_create_pdf']==1){
  66. $createCount++;
  67. }
  68. if(!$isDownload && $student['is_download']==1){
  69. $isDownload=1;
  70. $downloadTime=$student['download_time'];
  71. }
  72. }
  73. $classList[$key]['create_count']=$createCount;
  74. $classList[$key]['is_download']=$isDownload;
  75. $classList[$key]['download_time']=$downloadTime;
  76. $classList[$key]['order_student_count']=0;
  77. //订单学生数量
  78. $intarr=array(
  79. "schoolId"=>$this->schoolId,
  80. "clazzId"=>$item['class_id'],
  81. "semester"=>$code['refer_code'],
  82. "grade"=>$item['grade'],
  83. "students"=>$studentIds,
  84. "examTime"=>$item['create_time'],
  85. "classify"=>66,
  86. "subject"=>$this->subjectId
  87. );
  88. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  89. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  90. if(!$rs){
  91. Yii::app()->jump->error("接口错误");
  92. }
  93. if($rs->errCode!="00"){
  94. Yii::app()->jump->error($rs->errMsg);
  95. }
  96. if(!empty($rs->data)){
  97. $classList[$key]['order_student_count']=count($rs->data);
  98. }
  99. }
  100. }
  101. $data['printList']=$classList;
  102. $data['type']=66;
  103. $this->render('class_list',$data);
  104. }
  105. /**
  106. * 学生列表
  107. */
  108. public function actionStu()
  109. {
  110. $data = array();
  111. $sname = (string)Req::get("sname"); //学生名字
  112. $gpId = (string)Req::get("gp_id");
  113. if (!$gpId) {
  114. Yii::app()->jump->error('参数错误!');
  115. }
  116. //获取班级名称以及产品名称
  117. $sql = "select g.name,c.class_name,g.class_id,g.create_time,g.semester_id,c.grade from general_product g join class c on g.class_id = c.class_id where g.gp_id = '{$gpId}'";
  118. $names = $this->sConn->createCommand($sql)->queryRow();
  119. if (empty($names)) {
  120. Yii::app()->jump->error('数据错误!');
  121. }
  122. $sql = "select student_id,is_create_pdf from general_product_student where gp_id = '{$gpId}'";
  123. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  124. $studentIds = array();
  125. $stuIsPdf = array();
  126. if ($relateStudent) {
  127. foreach ($relateStudent as $studentInfo) {
  128. $studentIds[] = (string)$studentInfo['student_id'];
  129. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_create_pdf'];
  130. }
  131. }
  132. if ($studentIds) {
  133. $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
  134. if ($studentNames) {
  135. if ($sname) {
  136. $i = 1;
  137. foreach ($studentNames as $k => $v) {
  138. if (strpos($v, $sname) !== false) {
  139. $data['list'][$i]['stu_id'] = (string)$k;
  140. $data['list'][$i]['stu_name'] = $v;
  141. $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
  142. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
  143. $i++;
  144. }
  145. }
  146. } else {
  147. $i = 1;
  148. foreach ($studentNames as $k => $v) {
  149. $data['list'][$i]['stu_id'] = (string)$k;
  150. $data['list'][$i]['stu_name'] = $v;
  151. $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
  152. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
  153. $i++;
  154. }
  155. }
  156. }
  157. }
  158. $Sem = new SSemester();
  159. $code = $Sem->conn->createQuery()
  160. ->from('semester')
  161. ->where("semester_id = '" . $names['semester_id'] . "'")
  162. ->limit(1)
  163. ->query()
  164. ->read();
  165. $intarr = array(
  166. "schoolId" => $this->schoolId,
  167. "clazzId" => $names['class_id'],
  168. "semester" => $code['refer_code'],
  169. "grade" => $names['grade'],
  170. "students" => $studentIds,
  171. "examTime" => $names['create_time'],
  172. "classify" => 66,
  173. "subject" => 3
  174. );
  175. $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  176. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  177. if (!$rs) {
  178. Yii::app()->jump->error("接口错误");
  179. }
  180. if ($rs->errCode != "00") {
  181. Yii::app()->jump->error($rs->errMsg);
  182. }
  183. if (!empty($rs->data)) {
  184. $data['limitstu'] = $rs->data;
  185. }
  186. $data['gp_id'] = $gpId;
  187. $data['class_id'] = $names['class_id'];
  188. $data['sname'] = $sname;
  189. $data['type'] = ProductDownload::PRODUCT_TYPE_CORRECT;
  190. $data['printType'] = 'general_product';
  191. $this->render('stu', $data);
  192. }
  193. //加载考试根据时间年级
  194. public function actionLoadExam(){
  195. $grade=(int)Req::post('grade');
  196. $startDate=Req::post('startDate');
  197. $endDate=Req::post('endDate');
  198. $condition=array();
  199. $subject=$this->subjectId;
  200. // $grade=1;
  201. // $startDate='2023-01';
  202. // $endDate='2024-05';
  203. $condition[]='e.status=1';
  204. $condition[]="e.semester_id='{$this->semesterId}'";
  205. $condition[]='e.is_display=0';
  206. $condition[]='(tw.status=2 or eg.is_third=0)';
  207. if($subject==3){
  208. $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
  209. }else{
  210. $condition[]="e.subject_id ='".$subject."'";
  211. }
  212. if($grade){
  213. $condition[]="c.grade='".$grade."'";
  214. }
  215. $result['status']=0;
  216. if($startDate){
  217. $startDate=strtotime($startDate);
  218. $condition[]="e.complete_time>='".$startDate."'";
  219. }else{
  220. $result['msg']='请选择开始时间';
  221. exit(json_encode($result));
  222. }
  223. if($endDate){
  224. $endDate=strtotime($endDate);
  225. $condition[]="e.complete_time<='".$endDate."'";
  226. }else{
  227. $result['msg']='请选择结束时间';
  228. exit(json_encode($result));
  229. }
  230. $sql="SELECT distinct eg.exam_group_id,e.name,c.grade FROM `exam` e ";
  231. $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id ";
  232. $sql.=" left join topic_word tw on tw.exam_group_id=e.exam_group_id ";
  233. $sql.="join class c on c.class_id=e.class_id ";
  234. if($condition){
  235. $sql.=" where ".implode(' and ',$condition);
  236. }
  237. $list = $this->sConn->createCommand($sql)->queryAll();
  238. //
  239. // if($list){
  240. // foreach ($list as $key => $val){
  241. //
  242. // }
  243. // }
  244. $result['status']=1;
  245. $result['list']=$list;
  246. exit(json_encode($result));
  247. }
  248. public function actionGetclass()
  249. {
  250. $grade = Req::post("grade");
  251. $class_array = array();
  252. $class_data=array();
  253. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1',array(':grade' => $grade,':semester_id'=>$this->semesterId));
  254. if($class_data){
  255. foreach($class_data as $v )
  256. {
  257. $class_array[] = $v->attributes;
  258. }
  259. echo json_encode(array('status'=>1,'result'=>$class_array,'subject_name'=>Yii::app()->params['subjectId'][$this->subjectId]));exit;
  260. }
  261. echo json_encode(array('status'=>0,'result'=>array()));exit;
  262. }
  263. public function actionSaveSetting(){
  264. $grade=Req::post('grade');
  265. $classIds=Req::post('classIds');
  266. $examGroupIds=Req::post('examGroupIds');
  267. $answerParse=Req::post('answerParse');
  268. $name=Req::post('name');
  269. $startDate=Req::post('startDate');
  270. $endDate=Req::post('endDate');
  271. $gpGroupId=Req::post('gpGroupId');
  272. $result['status']=0;
  273. $result['msg']='';
  274. $error=array();
  275. if(!$classIds ){
  276. $error[]='班级参数异常';
  277. }
  278. if(!$examGroupIds ){
  279. $error[]='考试参数异常';
  280. }
  281. if(!$name){
  282. $error[]='名称参数异常';
  283. }
  284. if(!$answerParse){
  285. $error[]='答案解析参数异常';
  286. }
  287. if($error){
  288. $result['msg']=implode(',',$error);
  289. exit(json_encode($result));
  290. }
  291. $classIds=explode(',',$classIds);
  292. $examGroupIds=explode(',',$examGroupIds);
  293. $setting=array(
  294. 'class_ids'=>$classIds,
  295. 'exam_group_ids'=>$examGroupIds,
  296. 'answer_parse'=>$answerParse,
  297. 'name'=>$name,
  298. 'grade'=>$grade,
  299. 'start_date'=>$startDate,
  300. 'end_date'=>$endDate
  301. );
  302. $examRelationStudent=$this->getAllStudentByExamId($examGroupIds);
  303. if(!$examRelationStudent){
  304. $result['msg']='考试数据异常';
  305. exit(json_encode($result));
  306. }
  307. $time = time();
  308. $transaction = $this->sConn->beginTransaction();
  309. try {
  310. if($gpGroupId){
  311. //修改
  312. $gpList= $this->sConn->createCommand("select gp_id from general_product where gp_group_id='{$gpGroupId}'")->queryAll();
  313. $gpIds=array();
  314. if($gpList){
  315. foreach ($gpList as $item){
  316. $gpIds[]=$item['gp_id'];
  317. }
  318. }
  319. $this->sConn->createCommand("delete from general_product where gp_group_id='{$gpGroupId}'")->execute();
  320. $this->sConn->createCommand("delete from general_product_student where gp_id in(".implode(',',$gpIds).")")->execute();
  321. $groupId=$gpGroupId;
  322. }else{
  323. $groupId = getUniqueId($this->schoolId);
  324. }
  325. $gpIds = array();
  326. $noExamClass=array(); //未参加任何考试的班级
  327. foreach ($classIds as $classId) {
  328. $classJoinExam=array();
  329. //获取班级学生
  330. $classStudent = $this->getStudentIdsByClassId($classId);
  331. //查询学生参与的考试id
  332. foreach ($examRelationStudent as $examId => $studentIds){
  333. if(array_intersect($classStudent,$studentIds)){
  334. $classJoinExam[]=$examId;
  335. }
  336. }
  337. $extra=array();
  338. if(!$classJoinExam){
  339. $noExamClass[]=$classId;
  340. }else{
  341. $extra['exam_ids']=$classJoinExam;
  342. }
  343. $gpId = getUniqueId($this->schoolId);
  344. $this->sConn->createCommand()->insert('general_product', array(
  345. 'gp_id' => $gpId,
  346. 'gp_group_id' => $groupId,
  347. 'class_id' => $classId,
  348. 'grade' => $grade,
  349. 'name' =>$name,
  350. 'subject_id' => $this->subjectId,
  351. 'semester_id' => $this->semesterId,
  352. 'create_time' => $time,
  353. 'update_time' => $time,
  354. 'extra'=>!empty($extra)?jsonEncode($extra):''
  355. ));
  356. foreach ($classStudent as $kk => $vv) {
  357. $this->sConn->createCommand()->insert('general_product_student', array(
  358. 'gp_id' => $gpId,
  359. 'student_id' => $vv,
  360. ));
  361. }
  362. array_push($gpIds, $gpId);
  363. }
  364. $status=1;
  365. if($noExamClass){
  366. $setting['no_exam_class']=$noExamClass;
  367. $status=5;
  368. }
  369. if($gpGroupId){
  370. $this->sConn->createCommand("update general_product_setting set setting='".jsonEncode($setting)."',update_time='{$time}',status='{$status}' where gp_group_id='{$gpGroupId}'")->execute();
  371. }else{
  372. $this->sConn->createCommand()->insert('general_product_setting', array(
  373. 'gp_group_id' => $groupId,
  374. 'grade' => $grade,
  375. 'product_type' => 66,
  376. 'subject_id' => $this->subjectId,
  377. 'semester_id' => $this->semesterId,
  378. 'setting' => jsonEncode($setting),
  379. 'create_time' => $time,
  380. 'update_time' => $time,
  381. 'status'=>$status,
  382. ));
  383. }
  384. //写入数据预处理表
  385. // $this->conn->createCommand()->insert('xb_data_handle', array(
  386. // 'gp_group_id' => $groupId,
  387. // 'school_id' => $this->schoolId,
  388. // 'class_ids' => explode(',',$classIds),
  389. // 'exam_group_ids' => explode(',',$examGroupIds),
  390. // 'create_time' => $time,
  391. // 'update_time' => $time,
  392. // ));
  393. $transaction->commit();
  394. if(!$noExamClass){
  395. $kafkaData = array(
  396. 'school_id' => $this->schoolId,
  397. 'msg_type' => 1,//90:重置 1:新设置
  398. 'subject_id' => $this->subjectId,
  399. 'send_type' => 'error_correct',
  400. 'product_type' => 66,
  401. 'gp_group_id' => $groupId,
  402. 'gp_ids' => $gpIds,
  403. 'student_ids'=>array(),
  404. );
  405. sendDataToKafka("xbkc-php-product-html", $kafkaData);
  406. }
  407. $result['status']=1;
  408. $result['msg']='设置成功';
  409. } catch (Exception $e) {
  410. $transaction->rollBack();
  411. if (YII_ENV == 'production') {
  412. $result['msg'] = '系统错误[SQL]';
  413. } else {
  414. $result['msg'] = $e->getMessage();
  415. }
  416. }
  417. exit(json_encode($result));
  418. }
  419. //编辑设置
  420. public function actionGetDetail(){
  421. $gpGroupId=Req::post('gpGroupId');
  422. $result['status']=0;
  423. $result['msg']='';
  424. $error=array();
  425. if(!$gpGroupId){
  426. $error[]='参数异常';
  427. }
  428. $model = new SGeneralProductSetting();
  429. $setting=$model->getGeneralSetting($gpGroupId);
  430. if($setting){
  431. $result['status']=1;
  432. $jsonData=json_decode($setting,true);
  433. $data=array(
  434. 'classIds'=>$jsonData['class_ids'],
  435. 'examGroupIds'=>$jsonData['exam_group_ids'],
  436. 'answerParse'=>$jsonData['answer_parse'],
  437. 'name'=>$jsonData['name'],
  438. 'grade'=>$jsonData['grade'],
  439. 'startDate'=>$jsonData['start_date'],
  440. 'endDate'=>$jsonData['end_date'],
  441. );
  442. $result['data']=$data;
  443. }else{
  444. $result['msg']='读取设置信息失败';
  445. }
  446. exit(json_encode($result));
  447. }
  448. //查询所有参加学生
  449. private function getAllStudentByExamId($examGroupIds){
  450. $studentRelationExamId=array();
  451. foreach ($examGroupIds as $examGroupId){
  452. $examIds=$this->getExamIds($examGroupId);
  453. if(!$examIds){
  454. return null;
  455. }
  456. $sql="select student_id,exam_id from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_del=0 and is_feedback=1";
  457. $result = $this->sConn->createCommand($sql)->queryAll();
  458. if($result){
  459. foreach ($result as $item){
  460. $studentRelationExamId[(string)$item['exam_id']][]=$item['student_id'];
  461. }
  462. }
  463. }
  464. return $studentRelationExamId;
  465. }
  466. //读取考试id
  467. private function getExamIds($examGroupId){
  468. $sql="select exam_id from exam where exam_group_id='{$examGroupId}'";
  469. $result = $this->sConn->createCommand($sql)->queryAll();
  470. $examIds=array();
  471. if($result){
  472. foreach ($result as $item){
  473. $examIds[]=$item['exam_id'];
  474. }
  475. }
  476. return $examIds;
  477. }
  478. //读取班级学生
  479. private function getStudentIdsByClassId($classId){
  480. $sql="select student_id from student_class_relation where class_id='{$classId}' and status=0";
  481. $result = $this->sConn->createCommand($sql)->queryAll();
  482. $studentIds=array();
  483. if($result){
  484. foreach ($result as $item){
  485. $studentIds[]=$item['student_id'];
  486. }
  487. }
  488. return $studentIds;
  489. }
  490. //继续生成,删除未参加考试班级
  491. public function actionProceed(){
  492. $gpGroupId=Req::post('gpGroupId');
  493. $result['status']=0;
  494. $result['msg']='';
  495. $error=array();
  496. if(!$gpGroupId){
  497. $result['msg']='参数异常';
  498. exit(json_encode($result));
  499. }
  500. $sql="select setting from general_product_setting where gp_group_id='{$gpGroupId}' ";
  501. $setting = $this->sConn->createCommand($sql)->queryRow();
  502. if(!$setting){
  503. $result['msg']='参数异常';
  504. exit(json_encode($result));
  505. }
  506. $settingJson=json_decode($setting['setting'],true);
  507. if(isset($settingJson['no_exam_class']) && $settingJson['no_exam_class']){
  508. if(count($settingJson['no_exam_class'])==count($settingJson['class_ids'])){
  509. $result['msg']='没有符合生成条件的班级不能继续生成';
  510. exit(json_encode($result));
  511. }
  512. $transaction = $this->sConn->beginTransaction();
  513. try {
  514. $gpIds=array();
  515. $allGp=$this->sConn->createCommand("select gp_id from general_product where gp_group_id='{$gpGroupId}' and class_id in(".implode(',',$settingJson['no_exam_class']).")")->queryAll();
  516. if($allGp){
  517. foreach ($allGp as $item){
  518. $gpIds[]=$item['gp_id'];
  519. }
  520. }else{
  521. $result['msg']='没有符合生成条件的班级不能继续生成';
  522. exit(json_encode($result));
  523. }
  524. $deleteClassSql="delete from general_product where gp_id in(".implode(',',$gpIds).")";
  525. $deleteStudentSql="delete from general_product_student where gp_id in(".implode(',',$gpIds).")";
  526. $this->sConn->createCommand($deleteClassSql)->execute();
  527. $this->sConn->createCommand($deleteStudentSql)->execute();
  528. $this->sConn->createCommand("update general_product_setting set status=1 where gp_group_id='{$gpGroupId}' ")->execute();
  529. $restGpIds=array();
  530. $allGp=$this->sConn->createCommand("select gp_id from general_product where gp_group_id='{$gpGroupId}' and class_id not in(".implode(',',$settingJson['no_exam_class']).")")->queryAll();
  531. foreach ($allGp as $item){
  532. $restGpIds[]=$item['gp_id'];
  533. }
  534. $transaction->commit();
  535. $result['status']=1;
  536. $kafkaData = array(
  537. 'school_id' => $this->schoolId,
  538. 'msg_type' => 1,//90:重置 1:新设置
  539. 'subject_id' => $this->subjectId,
  540. 'send_type' => 'error_correct',
  541. 'product_type' => 66,
  542. 'gp_group_id' => $gpGroupId,
  543. 'gp_ids' => $restGpIds,
  544. 'student_ids'=>array(),
  545. );
  546. sendDataToKafka("xbkc-php-product-html", $kafkaData);
  547. } catch (Exception $e) {
  548. $transaction->rollBack();
  549. if (YII_ENV == 'production') {
  550. $error[] = '系统错误[SQL]';
  551. } else {
  552. $error[] = $e->getMessage();
  553. }
  554. $result['msg']=implode(',',$error);
  555. }
  556. }else{
  557. $result['msg']='班级设置数据异常,未参与考试班级数据为空';
  558. }
  559. exit(json_encode($result));
  560. }
  561. //班级重置页面
  562. public function actionResetClass()
  563. {
  564. $groupId = Req::get('gp_group_id');
  565. $name = Req::get('name');
  566. if (empty($groupId) || empty($name)) {
  567. Yii::app()->jump->error('参数异常');
  568. }
  569. $newCondition[] = 'g.gp_group_id=' . $groupId;
  570. $model = new SGeneralProductSetting();
  571. $rs = $model->getList($newCondition, array('g.create_time desc'), 100);
  572. if (!isset($rs['rs'])) {
  573. Yii::app()->jump->error('获取班级数据失败');
  574. }
  575. $resetTotal=3;//学管重置总次数
  576. foreach($rs['rs'] as $key=>$item){
  577. //学管剩余重置次数
  578. $item['learn_tube_reset_residue_count']=$resetTotal>$item['learn_tube_reset_count']?$resetTotal-$item['learn_tube_reset_count']:0;
  579. //学管30分钟内只能重置一次
  580. $item['is_cool_down']=time()-$item['learn_tube_reset_time']<=1800?0:1;
  581. //冷却文字提示 30分钟内并且剩余次数大于0
  582. $item['is_cool_down_prompt']=!$item['is_cool_down'] && $item['learn_tube_reset_residue_count']?true:false;
  583. $rs['rs'][$key]=$item;
  584. }
  585. //是不是技术支持
  586. $isTechnicalSupport=1;
  587. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
  588. $isTechnicalSupport=0;
  589. }
  590. $data['resultList'] = $rs['rs'];
  591. $data['productName'] = $name;
  592. $data['currentWeek'] = date('W');
  593. $data['is_technical_support']=$isTechnicalSupport;
  594. $this->render('reset', $data);
  595. }
  596. //重置操作
  597. public function actionReset()
  598. {
  599. $gpIds = Req::post('classExam');
  600. if (!$gpIds || !is_array($gpIds)) {
  601. echo json_encode(array("status" => 0, "message" => "参数错误!"));
  602. exit;
  603. }
  604. $transaction = $this->sConn->beginTransaction();
  605. try {
  606. $gpIdsStr=implode(',',$gpIds);
  607. $sql="select gp_id,reset_times,learn_tube_reset_count from general_product where gp_id in ({$gpIdsStr})";
  608. $generalProducts=$this->sConn->createCommand($sql)->queryAll();
  609. $learnTubeResetCounts=_array_column($generalProducts,'learn_tube_reset_count','gp_id');
  610. foreach ($gpIds as $gpId) {
  611. $this->sConn->createCommand()->update("general_product_student", array(
  612. 'is_create_html' => 90,
  613. 'is_create_pdf' => 90,
  614. 'is_download' => 0,
  615. 'pdf_page_num' => 0,
  616. 'pdf_sheet_num' => 0,), "gp_id = '{$gpId}'");
  617. if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ) {
  618. if(!isset($learnTubeResetCounts[$gpId])){
  619. continue;
  620. }
  621. $learnTubeResetCount=$learnTubeResetCounts[$gpId]+1;
  622. $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}'");
  623. }else{
  624. $this->sConn->createCommand()->update("general_product", array('reset_times' => new CDbExpression('reset_times+1')), "gp_id = '{$gpId}'");
  625. }
  626. }
  627. //发送消息
  628. $groupModel = SGeneralProduct::model()->find('gp_id=:gp_id',array('gp_id'=>$gpIds[0]));
  629. if(!$groupModel){
  630. echo json_encode(array("status" => 0, "message" => "数据异常!"));
  631. exit;
  632. }
  633. // setting更新补提信息
  634. $this->sConn->createCommand()->update("general_product_setting", array('status' =>1), "gp_group_id = '{$groupModel['gp_group_id']}'");
  635. $sendMsg=array(
  636. 'school_id'=>$this->schoolId,
  637. 'msg_type'=>90,
  638. 'subject_id'=>$this->subjectId,
  639. 'send_type'=>'error_correct',
  640. 'product_type'=>66,
  641. 'gp_group_id'=>$groupModel['gp_group_id'],
  642. 'gp_ids'=>$gpIds
  643. );
  644. $transaction->commit();
  645. sendDataToKafka('xbkc-php-product-html',$sendMsg);
  646. } catch (\Exception $e) {
  647. $transaction->rollBack();
  648. echo json_encode(array('status' => 0, 'message' => $e->getMessage()));
  649. exit;
  650. }
  651. echo json_encode(array('status' => 1));
  652. exit;
  653. }
  654. }