session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3; $productTemplate=$this->sConn->createCommand("select template_id,template_name,product_type,target_type,is_default from product_template where subject_id='{$subject_id}' and product_type=31")->queryAll(); if($productTemplate){ foreach ($productTemplate as $val){ $data['list'][$val['product_type']]=$val; } }else{ $this->initTemplate3(); $productTemplate=$this->sConn->createCommand("select template_id,template_name,product_type,target_type,is_default from product_template where subject_id='{$subject_id}' and product_type=31")->queryAll(); foreach ($productTemplate as $val){ $data['list'][$val['product_type']]=$val; } } $result['status'] = 1; $result['data']=$data['list']; exit(json_encode($result)); } public function actionAjaxGetTemplateById(){ $id = intval(Req::post('id')); $result['status'] = 0; if(!$id){ $result['msg']='模板ID不正确'; exit(json_encode($result)); } $productTemplate=$this->sConn->createCommand("select template_id,template_name,product_type,target_type,config_text,subject_id,is_default,create_time from product_template where template_id='{$id}'")->queryRow(); if(!$productTemplate){ $result['msg']='模板id不正确'; exit(json_encode($result)); }else{ $result['status'] = 1; $result['data'] = $productTemplate; exit(json_encode($result)); } } /*方法宝保存模板设置*/ public function actionSaveTemplate(){ $id = intval(Req::post('id')); $config=Req::post('config'); $result['status'] = 0; $subject_id = 3; if(!$id || !$config){ $result['msg']='模板参数不正确'; exit(json_encode($result)); } // $config=str_replace('"','"',$config); $configArr=json_decode($config,true); if(!$configArr){ $result['msg']='设置数据格式不正确'; exit(json_encode($result)); } $productTemplate=$this->sConn->createCommand("select template_id,product_type,target_type,subject_id from product_template where template_id='{$id}'")->queryRow(); if(!$productTemplate){ $result['msg']='模板id不正确'; exit(json_encode($result)); }else{ $subject_id = $productTemplate["subject_id"]; } if(!$this->checkoutJson($configArr,$productTemplate['product_type'],$productTemplate['target_type'],$subject_id)){ $result['msg']='设置数据格式不正确'; exit(json_encode($result)); } if($productTemplate['target_type']==1){ //班级模板 if(isset($configArr['studentLevelDivide']['levelDetails'])){ foreach ($configArr['studentLevelDivide']['levelDetails'] as $val){ if(isset($val['trainPushDetail']) && !$val['trainPushDetail']['pushDifficulty']){ $result['msg']='推送配置难度不能为空'; exit(json_encode($result)); } } }else{ $result['msg']='设置数据格式不正确'; exit(json_encode($result)); } } $criteria = new CDbCriteria(); $criteria->addCondition("template_id={$id}"); SProductTemplate::model()->updateAll(array('config_text'=>$config),$criteria); $result['status'] = 1; $result['msg']='操作成功'; exit(json_encode($result)); } //方法宝保存班级定制 public function actionSaveClassSet(){ $classIds=Req::post('classes'); //班级id组 包含年级 $template_id=Req::post('template_id'); $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3; $subject_id = $post_subject_id?$post_subject_id:$session_subject_id; $result['status'] = 0; if(!$classIds){ $result['msg']='请选择班级'; exit(json_encode($result)); } if(!$template_id){ $result['msg']='请选择模板'; exit(json_encode($result)); } $templateInfo=$this->sConn->createCommand("select product_type,target_type from product_template where template_id='{$template_id}' ")->queryRow(); if(!$templateInfo){ $result['msg']='模板id不正确'; exit(json_encode($result)); } $updateSql=array(); $insertSql=array(); foreach ($classIds as $val){ if(!isset($val['class_id']) || !$val['class_id']){ $result['msg']='班级数据错误'; exit(json_encode($result)); } $classInfo=$this->sConn->createCommand("select class_id,grade from class where class_id='{$val['class_id']}'")->queryRow(); if(!$classInfo){ $result['msg']='选择的班级不存在'; exit(json_encode($result)); } $classSet=$this->sConn->createCommand("select class_id from product_class_set where class_id='{$val['class_id']}' and subject_id='{$subject_id}' and product_type=31 ")->queryRow(); if($classSet){ $updateSql[]="update product_class_set set `template_id`='".$template_id."',semester_id='".$this->semesterId."' where class_id='".$val['class_id']."' and subject_id='{$subject_id}' and product_type=31"; }else{ $insertSql[]="insert into product_class_set(`class_id`,`semester_id`,`grade`,`template_id`,`subject_id`,`product_type`) values('".$val['class_id']."','".$this->semesterId."','".$classInfo['grade']."','".$template_id."','".$subject_id."','31')"; } } $trans = $this->sConn->beginTransaction(); try{ if($updateSql){ foreach ($updateSql as $sql){ $this->sConn->createCommand($sql)->execute(); } } if($insertSql){ foreach ($insertSql as $sql){ $this->sConn->createCommand($sql)->execute(); } } $trans->commit(); $result['status'] = 1; $result['msg'] = "更新成功"; }catch (Exception $e){ $trans->rollBack(); $result['status'] = 0; $result['msg'] = "更新失败"; } exit(json_encode($result)); } //班级定制列表 public function actionProductClassSet(){ $page=intval(Req::post('page')); $class_id=Req::post('class_id'); $grade_id=Req::post('grade_id'); $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3; $subject_id = $post_subject_id?$post_subject_id:$session_subject_id; if(!$page) $page=1; $pageLimit =10; $offset=($page-1)*$pageLimit; $semesterId=$this->semesterId; $pages=array(); //wrong_book 或wb ,isp ,wb_isp if($class_id){ $data=$this->sConn->createCommand("select class_id,grade,template_id from product_class_set where class_id='{$class_id}' and subject_id='{$subject_id}' and product_type=31")->queryAll(); }else{ if($grade_id){ $count=$this->sConn->createCommand("select count(*) as count from product_class_set where semester_id='{$semesterId}' and grade='{$grade_id}' and subject_id='{$subject_id}' and product_type=31")->queryRow(); $total=$count['count']; $totalPage=ceil($total/$pageLimit); $data=$this->sConn->createCommand("select class_id,grade,template_id from product_class_set where semester_id='{$semesterId}' and grade='{$grade_id}' and subject_id='{$subject_id}' and product_type=31 limit {$offset},{$pageLimit}")->queryAll(); }else{ $count=$this->sConn->createCommand("select count(*) as count from product_class_set where semester_id='{$semesterId}' and subject_id='{$subject_id}' and product_type=31")->queryRow(); $total=$count['count']; $totalPage=ceil($total/$pageLimit); $data=$this->sConn->createCommand("select class_id,grade,template_id from product_class_set where semester_id='{$semesterId}' and subject_id='{$subject_id}' and product_type=31 limit {$offset},{$pageLimit}")->queryAll(); } $pages=array( 'totalPage'=>$totalPage, 'total'=>$total, 'nowPage'=>$page ); } if($data){ //读取默认模板 $defaultTemplate=$this->sConn->createCommand("select template_name,product_type,target_type from product_template where is_default=1 and target_type=1 and subject_id='{$subject_id}' and product_type=31")->queryRow(); foreach ($data as $key => $val){ $classInfo=$this->sConn->createCommand("select class_name,level from class where class_id='".$val['class_id']."'")->queryRow(); $data[$key]['class_name']=$classInfo['class_name']; $data[$key]['level']=$classInfo['level']; //读取模板名 if($val['template_id']){ $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['template_id']}'")->queryRow(); $data[$key]['template_name']=$Template['template_name']; }else{ $data[$key]['template_name']=$defaultTemplate['template_name']; } } } $result['list']=$data; $result['pages']=$pages; exit(json_encode(array('status'=>1,'data'=>$result))); } //班级恢复默认 public function actionResetClassSet(){ $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id $subject_id = isset(Yii::app()->session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3; $subject_id = $post_subject_id?$post_subject_id:$subject_id; $sql = "select class_id from product_class_set where subject_id = '{$subject_id}' and product_type=31"; $class_set = $this->sConn->createCommand($sql)->queryRow(); if(!$class_set){ echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit; } if($this->sConn->createCommand("update product_class_set set template_id=0 where subject_id = '{$subject_id}' and product_type=31")->execute()){ echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit; }else{ echo json_encode(array('status'=>0,'msg'=>'操作失败'));exit; } } //学生定制列表 public function actionProductStudentSet(){ $page=intval(Req::post('page')); $class_id=Req::post('class_id'); $grade_id=Req::post('grade_id'); $student_name=Req::post('student_name'); if(!$page) $page=1; $pageLimit =10; $offset=($page-1)*$pageLimit; $semesterId=$this->semesterId; $subject_id=$this->subjectId; $where=array(); $where[]=" semester_id='{$semesterId}'"; $where[]=" product_type=31"; $where[]=" subject_id='{$subject_id}'"; if($class_id){ $where[]=" class_id='{$class_id}'"; } if($grade_id){ $where[]=" grade='{$grade_id}'"; } if($student_name){ $where[]=" student_name like '%".$student_name."%'"; } if($subject_id){ $where[]=" subject_id='{$subject_id}'"; } $count=$this->sConn->createCommand("select count(*) as count from product_student_set where ".implode(' and ',$where))->queryRow(); $total=$count['count']; $totalPage=ceil($total/$pageLimit); $data=$this->sConn->createCommand("select student_id,class_id,grade,wrong_book,isp,wb_isp,student_name,template_id from product_student_set where ".implode(' and ',$where)." limit {$offset},{$pageLimit}")->queryAll(); $pages=array( 'totalPage'=>$totalPage, 'total'=>$total, 'nowPage'=>$page ); if($data){ //取出所有学生,再查询行政班级名字 $student_arr = array(); foreach ($data as $value) { $student_arr[$value['student_id']] = $value['student_id']; } $stu_rel_class = $this->getStudentXzClassName(array_keys($student_arr)); //读取默认模板 $defaultTemplate=$this->sConn->createCommand("select template_name,product_type,target_type from product_template where is_default=1 and target_type=1 and subject_id='{$subject_id}' and product_type=31")->queryRow(); foreach ($data as $key => $val){ $classInfo=$this->sConn->createCommand("select class_name,level from class where class_id='".$val['class_id']."'")->queryRow(); if (isset($stu_rel_class[$val['student_id']])) { $data[$key]['class_name']=$stu_rel_class[$val['student_id']]; }else{ $data[$key]['class_name']=$classInfo['class_name']; } $data[$key]['level']=$classInfo['level']; //读取系统准考证号 $student=$this->conn->createCommand("select student_card from student where student_id='".$val['student_id']."'")->queryRow(); $data[$key]['student_card']=$student['student_card']; $classTemplateData=$this->sConn->createCommand("select template_id from product_class_set where class_id='".$val['class_id']."' and subject_id = '{$subject_id}' and product_type=31")->queryRow(); //读取模板名 if($val['template_id']){ $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$val['template_id']}' ")->queryRow(); $data[$key]['template_name']=$Template['template_name']; }else{ if($classTemplateData['template_id']){ $Template=$this->sConn->createCommand("select template_name from product_template where template_id='{$classTemplateData['template_id']}' ")->queryRow(); $data[$key]['template_name']=$Template['template_name']; }else{ $data[$key]['template_name']=$defaultTemplate['template_name']; } } } } $result['list']=$data; $result['pages']=$pages; exit(json_encode(array('status'=>1,'data'=>$result))); } //保存学生定制 public function actionSaveStudentSet(){ $studentIds=Req::post('students'); $template_id=Req::post('template_id'); $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3; $subject_id = $post_subject_id?$post_subject_id:$session_subject_id; $result['status'] = 0; if(!$studentIds){ $result['msg']='请选择学生'; exit(json_encode($result)); } if(!$template_id){ $result['msg']='请选择模板'; exit(json_encode($result)); } $templateInfo=$this->sConn->createCommand("select product_type,target_type from product_template where template_id='{$template_id}' ")->queryRow(); if($templateInfo['product_type']!=31){ $result['msg']='模板类型不正确'; exit(json_encode($result)); } $updateSql=array(); $insertSql=array(); foreach ($studentIds as $val){ if(!$val['student_id'] || !$val['realname'] || !$val['class_id'] || !$val['grade_id']){ $result['msg']='学生数据错误'; exit(json_encode($result)); } $classInfo=$this->sConn->createCommand("select class_id,grade from class where class_id='{$val['class_id']}'")->queryRow(); if(!$classInfo){ $result['msg']='选择的班级不存在'; exit(json_encode($result)); } $studentSet=$this->sConn->createCommand("select student_id,student_name,use_custom,semester_id from product_student_set where student_id='{$val['student_id']}' and subject_id='{$subject_id}' and product_type=31")->queryRow(); if($studentSet){ $updateSql[]="update product_student_set set `template_id`='".$template_id."',semester_id='".$this->semesterId."' where student_id='".$val['student_id']."' and subject_id='".$subject_id."' and product_type=31"; }else{ $insertSql[]="insert into product_student_set(`student_id`,`student_name`,`semester_id`,`class_id`,`grade`,`template_id`,`subject_id`,`product_type`) values('".$val['student_id']."','".$val['realname']."','".$this->semesterId."','".$val['class_id']."','".$classInfo['grade']."','".$template_id."','".$subject_id."','31')"; } } $trans = $this->sConn->beginTransaction(); try{ if($updateSql){ foreach ($updateSql as $sql){ $this->sConn->createCommand($sql)->execute(); } } if($insertSql){ foreach ($insertSql as $sql){ $this->sConn->createCommand($sql)->execute(); } } $trans->commit(); $result['status'] = 1; $result['msg']='更新完成'; }catch (Exception $e){ $trans->rollBack(); $result['status'] = 0; $result['msg'] = "更新失败"; } exit(json_encode($result)); } //学生恢复默认 public function actionResetStudentSet(){ $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id $subject_id = isset(Yii::app()->session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3; $subject_id = $post_subject_id?$post_subject_id:$subject_id; $sql = "select student_id from product_student_set where subject_id = '{$subject_id}' and product_type=31"; $student_set = $this->sConn->createCommand($sql)->queryRow(); if(!$student_set){ echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit; } if($this->sConn->createCommand("update product_student_set set template_id=0 where subject_id='{$subject_id}' and product_type=31")->execute()){ echo json_encode(array('status'=>1,'msg'=>'操作成功'));exit; }else{ echo json_encode(array('status'=>0,'msg'=>'操作失败'));exit; } } //复用模板设置 public function actionCopyTemplate(){ $id = intval(Req::post('id')); $result['status'] = 0; if(!$id){ $result['msg']='模板ID不能为空'; exit(json_encode($result)); } $productTemplate=$this->sConn->createCommand("select template_name,product_type,target_type,config_text,subject_id from product_template where template_id='{$id}'")->queryRow(); if(!$productTemplate){ $result['msg']='请选择复用的模板'; exit(json_encode($result)); } //查询模板名称 $templateName=$productTemplate['template_name'].'副本'; $repeat=$this->sConn->createCommand("select template_name from product_template where template_name like '".$templateName."%' and product_type='".$productTemplate['product_type']."' and target_type='".$productTemplate['target_type']."' and subject_id='".$productTemplate['subject_id']."'")->queryAll(); if($repeat){ $preg='/\(\d+\)/is'; $cloneCount=0; foreach ($repeat as $value){ $str=str_replace($templateName,'',$value['template_name']); preg_match_all($preg,$str,$match); if(isset($match[0]) && count($match[0])==1){ $cloneCount++; } } $templateName.='('.($cloneCount+1).')'; }else{ $templateName.='(1)'; } $ps = new SProductTemplate(); $ps->template_name = $templateName; $ps->product_type = $productTemplate['product_type']; $ps->target_type = $productTemplate['target_type']; $ps->config_text = $productTemplate['config_text']; $ps->subject_id = $productTemplate['subject_id']; $ps->is_default = 0; $ps->create_time = time(); if($bool = $ps->save()){ $result['status'] = 1; $result['msg']='操作成功'; $result['data']=array( 'id'=>$ps->template_id, 'name'=>$templateName ); }else{ $result['msg']='操作失败'; } exit(json_encode($result)); } //根据类型读取模板 public function actionGetTemplateByType(){ $targetType=intval(Req::post('target_type')); //使用类型:1班级模板,2学生模板 $post_subject_id = intval(Req::post('subject_id')); //接口传的subject_id $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3; $subject_id = $post_subject_id?$post_subject_id:$session_subject_id; $isBeta = $this->isBeta($subject_id); $sql="select template_id,template_name,target_type from product_template where product_type='31 ' and subject_id={$subject_id} "; if($targetType && in_array($targetType,array(1,2))){ $sql.=" and target_type='".$targetType."'"; } $productTemplate=$this->sConn->createCommand($sql)->queryAll(); if(!$productTemplate){ $this->initTemplate3(); $productTemplate=$this->sConn->createCommand($sql)->queryAll(); } $result['status'] = 1; $result['msg']='操作成功'; $result['data']=$productTemplate; exit(json_encode($result)); } }