123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- <?php
- /**
- *
- * 专题宝
- *
- */
- class GeneralproductController extends Controller
- {
- /**
- * 假期作业产品表
- */
- public function actionIndex()
- {
- Url::clean();
- $data = array();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $grade = Req::get("grade");
- $productType = (int)Req::get("productType")?(int)Req::get("productType"):ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK;//产品类型
- $newCondition=array(
- 'g.product_type=' . $productType,
- 'g.subject_id=' . $this->subjectId,
- );
- if ($grade) {
- $newCondition[] = 'p.grade='.$grade;
- }
- if ($printName) {
- $newCondition[] = 'p.name like "%' . $printName . '%"';
- }
- if ($classId) {
- $newCondition[] = 'p.class_id=' . $classId;
- }
- $generalProductSttingModel = new SGeneralProductSetting();
- $resultList = $generalProductSttingModel->getList($newCondition, array('p.create_time desc'), 9);
- $printList = array();
- if ($resultList["rs"]) {
- foreach ($resultList['rs'] as $k => $v) {
- $printList[$k] = $v;
- $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']));
- }
- }
- $isSetting=false;
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
- $months=array(11,12,1,4,5,6,7);
- $currentMonth=(int)date('m',time());
- if(in_array($currentMonth,$months)){
- $isSetting=true;
- }
- }else{
- $isSetting=true;
- }
- if(in_array($productType,array(ProductDownload::PRODUCT_TYPE_WRONG_REFINE))){
- $isSetting = true;
- }
- $productDesc = ProductDownload::$desc;
- $productName = isset($productDesc[$productType]) ? $productDesc[$productType]: "";
- $classes = $this->schoolManager->getClasses($grade);
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data['printList'] = $printList;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data['printType'] = 'special';
- $data['subjectId'] = $this->subjectId;
- $data['productType'] = $productType;
- $data['productName']=$productName;//产品名称
- $data['isSetting']=$isSetting;//假期作业入口
- //debug($data['productName']);exit;
- $this->render('index', $data);
- }
- /**
- * 学生列表
- */
- public function actionStu()
- {
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $gpId = (string)Req::get("gp_id");
- $type = (int)Req::get("type");
- if (!$gpId || !$type) {
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及产品名称
- $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}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if (empty($names)) {
- Yii::app()->jump->error('数据错误!');
- }
- $data['name'] = isset($names['name']) && isset($names['class_name']) ? $names['class_name'] . $names['name'] : '';
- $sql = "select student_id,is_create_pdf from general_product_student where gp_id = '{$gpId}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if ($relateStudent) {
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_create_pdf'];
- }
- }
- if ($studentIds) {
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- if ($studentNames) {
- if ($sname) {
- $i = 1;
- foreach ($studentNames as $k => $v) {
- if (strpos($v, $sname) !== false) {
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
- $i++;
- }
- }
- } else {
- $i = 1;
- foreach ($studentNames as $k => $v) {
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
- $i++;
- }
- }
- }
- }
- $Sem = new SSemester();
- $code = $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '" . $names['semester_id'] . "'")
- ->limit(1)
- ->query()
- ->read();
- $intarr = array(
- "schoolId" => $this->schoolId,
- "clazzId" => $names['class_id'],
- "semester" => $code['refer_code'],
- "grade" => $names['grade'],
- "students" => $studentIds,
- "examTime" => $names['create_time'],
- "classify" => $type,
- "subject" => $this->subjectId
- );
- $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
- if (!$rs) {
- Yii::app()->jump->error("接口错误");
- }
- if ($rs->errCode != "00") {
- Yii::app()->jump->error($rs->errMsg);
- }
- if (!empty($rs->data)) {
- $data['limitstu'] = $rs->data;
- }
- $productDesc = ProductDownload::$desc;
- $productName = isset($productDesc[$type]) ? $productDesc[$type]: "";
- $data['gp_id'] = $gpId;
- $data['class_id'] = $names['class_id'];
- $data['sname'] = $sname;
- $data['type'] = $type;
- $data['productName'] = $productName;
- $data['printType'] = 'general_product';
- $this->render('stu', $data);
- }
- /**
- * 设置
- */
- public function actionSetting()
- {
- $productType = (int)Req::get("productType")?(int)Req::get("productType"):ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK;//产品类型
- $productDesc = ProductDownload::$desc;
- $productName = isset($productDesc[$productType]) ? $productDesc[$productType]: "";
- $semesterModel=new Semester();
- $semesterName=$semesterModel->getSemesterName($this->semesterId);
- $data=array(
- 'productName'=>$productName,
- 'semesterName'=>$semesterName,
- 'productType'=>$productType,
- );
- if($productType==ProductDownload::PRODUCT_TYPE_WRONG_REFINE) {
- $this->render('setting_homework2',$data);
- }
- if($productType==ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK) {
- $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$this->schoolId));
- $type=1;//默认新高考
- if(isset($schoolInfo['province_id']) && in_array($this->subjectId, array(8))){
- $provinceGradeIsnewResult=$this->apiPost('all_content/provinceGradeIsnew',array('subjectId'=>array($this->subjectId),'provinceId'=>$schoolInfo['province_id'],'grade'=>1));
- if(isset($provinceGradeIsnewResult['status']) && $provinceGradeIsnewResult['status'] && isset($provinceGradeIsnewResult['data'][0]['is_new'])){
- $type=$provinceGradeIsnewResult['data'][0]['is_new'];
- }
- }
- $data['type']=$type;
- if (in_array($this->subjectId, array(8))) { //英语
- $this->render('setting_homework',$data);
- } elseif (in_array($this->subjectId, array(3, 6, 51, 12))) {//物理
- $this->render('setting_homework2',$data);
- }
- }
- }
- /**
- * 假期作业设置
- */
- private function getHolidayHomeworkSetting($settingJson){
- $setting=array();
- if (in_array($this->subjectId, array(8))) { //英语
- if(!isset($settingJson['scoringRate']) || !isset($settingJson['examType']) || !isset($settingJson['layeredTraining']) || !isset($settingJson['isAnswerMerge'])){
- exit(json_encode(array('status' => 0, 'error' => '请检查参数')));
- }
- $scoringRate=$settingJson['scoringRate'];
- $examType=$settingJson['examType'];
- $layered=$settingJson['layeredTraining'];
- $isAnswerMerge=$settingJson['isAnswerMerge'];
- if(!in_array($scoringRate,array('A','B','C')) || !in_array($examType,array(1,2)) || !in_array($isAnswerMerge,array(0,1))){
- exit(json_encode(array('status' => 0, 'error' =>'参数不在范围内')));
- }
- $reg="/^[0-9]*$/";
- if(!isset($layered['hearing']) || !isset($layered['readingComprehension']) || !isset($layered['sevenChooseFive']) || !isset($layered['completionFillIn'])|| !isset($layered['grammaticalFillIn']) || !isset($layered['practicalWriting'])
- || ($examType==1 && !isset($layered['readingPriorWritten'])) || ($examType==2 && !isset($layered['passagesChangeWrong'])) ){
- exit(json_encode(array('status' => 0, 'error' => '请检查分层训练参数')));
- }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'])
- || !preg_match($reg, $layered['practicalWriting']) || ($examType==1 && !preg_match($reg, $layered['readingPriorWritten'])) || ($examType==2 && !preg_match($reg, $layered['passagesChangeWrong']))){
- exit(json_encode(array('status' => 0, 'error' =>'分层训练数量是等于0或者大于0的整数')));
- }
- $hearing=intval($layered['hearing']);
- $readingComprehension=intval($layered['readingComprehension']);
- $sevenChooseFive=intval($layered['sevenChooseFive']);
- $completionFillIn=intval($layered['completionFillIn']);
- $grammaticalFillIn=intval($layered['grammaticalFillIn']);
- $practicalWriting=intval($layered['practicalWriting']);
- $readingPriorWritten=$examType==1 && isset($layered['readingPriorWritten'])?intval($layered['readingPriorWritten']):0;
- $passagesChangeWrong=$examType==2 && isset($layered['passagesChangeWrong'])?intval($layered['passagesChangeWrong']):0;
- if(($hearing<0 || $hearing>1) || ($readingComprehension<0 || $readingComprehension>8) || ($sevenChooseFive<0 || $sevenChooseFive>3) || ($completionFillIn<0 || $completionFillIn>3) ||
- ($grammaticalFillIn<0 || $grammaticalFillIn>5) || ($practicalWriting<0 || $practicalWriting>1) ||
- ($examType==1 && ($readingPriorWritten<0 || $readingPriorWritten>1) ) || ($examType==2 && ($passagesChangeWrong<0 || $passagesChangeWrong>5))
- ){
- exit(json_encode(array('status' => 0, 'error' =>'请检查分层训练参数是否在限制范围内')));
- }
- $totalCount=$hearing+$readingComprehension+$sevenChooseFive+$completionFillIn+$grammaticalFillIn+$practicalWriting+$readingPriorWritten+$passagesChangeWrong;
- if($totalCount<3){
- exit(json_encode(array('status' => 0, 'error' => '分层训练题数不少于3个')));
- }
- //分层训练
- $layeredTraining=array(
- 'hearing'=>$hearing,
- 'reading_comprehension'=>$readingComprehension,
- 'seven_choose_five'=>$sevenChooseFive,
- 'completion_fill_in'=>$completionFillIn,
- 'grammatical_fill_in'=>$grammaticalFillIn,
- 'practical_writing'=>$practicalWriting,
- );
- if($examType==1){
- $layeredTraining['reading_prior_written']=$readingPriorWritten;
- }else{
- $layeredTraining['passages_change_wrong']=$passagesChangeWrong;
- }
- $setting=array(
- 'product_type'=>ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK,
- 'scoring_rate'=>$scoringRate,
- 'exam_type'=>$examType,
- 'layered_training'=>$layeredTraining,
- 'is_answer_merge'=>$isAnswerMerge?true:false,
- );
- } elseif (in_array($this->subjectId, array(3, 6, 51, 12))) {//数学,物理
- if(!isset($settingJson['scoringRate']) || !isset($settingJson['isAnswerMerge'])){
- exit(json_encode(array('status' => 0, 'error' => '请检查参数')));
- }
- $scoringRate=$settingJson['scoringRate'];
- $isAnswerMerge=$settingJson['isAnswerMerge'];
- if(!in_array($scoringRate,array('A','B','C')) || !in_array($isAnswerMerge,array(0,1))){
- exit(json_encode(array('status' => 0, 'error' => '参数不在范围内')));
- }
- $setting=array(
- 'product_type'=>ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK,
- 'scoring_rate'=>$scoringRate,
- 'is_answer_merge'=>$isAnswerMerge?true:false,
- );
- }
- return $setting;
- }
- /**
- * 假期作业校验成绩
- * @param $classIds
- */
- private function holidayHomeworkCheckScore($classIds,$subjectIds){
- if(in_array($subjectIds,array(3,6,51))){
- $subjectIds=array(3,6,51);
- }else{
- $subjectIds=array($subjectIds);
- }
- $subjectIds=implode(',',$subjectIds);
- $classIdsStr=implode(',',$classIds);
- $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";
- $examInfo = $this->sConn->createCommand($sql)->queryAll();
- $examClassIds=_array_column($examInfo,'class_id');
- if(count($classIds)!=count($examClassIds)){
- $diff=array_diff($classIds,$examClassIds);
- $diffClassIdsStr=implode(',',$diff);
- $sql="select class_id,class_name from class where class_id in ({$diffClassIdsStr})";
- $classInfo=$this->sConn->createCommand($sql)->queryAll();
- if(!$classInfo){
- exit(json_encode(array('status' => 0, 'error' => '请刷新后再试!')));
- }
- $classNames=implode(',',_array_column($classInfo,'class_name'));
- $msg="{$classNames},班级无考试数据!<br/>无考试数据的班级,可以至试卷管理中导入一场考试数据";
- exit(json_encode(array('status' => 0, 'error' =>$msg)));
- }
- }
- /**
- * 生成设置保存
- */
- public function actionAjaxSaveSetting()
- {
- $error = array();
- if (!Yii::app()->request->isAjaxRequest OR !Yii::app()->request->isPostRequest) {
- $error[] = '错误的来源!';
- } else {
- $grade = (int)Req::post('grade');
- $textbook = (int)Req::post('textbook');
- $classIds = (array)Req::post('selectClassIds');
- $productType = (int)Req::post('productType');
- $settingJson = Req::post('settingJson');
- $settingJson = str_replace('"', '"', $settingJson);
- $productTypeArr=array(
- ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK,
- ProductDownload::PRODUCT_TYPE_WRONG_REFINE
- );
- if(!in_array($productType,$productTypeArr)){
- exit(json_encode(array('status' => 0, 'error' => '请检查产品类型参数')));
- }
- if (!json_decode($settingJson, true)) {
- exit(json_encode(array('status' => 0, 'error' => '设置内容错误')));
- }
- $textbookArr=array(
- 1=>'第一册',2=>'第二册',3=>'第三册',4=>'第四册',5=>'第五册',6=>'第六册',
- );
- $settingJson=json_decode($settingJson, true);
- $setting=array();
- if($productType==ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK){
- $topic_name = 'php-product-holiday-work-html';
- $send_type = 'holiday_work';
- $semesterModel=new Semester();
- $name=$semesterModel->getSemesterName($this->semesterId);
- $name.='"假期作业"';
- $this->holidayHomeworkCheckScore($classIds,$this->subjectId);//假期作业校验成绩
- $setting=$this->getHolidayHomeworkSetting($settingJson);
- }else if($productType==ProductDownload::PRODUCT_TYPE_WRONG_REFINE){
- $topic_name = 'php-product-wrong-topic-refining';
- $send_type = 'wrong_topic_refining';
- $semesterModel=new Semester();
- $name=$semesterModel->getSemesterName($this->semesterId);
- $name.='"错题精练"';
- if($textbook && isset($textbookArr[$textbook])){
- $name.=$textbookArr[$textbook];
- }
- $this->holidayHomeworkCheckScore($classIds,$this->subjectId);//假期作业校验成绩
- //订单校验
- // $strModel = new SStudentClassRelation();
- // $intArr=array();
- // foreach ($classIds as $id){
- // $stuData = $strModel->getRelationsByClassId_Status_0($id);
- // if($stuData){
- // $studentIds=array();
- // foreach ($stuData as $datum){
- // $studentIds[]=$datum['student_id'];
- // }
- // $intArr[]=array(
- // "schoolId"=>$this->schoolId,
- // "clazzId"=>$id,
- // "semester"=>$this->semesterId,
- // "grade"=>$grade,
- // "students"=>$studentIds,
- // "examTime"=>time(),
- // "classify"=>$productType,
- // "subject"=>$this->subjectId
- // );
- //
- // }
- // }
- // $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- // $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intArr),$basic));
- //
- //
- // if(!$rs){
- // exit(json_encode(array('status' => 0, 'error' => '查询订单接口有误')));
- // }
- // if(empty($rs->data)){
- // $classInfo=ClassModel::model()->find($id);
- // exit(json_encode(array('status' => 0, 'error' => $classInfo->class_name.'班级无人开通订单')));
- // }
- $setting['product_type'] = ProductDownload::PRODUCT_TYPE_WRONG_REFINE;
- $setting['is_answer_merge'] = isset($settingJson['isAnswerMerge']) && $settingJson['isAnswerMerge']?true:false;
- }
- //次数限制
- if(!$setting){
- exit(json_encode(array('status' => 0, 'error' => '无生成配置数据')));
- }
- $time = time();
- $transaction = $this->sConn->beginTransaction();
- try {
- $groupId = getUniqueId($this->schoolId);
- $strModel = new SStudentClassRelation();
- $this->sConn->createCommand()->insert('general_product_setting', array(
- 'gp_group_id' => $groupId,
- 'grade' => $grade,
- 'textbook'=>$textbook,
- 'product_type' => $productType,
- 'subject_id' => $this->subjectId,
- 'semester_id' => $this->semesterId,
- 'setting' => json_encode($setting, true),
- 'create_time' => $time,
- 'update_time' => $time,
- ));
- $gpIds = array();
- foreach ($classIds as $classId) {
- $gpId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('general_product', array(
- 'gp_id' => $gpId,
- 'gp_group_id' => $groupId,
- 'class_id' => $classId,
- 'grade' => $grade,
- 'name' =>$name,
- 'subject_id' => $this->subjectId,
- 'semester_id' => $this->semesterId,
- 'create_time' => $time,
- 'update_time' => $time,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($classId);
- foreach ($stuData as $kk => $vv) {
- $this->sConn->createCommand()->insert('general_product_student', array(
- 'gp_id' => $gpId,
- 'student_id' => $vv['student_id'],
- ));
- }
- array_push($gpIds, $gpId);
- }
- // $sendMsg=array(
- // 'school_id'=>$this->schoolId,
- // 'msg_type'=>1,
- // 'subject_id'=>$this->subjectId,
- // 'send_type'=>'holiday_work',
- // 'product_type'=>$productType,
- // 'gp_group_id'=>$groupId,
- // 'gp_ids'=>$gpIds
- // );
- $transaction->commit();
- // sendDataToKafka('php-product-holiday-work-html',$sendMsg);
- } catch (Exception $e) {
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- }
- if ($error) {
- echo json_encode(array('status' => 0, 'error' => $error));
- exit;
- } else {
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>1,
- 'subject_id'=>$this->subjectId,
- 'send_type'=>$send_type,
- 'product_type'=>$productType,
- 'gp_group_id'=>$groupId,
- 'gp_ids'=>$gpIds
- );
- sendDataToKafka($topic_name,$sendMsg);
- echo json_encode(array('status' => 1));
- exit;
- }
- }
- //产品班级
- public function actionAjaxGetClasses()
- {
- $result = array();
- $grade = (int)Req::post('grade');
- $productType = (int)Req::post('productType');
- $textbook = (int)Req::post('textbook');
- if ($grade && $productType) {
- $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if ($data) {
- $classIds=array();
- foreach ($data as $k => $v) {
- $classIds[]=$v['class_id'];
- }
- if($classIds){
- $classIds=implode(',',$classIds);
- if($textbook){
- $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";
- }else{
- $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";
- }
- $classProduct = $this->sConn->createCommand($sql)->queryAll();
- foreach($classProduct as $key=>$item){
- $classProduct[$item['class_id']]=$item['count'];
- unset($classProduct[$key]);
- }
- foreach($data as $item){
- if($productType == ProductDownload::PRODUCT_TYPE_WRONG_REFINE){
- $item['status']=isset($classProduct[$item['class_id']]) && $classProduct[$item['class_id']] > 2 ?1:0;
- }else{
- $item['status']=isset($classProduct[$item['class_id']])?$classProduct[$item['class_id']]:0;
- }
- $result[]=$item;
- }
- }
- }
- }
- echo json_encode($result);
- exit;
- }
- //重置页面
- public function actionClasses()
- {
- $groupId = Req::get('gp_group_id');
- $name = stripslashes(Req::get('name'));
- $productType = Req::get('productType');
- if (empty($groupId) || empty($name)) {
- Yii::app()->jump->error('参数异常');
- }
- $newCondition[] = 'g.gp_group_id=' . $groupId;
- $model = new SGeneralProductSetting();
- $rs = $model->getList($newCondition, array('g.create_time desc'), 100);
- if (!isset($rs['rs'])) {
- Yii::app()->jump->error('获取班级数据失败');
- }
- $resetTotal=3;//学管重置总次数
- foreach($rs['rs'] as $key=>$item){
- //学管剩余重置次数
- $item['learn_tube_reset_residue_count']=$resetTotal>$item['learn_tube_reset_count']?$resetTotal-$item['learn_tube_reset_count']:0;
- //学管30分钟内只能重置一次
- $item['is_cool_down']=time()-$item['learn_tube_reset_time']<=1800?0:1;
- //冷却文字提示 30分钟内并且剩余次数大于0
- $item['is_cool_down_prompt']=!$item['is_cool_down'] && $item['learn_tube_reset_residue_count']?true:false;
- $rs['rs'][$key]=$item;
- }
- //是不是技术支持
- $isTechnicalSupport=1;
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
- $isTechnicalSupport=0;
- }
- $productDesc = ProductDownload::$desc;
- $productName = isset($productDesc[$productType]) ? $productDesc[$productType]: "";
- $data['resultList'] = $rs['rs'];
- $data['name'] = $name;
- $data['productName'] = $productName;
- $data['currentWeek'] = date('W');
- $data['is_technical_support']=$isTechnicalSupport;
- //debug($data);exit;
- $this->render('reset', $data);
- }
- //重置操作
- public function actionReset()
- {
- $gpIds = Req::post('classExam');
- if (!$gpIds || !is_array($gpIds)) {
- echo json_encode(array("status" => 0, "message" => "参数错误!"));
- exit;
- }
- $sendStatus = 1;
- $tempProductType = 0;
- $transaction = $this->sConn->beginTransaction();
- try {
- $gpIdsStr=implode(',',$gpIds);
- $sql="select gp_id,reset_times,learn_tube_reset_count from general_product where gp_id in ({$gpIdsStr})";
- $generalProducts=$this->sConn->createCommand($sql)->queryAll();
- $learnTubeResetCounts=_array_column($generalProducts,'learn_tube_reset_count','gp_id');
-
- foreach ($gpIds as $gpId) {
- $this->sConn->createCommand()->update("general_product_student", array(
- 'is_create_html' => 90,
- 'is_create_pdf' => 90,
- 'is_download' => 0,
- 'pdf_page_num' => 0,
- 'pdf_sheet_num' => 0,), "gp_id = '{$gpId}'");
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1) {
- if(!isset($learnTubeResetCounts[$gpId])){
- continue;
- }
- $learnTubeResetCount=$learnTubeResetCounts[$gpId]+1;
- $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}'");
- }else{
- $this->sConn->createCommand()->update("general_product", array('reset_times' => new CDbExpression('reset_times+1')), "gp_id = '{$gpId}'");
- }
- }
- //发送消息
- $groupModel = SGeneralProduct::model()->find('gp_id=:gp_id',array('gp_id'=>$gpIds[0]));
- if(!$groupModel){
- echo json_encode(array("status" => 0, "message" => "数据异常!"));
- exit;
- }
- if(!$tempProductType){
- $groupSettingModel = SGeneralProductSetting::model()->find('gp_group_id=:gp_group_id',array('gp_group_id'=>$groupModel['gp_group_id']));
- if(!$groupSettingModel){
- echo json_encode(array("status" => 0, "message" => "设置数据异常!"));
- exit;
- }else{
- $tempProductType = $groupSettingModel['product_type'];
- }
- }
- // setting更新补提信息
- $this->sConn->createCommand()->update("general_product_setting", array('status' =>1), "gp_group_id = '{$groupModel['gp_group_id']}'");
-
- if($tempProductType == ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK){
- $topicName = 'php-product-holiday-work-html';
- $sendType = 'holiday_work';
- }else if($tempProductType==ProductDownload::PRODUCT_TYPE_WRONG_REFINE){
- $topicName = 'php-product-wrong-topic-refining';
- $sendType = 'wrong_topic_refining';
- }else{
- $sendStatus = 0;
- }
-
- // $sendMsg=array(
- // 'school_id'=>$this->schoolId,
- // 'msg_type'=>90,
- // 'subject_id'=>$this->subjectId,
- // 'send_type'=>'holiday_work',
- // 'product_type'=>50,
- // 'gp_group_id'=>$groupModel['gp_group_id'],
- // 'gp_ids'=>$gpIds
- // );
- $transaction->commit();
- // sendDataToKafka('php-product-holiday-work-html',$sendMsg);
- } catch (\Exception $e) {
- $transaction->rollBack();
- echo json_encode(array('status' => 0, 'message' => $e->getMessage()));
- exit;
- }
- if($sendStatus && $tempProductType){
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>90,
- 'subject_id'=>$this->subjectId,
- 'send_type'=>$sendType,
- 'product_type'=>$tempProductType,
- 'gp_group_id'=>$groupModel['gp_group_id'],
- 'gp_ids'=>$gpIds
- );
- sendDataToKafka($topicName,$sendMsg);
- }
- echo json_encode(array('status' => 1));
- exit;
- }
- public function apiPost($path, $arr, $type = 0)
- {
- $ch = @curl_init();
- $result = FALSE;
- if ($ch) {
- $data = json_encode($arr);
- $url = Yii::app()->params['api'][$type]['prefix'] . $path;
- $username = Yii::app()->params['api'][$type]['username'];
- $password = Yii::app()->params['api'][$type]['password'];
- // Digest认证
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
- // 不输出头部
- curl_setopt($ch, CURLOPT_HEADER, 0);
- // curl_exec 获取到的内容不直接输出, 而是返回
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- // 请求重启路由器的地址 传参 进行重启
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data),
- ));
- if (!curl_errno($ch)) {
- $result = json_decode(curl_exec($ch),1);
- }
- // 释放资源
- curl_close($ch);
- }
- return $result;
- }
- }
|