session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3; // $subject_id = 3; $isBeta = $this->isBeta($subject_id); $productTemplate=$this->sConn->createCommand("select template_id,template_name,product_type,target_type,is_default,is_beta from product_template where is_default=1 and subject_id = {$subject_id}")->queryAll(); if($productTemplate){ foreach ($productTemplate as $val){ if($val['product_type']==1 && $val['is_beta']==$isBeta){ if($val['target_type']==1){ $wrongBook['class']=1; }elseif($val['target_type']==2){ $wrongBook['student']=1; } }elseif($val['product_type']==2 && $val['is_beta']==$isBeta){ if($val['target_type']==1){ $isp['class']=1; }elseif($val['target_type']==2){ $isp['student']=1; } }elseif($val['product_type']==3 && $val['is_beta']==$isBeta){ if($val['target_type']==1){ $wbIsp['class']=1; }elseif($val['target_type']==2){ $wbIsp['student']=1; } }elseif($val['product_type']==31){ if($val['target_type']==1){ $methodIsp['class']=1; }elseif($val['target_type']==2){ $methodIsp['student']=1; } } } } //判断默认模板是否存在 if($subject_id == 12){ $wrongBookClassConfig = ProductPhysicsTpl::PHYSICS_CLASS_WB; $wrongBookStudentConfig = ProductPhysicsTpl::PHYSICS_STU_WB; $ispClassConfig = ProductPhysicsTpl::PHYSICS_CLASS_ISP; $ispStudentConfig = ProductPhysicsTpl::PHYSICS_STU_ISP; $wpIspClassConfig = ProductPhysicsTpl::PHYSICS_CLASS_WB_ISP; $wpIspStudentConfig = ProductPhysicsTpl::PHYSICS_STU_WB_ISP; }else{ if(!$isBeta) { $wrongBookClassConfig = ProductMathTpl::MATH_CLASS_WB; $wrongBookStudentConfig = ProductMathTpl::MATH_STU_WB; $ispClassConfig = ProductMathTpl::MATH_CLASS_ISP; $ispStudentConfig = ProductMathTpl::MATH_STU_ISP; $wpIspClassConfig = ProductMathTpl::MATH_CLASS_WB_ISP; $wpIspStudentConfig = ProductMathTpl::MATH_STU_WB_ISP; $methodIspClassConfig = ProductMethodTpl::Method_CLASS_WB; $methodIspStudentConfig = ProductMethodTpl::Method_STU_WB; }else{ $wrongBookClassConfig = ProductMathTpl::MATH_CLASS_WB_BETA; $wrongBookStudentConfig = ProductMathTpl::MATH_STU_WB_BETA; $ispClassConfig = ProductMathTpl::MATH_CLASS_ISP_BETA; $ispStudentConfig = ProductMathTpl::MATH_STU_ISP_BETA; $wpIspClassConfig = ProductMathTpl::MATH_CLASS_WB_ISP_BETA; $wpIspStudentConfig = ProductMathTpl::MATH_STU_WB_ISP_BETA; $methodIspClassConfig = ProductMethodTpl::Method_CLASS_WB; $methodIspStudentConfig = ProductMethodTpl::Method_STU_WB; } } $values=array(); if(!isset($wrongBook['class'])){ $values[]="('班级默认模板',1,1,'".$wrongBookClassConfig."',".$subject_id.",1,'".time()."',".$isBeta.")"; } if(!isset($wrongBook['student'])){ $values[]="('学生默认模板',1,2,'".$wrongBookStudentConfig."',".$subject_id.",1,'".time()."',".$isBeta.")"; } if(!isset($isp['class'])){ $values[]="('班级默认模板',2,1,'".$ispClassConfig."',".$subject_id.",1,'".time()."',".$isBeta.")"; } if(!isset($isp['student'])){ $values[]="('学生默认模板',2,2,'".$ispStudentConfig."',".$subject_id.",1,'".time()."',".$isBeta.")"; } if(!isset($wbIsp['class'])){ $values[]="('班级默认模板',3,1,'".$wpIspClassConfig."',".$subject_id.",1,'".time()."',".$isBeta.")"; } if(!isset($wbIsp['student'])){ $values[]="('学生默认模板',3,2,'".$wpIspStudentConfig."',".$subject_id.",1,'".time()."',".$isBeta.")"; } if($subject_id == 3) {//只有高中数学才有方法宝设置 if (!isset($methodIsp['class'])) { $values[] = "('班级默认模板',31,1,'" . $methodIspClassConfig . "'," . $subject_id . ",1,'" . time() . "',0)"; } if (!isset($methodIsp['student'])) { $values[] = "('学生默认模板',31,2,'" . $methodIspStudentConfig . "'," . $subject_id . ",1,'" . time() . "',0)"; } } if($values){ $sql="insert into product_template(`template_name`,`product_type`,`target_type`,`config_text`,`subject_id`,`is_default`,`create_time`,`is_beta`) values ".implode(',',$values); $this->sConn->createCommand($sql)->execute(); } } //根据类型读取模板 public function actionGetTemplateByType(){ $type = intval(Req::post('type')); //模板类型 1-错题本 2-个性化学习方案 3-个性化学习宝 $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; if(!$type ){ $result['msg']='参数错误'; exit(json_encode($result)); } $sql="select template_id,template_name,target_type from product_template where product_type='{$type} ' and subject_id={$subject_id} "; if($targetType && in_array($targetType,array(1,2))){ $sql.=" and target_type='".$targetType."'"; } $productTemplate=$this->sConn->createCommand($sql)->queryAll(); $result['status'] = 1; $result['msg']='操作成功'; $result['data']=$productTemplate; exit(json_encode($result)); } //将提交的json和模板结构进行对比 protected function checkoutJson($jsonArr,$productType,$targetType,$subject_id=3){ // $subject_id = isset(Yii::app()->session['session_duoxueke_subject_id']) ? Yii::app()->session['session_duoxueke_subject_id']:3; if(!$jsonArr) return false; $tempJson=''; $isBeta = $this->isBeta($subject_id); if($productType==1){ if($targetType==1){ if($subject_id == 12){ $tempJson = ProductPhysicsTpl::PHYSICS_CLASS_WB; }else{ $tempJson = $isBeta ? ProductMathTpl::MATH_CLASS_WB_BETA : ProductMathTpl::MATH_CLASS_WB; } }elseif($targetType==2){ if($subject_id == 12){ $tempJson = ProductPhysicsTpl::PHYSICS_STU_WB; }else{ $tempJson = $isBeta ? ProductMathTpl::MATH_STU_WB_BETA: ProductMathTpl::MATH_STU_WB; } } }elseif($productType==2){ if($targetType==1){ if($subject_id == 12){ $tempJson = ProductPhysicsTpl::PHYSICS_CLASS_ISP; }else{ $tempJson = $isBeta ? ProductMathTpl::MATH_CLASS_ISP_BETA : ProductMathTpl::MATH_CLASS_ISP; } }elseif($targetType==2){ if($subject_id == 12){ $tempJson = ProductPhysicsTpl::PHYSICS_STU_ISP; }else{ $tempJson = $isBeta ? ProductMathTpl::MATH_STU_ISP_BETA : ProductMathTpl::MATH_STU_ISP; } } }elseif($productType==3){ if($targetType==1){ if($subject_id == 12){ $tempJson = ProductPhysicsTpl::PHYSICS_CLASS_WB_ISP; }else{ $tempJson = $isBeta ? ProductMathTpl::MATH_CLASS_WB_ISP_BETA : ProductMathTpl::MATH_CLASS_WB_ISP; } }elseif($targetType==2){ if($subject_id == 12){ $tempJson = ProductPhysicsTpl::PHYSICS_STU_WB_ISP; }else{ $tempJson = $isBeta ? ProductMathTpl::MATH_STU_WB_ISP_BETA : ProductMathTpl::MATH_STU_WB_ISP; } } }elseif($productType==31){ if($targetType==1){ $tempJson = ProductMethodTpl::Method_CLASS_WB; }elseif($targetType==2){ $tempJson = ProductMethodTpl::Method_STU_WB; } } if(!$tempJson) return false; $jsonTemplate=json_decode($tempJson,true); foreach ($jsonTemplate as $key =>$value){ if(!isset($jsonArr[$key])) return false; if(is_array($value)){ foreach ($value as $key_2 =>$val ){ if(!isset($jsonArr[$key][$key_2])) return false; if(is_array($val)){ foreach ($val as $key_3 =>$v){ if($key_2=='levelDetails' && $key_3>0){ continue; } if(!isset($jsonArr[$key][$key_2][$key_3])) return false; if(is_array($v)){ foreach ($v as $key_4 =>$vv){ if(!isset($jsonArr[$key][$key_2][$key_3][$key_4])) return false; } } } } } } } return true; } //获取学期学年 public function actionGetSemester(){ $semesterId = $this->semesterId; $data = array(); if($semesterId){ $result=$this->sConn->createCommand("select semester_name,school_year from semester where semester_id='{$semesterId}'")->queryRow(); if($result){ $data['semester_name'] = $result['semester_name']; $data['school_year'] = $result['school_year']; } } echo json_encode(array('status'=>1,'data'=>$data));exit; } public function getProductEdition() { $switch = 2; $data=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow(); if($data){ $switch = $data['switch']; } return $switch; } //FIXME public function isBeta($subject_id=3) { if(!in_array($subject_id,Yii::app()->params['mathSubjectId'])){ return 0; } $switch = $this->getProductEdition(); return $switch == 4 ? 1 :0; } //切换学科 public function actionChangeSubject(){ $subjectId=Req::post('subjectId')?Req::post('subjectId'):0; if(!$subjectId){ echo json_encode(array('status'=>0,'msg'=>'学科不正确 '));exit; }else{ Yii::app()->session['session_duoxueke_subject_id'] = $subjectId; Yii::app()->session['session_subject_id'] = $subjectId; echo json_encode(array('status'=>1));exit; } } //根据年级读取班级 public function actionGetClassByGrade(){ $grade_id = Req::post("grade_id"); $class_array = array(); if(!in_array($grade_id,array(0,1,2,3))) { echo json_encode(array('status'=>0,'result'=>array()));exit; } if($grade_id){ $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=:class_type',array(':grade' => $grade_id,':semester_id'=>$this->semesterId,':class_type'=>1)); }else{ $class_data = ClassModel::model()->findAll(' semester_id=:semester_id and class_type=:class_type',array(':semester_id'=>$this->semesterId ,':class_type'=>1)); } if($class_data){ foreach($class_data as $v ) { $class_array[] = $v->attributes; } echo json_encode(array('status'=>1,'result'=>$class_array));exit; } echo json_encode(array('status'=>0,'result'=>array()));exit; } /** * 查询行政班级名字 * @param $stu_ids * @return mixed */ protected function getStudentXzClassName($stu_ids) { $student_class_info =$this->sConn->createCommand("select c.class_name,scr.student_id from student_class_relation as scr left join class as c on scr.class_id = c.class_id where scr.status = 0 and c.class_type = 1 and scr.student_id in (".implode(',',$stu_ids).")")->queryAll(); if ($student_class_info) { foreach ($student_class_info as $value) { $stu_rel_class[$value['student_id']] = $value['class_name']; } } unset($student_class_info); return $stu_rel_class; } //重命名 public function actionReNameTemplate(){ $id = intval(Req::post('id')); $name=Req::post('name'); $result['status'] = 0; $session_subject_id = isset(Yii::app()->session['session_duoxueke_subject_id'])?Yii::app()->session['session_duoxueke_subject_id']:3; if(!$id ){ $result['msg']='请选择模板'; exit(json_encode($result)); } if(!$name){ $result['msg']='名称不能为空'; exit(json_encode($result)); } $productTemplate=$this->sConn->createCommand("select template_id,product_type from product_template where template_id='{$id}'")->queryRow(); if(!$productTemplate){ $result['msg']='模板id不正确'; exit(json_encode($result)); } $productTemplate=$this->sConn->createCommand("select template_id from product_template where template_name='{$name}' and product_type='{$productTemplate['product_type']}' and subject_id='{$session_subject_id}'")->queryRow(); if($productTemplate){ $result['msg']='模板名称已存在'; exit(json_encode($result)); } $criteria = new CDbCriteria(); $criteria->addCondition("template_id={$id}"); if(SProductTemplate::model()->updateAll(array('template_name'=>$name),$criteria)){ $result['status'] = 1; $result['msg']='操作成功'; }else{ $result['msg']='操作失败'; } exit(json_encode($result)); } //删除 public function actionDelTemplate(){ $id = intval(Req::post('id')); $result['status'] = 0; if(!$id ){ $result['msg']='请选择模板'; exit(json_encode($result)); } $productTemplate=$this->sConn->createCommand("select template_id,is_default,product_type,target_type from product_template where template_id='{$id}'")->queryRow(); if(!$productTemplate){ $result['msg']='模板id不正确'; exit(json_encode($result)); } if($productTemplate['is_default']==1){ $result['msg']='默认模板不可以删除'; exit(json_encode($result)); } //删除模板 $trans = $this->sConn->beginTransaction(); try{ if($productTemplate['product_type']==1){ if($productTemplate['target_type']==1){ $this->sConn->createCommand("update product_class_set set wrong_book=0 where wrong_book='{$id}'")->execute(); }if($productTemplate['target_type']==2){ $this->sConn->createCommand("update product_student_set set wrong_book=0 where wrong_book='{$id}'")->execute(); } }elseif($productTemplate['product_type']==2){ if($productTemplate['target_type']==1){ $this->sConn->createCommand("update product_class_set set isp=0 where isp='{$id}'")->execute(); }if($productTemplate['target_type']==2){ $this->sConn->createCommand("update product_student_set set isp=0 where isp='{$id}'")->execute(); } }elseif($productTemplate['product_type']==3){ if($productTemplate['target_type']==1){ $this->sConn->createCommand("update product_class_set set wb_isp=0 where wb_isp='{$id}'")->execute(); }if($productTemplate['target_type']==2){ $this->sConn->createCommand("update product_student_set set wb_isp=0 where wb_isp='{$id}'")->execute(); } }else{ if($productTemplate['target_type']==1){ $this->sConn->createCommand("update product_class_set set template_id=0 where template_id='{$id}'")->execute(); }if($productTemplate['target_type']==2){ $this->sConn->createCommand("update product_student_set set template_id=0 where template_id='{$id}'")->execute(); } } $this->sConn->createCommand("delete from product_template where template_id='{$id}'")->execute(); $trans->commit(); $result['status'] = 1; $result['msg'] = "删除成功"; }catch (Exception $e){ $trans->rollBack(); $result['status'] = 0; $result['msg'] = "删除失败"; } exit(json_encode($result)); } //删除模板之前预判断 //返回值 :1正常可删除 -1 默认模板 -2 已有使用 0 参数异常 public function actionBeforeDelTemplate(){ $id = intval(Req::post('id')); $result['status'] = 0; if(!$id ){ $result['msg']='请选择模板'; exit(json_encode($result)); } $productTemplate=$this->sConn->createCommand("select template_id,is_default,product_type,target_type from product_template where template_id='{$id}'")->queryRow(); if(!$productTemplate){ $result['msg']='模板id不正确'; exit(json_encode($result)); } if($productTemplate['is_default']==1){ $result['status'] = -1; exit(json_encode($result)); } if($productTemplate['product_type']==1){ if($productTemplate['target_type']==1){ $used=$this->sConn->createCommand("select class_id from product_class_set where wrong_book='{$id}'")->queryRow(); }if($productTemplate['target_type']==2){ $used=$this->sConn->createCommand("select class_id from product_student_set where wrong_book='{$id}'")->queryRow(); } }elseif($productTemplate['product_type']==2){ if($productTemplate['target_type']==1){ $used=$this->sConn->createCommand("select class_id from product_class_set where isp='{$id}'")->queryRow(); }if($productTemplate['target_type']==2){ $used=$this->sConn->createCommand("select class_id from product_student_set where isp='{$id}'")->queryRow(); } }elseif($productTemplate['product_type']==3){ if($productTemplate['target_type']==1){ $used=$this->sConn->createCommand("select class_id from product_class_set where wb_isp='{$id}'")->queryRow(); }if($productTemplate['target_type']==2){ $used=$this->sConn->createCommand("select class_id from product_student_set where wb_isp='{$id}'")->queryRow(); } }else{ if($productTemplate['target_type']==1){ $used=$this->sConn->createCommand("select class_id from product_class_set where template_id='{$id}'")->queryRow(); }if($productTemplate['target_type']==2){ $used=$this->sConn->createCommand("select class_id from product_student_set where template_id='{$id}'")->queryRow(); } } if($used){ $result['status'] = -2; exit(json_encode($result)); } $result['status'] = 1; exit(json_encode($result)); } }