schoolManager->getHtb($newCondition,array('htb.create_time desc','htb.htb_id desc')); $printList = array(); if($resultList["rs"]){ foreach ($resultList['rs'] as $k=>$v) { $printList[$k]=$v; } } if (empty($grade)) { $grade = 'ALL'; } $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; $this->render('index',$data); } //二轮复习个性化提分手册设置 public function actionSetting() { $data =array(); /*$result = $this->apiPost('/product/batch',array( 'productId' => 1, 'parentId' => 0 ));*/ $result = $this->apiPost('all_product/getCatalog',array('product_id' => 42,)); $data['topNode']= isset($result->data) ? $result->data : array(); $this->render('setting', $data); } //获取好题本子节点 public function actionAjaxChildNode() { $parentId = Req::get("parentId"); /*$data = $this->apiPost('/product/batch',array( 'productId' => 1, 'parentId' => $parentId ));*/ $data = $this->apiPost('all_product/getCatalogByParentId',array('parent_id' => $parentId)); if ($data->status!= 1 && !empty($data->error)) { echo json_encode(array("status" => 0, "message" => $data->error));exit(); } $data = !empty($data->data) ? $data->data : null; echo json_encode(array('status'=>1,'data'=>$data));exit; } //保存二轮复习个性化提分手册设置 public function actionAjaxSaveHtb(){ $result = array(); $error = array(); if (! Yii::app()->request->isAjaxRequest || ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $grade=(int)Req::post('grade'); $classIds = Req::post('selectClassIds'); $pcIds = (array)Req::post('pcIds'); $isAnswerMerge=(int)Req::post('isAnswerMerge'); $isNewVersion=(int)Req::post('isNewVersion'); if(!$grade){ $error[] = '请选择年级'; } if(!$classIds){ $error[] = '请选择班级'; } if(!$pcIds){ $error[] = '请指定目录'; } } $nodeArr = self::createTree($pcIds); $lastNode = end($pcIds); if(!$error){ $time = time(); $strModel = new SStudentClassRelation(); $transaction = $this->sConn->beginTransaction(); try{ $date = date("Y-m-d", $time); $lastday = date("Y-m-d",strtotime("$date Sunday")); $firstday = date("Y-m-d",strtotime("$lastday - 6 days")); $htbGroupId = getUniqueId($this->schoolId); $htbIds=array(); foreach($classIds as $k=>$v){ $htbId = getUniqueId($this->schoolId); $htbIds[]=$htbId; $this->sConn->createCommand()->insert('math_htb_setting',array( 'htb_group_id' =>$htbGroupId, 'htb_id' => $htbId, 'name' => isset($lastNode['pcName']) ? $lastNode['pcName'] : '', 'semester_id' => $this->semesterId, 'grade' => $grade, 'class_id' => $v, 'is_all_html' => 0, 'node_ids' => json_encode($nodeArr, true), 'school_group_id'=> $this->schoolGroupId, 'create_time' => $time, 'is_answer_merge' => $isAnswerMerge, 'is_new_version' => $isNewVersion, )); //FIXME 当前周已存在则不插入记录 $sql = <<sConn->createCommand($sql)->queryRow(); if(empty($data)) { $this->sConn->createCommand()->insert('math_htb_class_limit', array( 'semester_id' => $this->semesterId, 'grade' => $grade, 'class_id' => $v, 'limit' => 3, 'week_start_time' => $firstday, 'week_end_time' => $lastday, 'create_time' => $time, )); } //获取班级学生 $stuData = $strModel->getRelationsByClassId_Status_0($v); if($stuData){ foreach($stuData as $kk=>$vv){ $this->sConn->createCommand()->insert('math_htb_student',array( 'htb_id' => $htbId, 'class_id' => $v, 'student_id' => $vv['student_id'], 'create_time'=>$time )); } } } $transaction->commit(); }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{ if($isNewVersion){ $kafkaData = array( 'school_id' => $this->schoolId, 'msg_type' => 1,//90:重置 1:新设置 'subject_id' => 3, 'send_type' => 'math_htb', 'product_type' => 21, 'gp_group_id' => $htbGroupId, 'gp_ids' => $htbIds, 'student_ids'=>array(), ); sendDataToKafka("php-product-math-htb-html", $kafkaData); } echo json_encode(array('status'=>1));exit; } } /** * 获取菜单功能层级树 */ private static function createTree($data,$parentId = 0) { if(!$data){ return array(); } $tree = array(); foreach($data as $k => $v) { //递归查找 if($v['parentId'] == $parentId) { $v['level'] = $k + 1; $version=0; if($v['pcName']=='基础版'){ $version=1; }elseif($v['pcName']=='培优版'){ $version=2; } $v['version']=$version; $v['children'] = static::createTree($data, $v['pcId']); $tree[] = $v; } } return $tree; } /* * 获取班级 */ public function actionAjaxGetClasses(){ $result = array(); $grade=(int)Req::post('grade'); $time = time(); $date = date('Y-m-d',$time); $endDate = date("Y-m-d",strtotime("$date Sunday")); $startDate = date("Y-m-d",strtotime("$endDate - 6 days")); $startTime = strtotime($startDate. ' 00:00:00'); $endTime = strtotime($endDate. ' 23:59:59'); //获取班级 $hasLimitClassIds = array(); $sql = <<={$startTime} and s.create_time<={$endTime} and '{$date}' BETWEEN l.week_start_time AND l.week_end_time GROUP BY s.class_id; SQL; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ foreach($data as $k=>$v){ if($v['c_count'] >= $v['limit']){ $hasLimitClassIds[] = (string)$v['class_id']; } } } if($grade){ $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ $i = 0; foreach($data as $k => $v){ $sql = "select count(student_id) count from student_class_relation where class_id = '{$v['class_id']}' and status = 0"; $class_student = $this->sConn->createCommand($sql)->queryRow(); if($class_student && $class_student['count']>0){ $result[$i]['class_id'] = $v['class_id']; $result[$i]['class_name'] = $v['class_name']; if(in_array((string)$v['class_id'],$hasLimitClassIds,true)){ $result[$i]['status'] = 1; }else{ $result[$i]['status'] = 0; } $i++; } } } } echo json_encode($result);exit; } //选择学生 好题本 public function actionSelectStu(){ $data = array(); $sname = (string)Req::get("sname"); //学生名字 $htbId = (string)Req::get("htbId"); if(!$htbId){ Yii::app()->jump->error('参数错误!'); } //获取班级名称以及周后推送名称 $sql = "select s.name,c.class_name,s.grade,s.class_id,s.create_time,s.semester_id from math_htb_setting s join class c on s.class_id = c.class_id where s.htb_id = '{$htbId}'"; $names = $this->sConn->createCommand($sql)->queryRow(); if(!$names){ $names = array(); $names['name'] = ''; $names['class_name'] = ''; $names['grade'] = 0; }else{ $data['name'] = isset($names['name'])?$names['name']:''; } $sql = "select student_id,is_htb_pdf from math_htb_student where htb_id = '{$htbId}'"; $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_htb_pdf']; } } if($studentIds){ $studentNames = SStudentInfo::model()->getStudents($studentIds); //求学生名字 if($studentNames){ if($sname){ $i = 1; foreach($studentNames as $k=>$v){ if(strpos($v['realname'],$sname) !== false){ $data['list'][$i]['stu_id'] = (string)$v['student_id']; $data['list'][$i]['stu_name'] = $v['realname']; $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0; $i++; } } }else{ $i = 1; foreach($studentNames as $k=>$v){ $data['list'][$i]['stu_id'] = (string)$v['student_id']; $data['list'][$i]['stu_name'] = $v['realname']; $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name']; $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0; $i++; } } } } $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$names['semester_id']."'") ->limit(1) ->query() ->read(); if($studentIds){ $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$names['class_id'], "semester"=>$code['refer_code'], "grade"=>$names['grade'], "students"=>$studentIds, "examTime"=>$names['create_time'], "classify"=>9, "subject"=>3 ); $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']=array(); foreach ($rs->data as $v){ $data['limitstu'][(string)$v]=$v; } } } $data['htbId'] = $htbId; $data['sname'] = $sname; $data['printType'] = 'htb_stu'; $this->render('htb_stu',$data); } //下载好题本 public function actionGetHtbFile(){ $htbId = (string)Req::get("htbId"); $studentsIds = (string)Req::get("studentsIds"); $params = array(); if(!$htbId){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!$studentsIds){ $studentsIds = array(); $sql = "select student_id from math_htb_student where htb_id = '{$htbId}' and is_htb_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if($stuArr){ foreach($stuArr as $k=>$v){ $studentsIds[] = $v['student_id']; } } }else{ $studentsIds = explode(',',$studentsIds); } if(!$studentsIds || empty($studentsIds)){ echo json_encode(array("success" => 0, "message" => "无生成的学生")); exit(); } $params['htbId'] = $htbId; $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_htb_setting where htb_id = '{$htbId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$msg['semester_id']."'") ->limit(1) ->query() ->read(); $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$msg['class_id'], "semester"=>$code['refer_code'], "grade"=>$msg['grade'], "students"=>$studentsIds, "examTime"=>$msg['create_time'], "classify"=>9, "subject"=>3 ); if(isset($msg['school_group_id']) && $msg['school_group_id']){ $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; }else{ $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if(!$apiUrl){ echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId)); if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){ if($studentsIds){ $params["studentIds"] = $studentsIds; } }else{ if(Yii::app()->params["limit_open"]){ $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"){ echo json_encode(array("success" => 0, "message" => $rs->errMsg)); exit(); } if(!empty($rs->data)){ $params["studentIds"]=$rs->data; if(count($rs->data)data)."位学生可下载"; } } else{ echo json_encode(array("success" => 0, "message" =>"请先购买商品")); exit(); } }else{ if($studentsIds){ $params["studentIds"] = $studentsIds; } } } $params['schoolId'] = $this->schoolId; $params['type'] = 5; $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params); if(!($rs = json_decode($rs))){ $rs = array( "success" => 0, "message" => "请求接口失败", ); }else{ //更新下载时间 if($rs->success==1 || $rs->success==2){ $time = time(); if($studentsIds){ $sql = "update math_htb_student set is_htb_download = 1,htb_download_time={$time} where htb_id = '{$htbId}' and student_id in (".implode(',',$studentsIds).")"; $this->sConn->createCommand($sql)->execute(); } } } if(isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)){ if (YII_ENV == 'pro' || YII_ENV == 'production') { $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$msg['school_group_id'],$rs->downloadPath); } } echo json_encode($rs);exit; } //好题本预览 public function actionPreview() { $this->layout = false; $pcIds = Req::get('pcIds'); $lastNode = end($pcIds); $node_id_arr = self::createTree($pcIds); //设置的目录树 $set_pc_ids = array(); $this->getPcIds($node_id_arr,$set_pc_ids); //好题本数据 $htb_rs_arr = $this->getHtbData(array('pcIds' => $set_pc_ids)); //取出试题id $student_htb_arr = array(); $all_topic_ids = array(); foreach ($htb_rs_arr as $htb_rs) { if (isset($htb_rs['pcId']) && isset($htb_rs['pcName']) && isset($htb_rs['details'])) { $_student_htb_arr = array(); $_student_htb_arr['pc_id'] = $htb_rs['pcId']; $_student_htb_arr['pc_name'] = $htb_rs['pcName']; $_student_htb_arr['details'] = array(); if (is_array($htb_rs['details']) && $htb_rs['details']) { $_student_htb_arr['details'] = $htb_rs['details']; foreach ($htb_rs['details'] as $detail) { //控件ID:1文本编辑器 2试题 if ($detail['pwId'] == 2) { $all_topic_ids[] = $detail['topicId']; } } } $student_htb_arr[$htb_rs['pcId']] = $_student_htb_arr; } } if (!$student_htb_arr) { echo '

