diff --git a/app/portal/controller/SchoolController.php b/app/portal/controller/SchoolController.php index 642c072..a6b9db5 100644 --- a/app/portal/controller/SchoolController.php +++ b/app/portal/controller/SchoolController.php @@ -45,9 +45,34 @@ class SchoolController extends WeChatBaseController{ $school_data[$key]['grade'] = Db::name('grade_class') -> where("school_id",$val['id']) -> select() -> toArray(); } //循环遍历比对 - /* foreach ($school_data as $key => $val){ - if() - }*/ + foreach ($school_data as $key => $val){ + //如果地区 学校 类型相同就进行下一步比对 + if($_POST['region']==$val['region'] && $_POST['school']==$val['school'] && $_POST['type']==$val['type']){ + foreach ($val['grade'] as $key1 => $val1){ + //循环传过来的年级 + foreach ($class_data as $key2 => $val2){ + $val2 = explode('-',$val2); + if($val2[0] == $val1['grade']){ + //将班级拆分循环装进数组 + $class_s = explode('-',$val1['class']); + for($i=$class_s[0];$i<=$class_s[1];$i++){ + $class_db[] = $i; + + } + //将传过来的班级循环 + for($j=$val2[1];$j<=$val2[2];$j++){ + $class_my[] = $j; + } + $result = array_intersect($class_db,$class_my); + $result = count($result); + if($result > 0){ + return 5; + } + } + } + } + } + } $school['uid'] = cmf_get_current_user_id(); $school['create_time'] = time(); $school['region'] = $_POST['region']; @@ -68,11 +93,7 @@ class SchoolController extends WeChatBaseController{ } }else{ - /*$data = Db::name('school') -> select() -> toArray(); - foreach ($data as $key => $val){ - $data[$key]['grade'] = Db::name('grade_class') -> where("school_id",$val['id']) -> select() -> toArray(); - } - dump($data);die;*/ + return $this -> fetch(); } diff --git a/public/themes/simpleboot3/portal/school/add_school.html b/public/themes/simpleboot3/portal/school/add_school.html index 0bf0456..aec5126 100644 --- a/public/themes/simpleboot3/portal/school/add_school.html +++ b/public/themes/simpleboot3/portal/school/add_school.html @@ -542,11 +542,16 @@ alert('请添加班级'); }else{ $.post("{:url('School/add_school')}",{school:school,type:type,region:region,str:str},function(data){ - /* if(data){ - window.location.href="{:url('School/school')}"; + if(data == 5){ + alert('学校信息重叠'); }else{ - alert('添加失败!'); - }*/ + if(data){ + window.location.href="{:url('School/school')}"; + }else{ + alert('添加失败!'); + } + } + }); } }