getList($newCondition,array('m.create_time desc','m.micro_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' => 2, 'parentId' => 0 )); $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' => 2, 'parentId' => $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; $res = $this->apiPost('/product/detail',array('pcIds'=> $parentId)); $details = array(); if($res->status== 1){ $resData = $res->data; $details = isset($resData[0]->details) ? $resData[0]->details : array(); } echo json_encode(array('status'=>1,'data'=>$data, 'detail'=>$details));exit; } //保存个性化学习宝赠品设置 public function actionAjaxSaveGift(){ $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'); if(!$grade){ $error[] = '请选择年级'; } if(!$classIds){ $error[] = '请选择班级'; } if(!$pcIds){ $error[] = '请指定目录'; } } $pcName =''; foreach ($pcIds as $item){ $pcName .= $item['pcName']; } $nodeArr = self::createTree($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")); $microGroupId = getUniqueId($this->schoolId); foreach($classIds as $k=>$v){ $microId = getUniqueId($this->schoolId); $this->sConn->createCommand()->insert('math_micro_setting',array( 'micro_group_id'=>$microGroupId, 'micro_id' => $microId, 'micro_type' => 2, 'name' => $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, )); $sql = <<sConn->createCommand($sql)->queryRow(); if(empty($data)) { $this->sConn->createCommand()->insert('math_micro_class_limit',array( 'micro_type' => 2, //微产品类型 2:个性化学习宝培优版赠品 '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_micro_student',array( 'micro_id' => $microId, '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{ 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; $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"); //学生名字 $microId = (string)Req::get("microId"); if(!$microId){ Yii::app()->jump->error('参数错误!'); } //获取班级名称以及周后推送名称 $sql = "select s.name,c.class_name,s.grade,s.class_id,s.create_time,s.semester_id from math_micro_setting s join class c on s.class_id = c.class_id where s.micro_id = '{$microId}'"; $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_micro_pdf from math_micro_student where micro_id = '{$microId}'"; $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_micro_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'], "subject"=>3 ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $intarr['classify'] = 1; $openStuIds = array(); while ($intarr['classify'] <= 3) { $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); } $openStuIds = array_merge($openStuIds, $rs->data); $intarr['classify']++; } $openStuIds = array_unique($openStuIds); if(!empty($openStuIds)){ $data['limitstu']=array(); foreach ($openStuIds as $v){ $data['limitstu'][(string)$v]=$v; } } } $data['microId'] = $microId; $data['sname'] = $sname; $data['printType'] = 'isp_gift_stu'; $this->render('isp_gift_stu',$data); } //下载好题本 public function actionGetGiftFile(){ $microId = (string)Req::get("microId"); $studentsIds = (string)Req::get("studentsIds"); $params = array(); if(!$microId){ echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if(!$studentsIds){ $studentsIds = array(); $sql = "select student_id from math_micro_student where micro_id = '{$microId}' and is_micro_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['microId'] = $microId; $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_micro_setting where micro_id = '{$microId}'"; $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'], "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"]); $intarr['classify'] = 1; $openStuIds = array(); while ($intarr['classify'] <= 3) { $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); } $openStuIds = array_merge($openStuIds, $rs->data); $intarr['classify']++; } if(!empty($openStuIds)){ $params["studentIds"]=array_unique($openStuIds); } else{ echo json_encode(array("success" => 0, "message" =>"请先购买商品")); exit(); } }else{ if($studentsIds){ $params["studentIds"] = $studentsIds; } } } $params['schoolId'] = $this->schoolId; $params['type'] = 6; //微产品 $params['microType'] = 2; //微产品类型 培优版赠品 $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_micro_student set is_micro_download = 1,micro_download_time={$time} where micro_id = '{$microId}' 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 actionDownload() { $pcdId = (string)Req::get("pcdId"); $url = (string)Req::get("url"); $fileName = (string)Req::get("fileName"); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_exec($ch); $code = curl_getinfo($ch,CURLINFO_HTTP_CODE); curl_close($ch); if($code == 404){ Yii::app()->jump->error('文件不存在!'); } $data['coachId'] = $this->coachId; $data['schoolId'] = $this->schoolId; $data['createTime'] = time(); $data['pcdId'] = $pcdId; $data['toDataPoint'] = true; $data['dataPointType'] = 15; @$this->sendKafka('datapoint-logs',$data); header('Content-Description: File Transfer'); header('Content-Type: application/vnd.android.package-archive'); header('Content-Disposition: attachment; filename=' . $fileName); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) { echo $buffer; return strlen($buffer); }); curl_exec($ch); curl_close($ch); } /** * 发送消息队列 * @return mixed */ private function sendKafka($topic='',$data = array()) { if ($data) { $conf = new RdKafka\Conf(); $conf->set('metadata.broker.list', Yii::app()->params['kafka']); $producer = new RdKafka\Producer($conf); $topic = $producer->newTopic($topic); $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($data)); $producer->poll(0); $result = $producer->flush(10000); if($result===0){ return true; } } return true; } /** * 发送消息队列 * @return mixed */ public function actionCheckOrder() { $classId = (string)Req::post("classId"); $grade = Req::post('grade'); $Sem=new SSemester(); $code= $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '".$this->semesterId."'") ->limit(1) ->query() ->read(); $strModel = new SStudentClassRelation(); $stuData = $strModel->getRelationsByClassId_Status_0($classId); $studentIds = array(); foreach ($stuData as $student){ $studentIds[]= $student['student_id']; } if($studentIds){ $intarr=array( "schoolId"=>$this->schoolId, "clazzId"=>$classId, "semester"=>$code['refer_code'], "grade"=>$grade, "students"=>$studentIds, "examTime"=>time(), "subject"=>3 ); $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]); $intarr['classify'] = 1; $openStuIds = array(); while ($intarr['classify'] <= 3) { $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); } $openStuIds = array_merge($openStuIds, $rs->data); $intarr['classify']++; } $openStuIds = array_unique($openStuIds); if(!empty($openStuIds)){ echo json_encode(array('status'=>1,'message'=>'ok'));exit; }else{ echo json_encode(array('status'=>0,'message'=>'该班级不存在个性化学习宝订单','class_id'=>$classId));exit; } }else{ echo json_encode(array('status'=>0,'message'=>'未获取该班级学生信息','class_id'=>$classId));exit; } } }