该节点下无内容,请不要生成,避免次数浪费!并把该情况及时反馈给研究院老师!

';exit; } //题详情 if ($all_topic_ids) { $_params = array('isFormat' => 1, 'isNoReplaceLable' => 0); $topic_info_arr = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $all_topic_ids, 'subjectId' => $this->subjectId, 'params' => $_params), 25, true); }else{ $topic_info_arr = array(); } //题考点最高使用量 $topic_method_use = array(); $topic_rel_method_max = array();//试题对应的使用最多考点id if ($topic_info_arr) { foreach ($topic_info_arr as $topic_info) { $method_names = isset($topic_info['method_names']) && $topic_info['method_names'] ? $topic_info['method_names'] : array(); $method_use_arr = array(); foreach ($method_names as $key=>$method){ $method_use_arr[$key] = Yii::app()->method_use_num->hmget('method_stat', $key); } if ($method_use_arr) { arsort($method_use_arr); foreach ($method_use_arr as $method_id => $num) { $topic_method_use[$topic_info['topic_id']] = $topic_info['method_names'][$method_id]; $topic_rel_method_max[$topic_info['topic_id']] = $method_id; break; } } } } //考点视频二维码 $method_qrcode_arr = array(); if ($topic_rel_method_max) { $method_qrcode_rs = self::methodVideoQrcode(array_values($topic_rel_method_max)); foreach ($topic_rel_method_max as $topic_id => $method_id) { if (isset($method_qrcode_rs[$method_id]) && $method_qrcode_rs[$method_id]) { $method_qrcode_arr[$topic_id] = $method_qrcode_rs[$method_id]; } } } $html_data['htb_set_name'] = isset($lastNode['pcName']) ? $lastNode['pcName'] : '好题本'; $html_data['node_id_arr'] = $node_id_arr; $html_data['htb_text_arr'] = $student_htb_arr; $html_data['topic_info_arr'] = $topic_info_arr; $html_data['topic_method_use'] = $topic_method_use; $html_data['method_video'] = $method_qrcode_arr; $this->render('preview', $html_data); } /** * 获取目录id * @param $node_id_arr * @param $set_pc_ids */ private function getPcIds($node_id_arr,&$set_pc_ids) { foreach ($node_id_arr as $_node_arr) { if (isset($_node_arr['pcId'])) { $set_pc_ids[] = $_node_arr['pcId']; if (isset($_node_arr['children']) && $_node_arr['children']) { $this->getPcIds($_node_arr['children'], $set_pc_ids); break; } } } } /** * 获取好题本数据 * @param $pc_ids * @return array */ private function getHtbData($pc_ids) { $htb_rs = array(); $rs = $this->apiPost('/product/detail',$pc_ids); $rs = json_decode(json_encode($rs),true); if (isset($rs['status'])) { if ($rs['status'] == 1 && isset($rs['data'])) { $htb_rs = $rs['data']; }else{ echo'获取好题本数据失败,错误信息是:'.(isset($rs['error'])?$rs['error']:''),0,true;exit; } }else{ echo 'brain:product/detail接口返回失败'; } return $htb_rs; } /** * 试题考点二维码 * @param $method_ids * @return array */ static public function methodVideoQrcode($method_ids) { $rs = array(); if ($method_ids) { foreach ($method_ids as $method_id) { $redis_json = Yii::app()->method_video->hget('content:method_video', $method_id); if ($redis_json) { if (is_array($redis_json)) { $video_arr = $redis_json; } else { $video_arr = json_decode($redis_json, true); } if (isset($video_arr[0]) && isset($video_arr[0]['video_qrcode'])) { $rs[$method_id] = $video_arr[0]['video_qrcode']; } } } } return $rs; } /** * 重置列表 */ public function actionResetHtb(){ $htbGroupId=(string)Req::get('htbGroupId'); $data = array(); $resetCount = 0; if($htbGroupId){ $sql = "select mhs.htb_id,mhs.`name`,mhs.class_id,mhs.is_reset,c.class_name from math_htb_setting mhs join class c on mhs.class_id = c.class_id where mhs.htb_group_id = '{$htbGroupId}'"; $data = $this->sConn->createCommand($sql)->queryAll(); if($data){ foreach($data as &$item){ if($item["is_reset"]){ $resetCount++; } $item['total_count']=0; $item['create_count']=0; $sql = "select count(*) total_count,count(case when is_htb_pdf = 1 then 1 end) create_count from math_htb_student where htb_id = '{$item['htb_id']}'"; $htbStudent = $this->sConn->createCommand($sql)->queryRow(); if($htbStudent){ $item['total_count'] = $htbStudent["total_count"]; $item['create_count'] = $htbStudent["create_count"]; } } } } if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']==1 ){ $resetCount = 0; } //debug($resetCount); $this->render('htb_reset',array("data"=>$data,"resetCount"=>$resetCount,'htb_group_id'=>$htbGroupId)); } /** * 重置接口 */ public function actionAjaxResetHtb(){ $error = array(); if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){ $error[] = '错误的来源!'; }else{ $reqHtbIds=Req::post('htbIds'); $reqhtbGroupId=Req::post('htbGroupId'); if(!$reqHtbIds){ $error[] = '请选择班级'; } if(!$reqhtbGroupId){ $error[]='无组id'; } } if(!$error){ $time = time(); $transaction = $this->sConn->beginTransaction(); try{ $reqHtbIdsStr=implode(',',$reqHtbIds); $sql="select htb_group_id,htb_id,is_reset from math_htb_setting where htb_group_id={$reqhtbGroupId} and htb_id in ({$reqHtbIdsStr}) and is_new_version=1"; $htb=$this->sConn->createCommand($sql)->queryAll(); if(!$htb){ throw new \Exception('无可重置的有效数据'); } $htbIds=array(); $htbGroupId=0; foreach($htb as $item){ $htbGroupId=$item['htb_group_id']; $htbIds[]=$item['htb_id']; } $this->sConn->createCommand("update math_htb_setting set is_all_html = 0,is_reset=1 where htb_id in (".implode(',',$htbIds).") ")->execute(); $sql = "update math_htb_student set htb_download_time = 0,is_htb_download=0,is_htb_html=0,htb_html_path='',is_htb_pdf=0,htb_pdf_path='' where htb_id in (".implode(',',$htbIds).") "; $this->sConn->createCommand($sql)->execute(); //重置后清除已存在的下载任务 /*$task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $htbIds).") and product_type=10"; $this->conn->createCommand($task_sql)->execute();*/ $transaction->commit(); }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{ //发消息 if($htbGroupId && $htbIds){ $kafkaData = array( 'school_id' => $this->schoolId, 'msg_type' => 90,//90:重置 1:新设置 'subject_id' => 3, 'send_type' => 'math_htb', 'product_type' => 21, 'gp_group_id' => $htbGroupId, 'gp_ids' => $htbIds, 'student_ids'=>array(), ); sendDataToKafka("php-product-math-htb-html", $kafkaData); } echo json_encode(array('status'=>1));exit; } } //好题本预览 public function actionNewPreview() { $this->layout = false; $pcIds = Req::get('pcIds'); $lastNode = end($pcIds); $nodeIdArr = self::createTree($pcIds); if(!isset($lastNode['pcId']) || !$lastNode['pcId']){ echo '

该节点下无内容,请不要生成

';exit; } $lastPcId=$lastNode['pcId']; //设置的目录树 $setPcIds =$htbRs= array(); $this->getPcIds($nodeIdArr,$setPcIds); //好题本数据 $htbRs = $this->getNewHtbData(array('catalogIds' => array($lastPcId))); //知识点和关联题对应关系 //382:知识点1 384:知识点2 386:知识点3 388:知识点4 390:知识点5 392:知识点6 394:知识点7 396:知识点8 383:关联题1 385:关联题2 387:关联题3 389:关联题4 391:关联题5 393:关联题6 395:关联题7 397:关联题8 $mapColumnIdArr=array( 383 => 382, 385=> 384, 387=> 386, 389=> 388, 391 => 390, 393=> 392, 395=> 394, 397=> 396, ); $htbNodes=$topicIds=array(); //处理知识点内容 foreach($htbRs as $item){ $columnId=$item['column_id']; if($item['topic_id']){ $topicIds[]=(string)$item['topic_id']; } if(in_array($columnId,$mapColumnIdArr) && !isset($htbNodes[$columnId])){ $item['topic_ids']=array(); $htbNodes[$columnId]=$item; } } if (!$htbNodes) { echo '

该节点下无内容,请不要生成,避免次数浪费!并把该情况及时反馈给研究院老师!

';exit; } //知识点加入试题id foreach($htbRs as $item){ $columnId=$item['column_id']; if(isset($mapColumnIdArr[$columnId]) && $mapColumnIdArr[$columnId] && $item['topic_id']){ $mapColumnId=$mapColumnIdArr[$columnId]; if(isset($htbNodes[$mapColumnId]) && $htbNodes[$mapColumnId]){ $htbNodes[$mapColumnId]['topic_ids'][]=(string)$item['topic_id']; } } } //题详情 if ($topicIds) { $params = array('isFormat' => 0 , 'isTird' => 0 ,'isNewEnglish' => 0); $topicInfoArr = $this->apiBrainPost('topic/batchAll', array('topicIds' => $topicIds, 'subjectId' => $this->subjectId, 'params' => $params), 25, true); if(isset($topicInfoArr['status']) && $topicInfoArr['status']===0){ echo '

没有获取到试题数据,请稍后再试!

';exit; } }else{ $topicInfoArr = array(); } foreach($topicInfoArr as $key=>$item){ //全学科逻辑题型,只显示单选多选 $_type_name=''; if(in_array($item['type_name'],array('单选题','多选题'))){ $_type_name=str_replace('题','',$item['type_name']); } $item['_type_name']=$_type_name; $topicInfoArr[(string)$item['id']]=$item; unset( $topicInfoArr[$key]); } //知识点试题顺序 if($topicInfoArr){ $number=1; foreach($htbNodes as &$item){ $topicIdBasicType=array(); $item['number_word']=$this->numToWord($number); if(isset($item['topic_ids']) && $item['topic_ids']){ foreach($item['topic_ids'] as $topicId){ if(isset($topicInfoArr[$topicId]) && isset($topicInfoArr[$topicId]['basic_type_id']) ){ $topicIdBasicType[$topicId]=$topicInfoArr[$topicId]['basic_type_id']; } } asort($topicIdBasicType); $item['topic_ids']=array_keys($topicIdBasicType); } $number++; } } $title=$versionStr=''; $version=0; $versionArr=array('基础版'=>1,'培优版'=>2); foreach($pcIds as $val){ if(!$version && !empty($versionArr[$val['pcName']])){ $version=$versionArr[$val['pcName']]; $versionStr=$val['pcName']; } $title.=$val['pcName'].' '; } $data=array( 'title'=>$title, 'version'=>$version, 'version_str'=>$versionStr, 'htbNodes'=>$htbNodes, 'topicInfos'=>$topicInfoArr, ); $this->render('new_preview', $data); } /** * 获取好题本数据 * @param $pc_ids * @return array */ private function getNewHtbData($pc_ids) { $htb_rs = array(); $rs = $this->apiPost('/all_content/detail',$pc_ids); $rs = json_decode(json_encode($rs),true); if (isset($rs['status'])) { if ($rs['status'] == 1 && isset($rs['data'])) { $htb_rs = $rs['data']; }else{ echo'获取好题本数据失败,错误信息是:'.(isset($rs['error'])?$rs['error']:''),0,true;exit; } }else{ echo 'brain:all_content/detail接口返回失败';exit; } return $htb_rs; } /** * 数学转汉字 * @param $num * @return string */ private function numToWord($num) { $chiNum =array('零','一','二','三','四','五','六','七','八','九'); $chiUni =array('','十','百','千','万','亿','十','百','千'); $num_str = (string)$num; $count =strlen($num_str); $last_flag = true;//上一个 是否为0 $zero_flag = true;//是否第一个 $temp_num = null;//临时数字 $chiStr ='';//拼接结果 if ($count == 2) {//两位数 $temp_num =$num_str[0]; $chiStr =$temp_num == 1 ?$chiUni[1] :$chiNum[$temp_num].$chiUni[1]; $temp_num =$num_str[1]; $chiStr .=$temp_num == 0 ?'' :$chiNum[$temp_num]; }else if($count > 2){ $index = 0; for ($i=$count-1;$i >= 0 ;$i--) { $temp_num =$num_str[$i]; if ($temp_num == 0) { if (!$zero_flag && !$last_flag ) { $chiStr =$chiNum[$temp_num].$chiStr; $last_flag = true; } }else{ $chiStr =$chiNum[$temp_num].$chiUni[$index%9] .$chiStr; $zero_flag = false; $last_flag = false; } $index ++; } }else{ $chiStr =$chiNum[$num_str[0]]; } return $chiStr; } }