123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <?php
- class AssistSchoolController extends AssistController
- {
- public function actionIndex()
- {
- $provinceId = (int)Req::get('province_id');
- $cityId = (int)Req::get('city_id');
- $areaId = (int)Req::get('area_id');
- $schoolName = Req::get('school_name');
- $page = (int)Req::get('page');
- //读取所有省份,用于搜索
- $provinceList=BusinessRegion::model()->findAll("parent_id=1");
- if(!$page) $page=1;
- $where = array();
- $condition=array();
- if($schoolName){
- $where[]= " school_name like '%".$schoolName."%' ";
- $condition['school_name']=$schoolName;
- }else{
- if ($provinceId) {
- $where[]= " province_id='{$provinceId}'";
- $condition['province_id']=$provinceId;
- }
- if ($cityId) {
- $where[]= " city_id='{$cityId}'";
- $condition['city_id']=$cityId;
- }
- if ($areaId) {
- $where[]= " area_id='{$areaId}'";
- $condition['area_id']=$areaId;
- }
- }
- //读取学校开关
- $setting=AssistSetting::model()->getAssistSetting();
- if($setting){
- $acceptSchoolOpen=$setting['accept_school_open'];
- }else{
- $acceptSchoolOpen=0;
- }
- $schoolIds=array();
- if($where){
- $schoolIds=BusinessSchool::model()->getSchoolIdByCondition($where);
- if(!$schoolIds){
- $data=array(
- 'pages' => array(),
- 'dataList' => array(),
- 'province'=>$provinceList,
- 'acceptSchoolOpen'=>$acceptSchoolOpen,
- 'condition' =>$condition,
- );
- // debug($data);
- return $this->render('list', $data);
- }
- }
- $AList=new AWhiteList();
- // 任务列表
- $totalCount = $AList->countSchool($schoolIds);
- $pageLimit=10;
- $pages['page']=$page;
- $pages['totalPage']=ceil($totalCount/$pageLimit);
- $pages['total']=$totalCount;
- //$pages = new Pagination(['totalCount' => $totalCount, 'pageSize' => 10]);
- //$dataList=ATask::model()->find(implode(' and ',$where),$param)->offset($pages->offset)->limit($pages->limit)->asArray()->all();
- $dataList=$AList->getList($schoolIds,$page,$pageLimit);
- if($dataList){
- foreach ($dataList as $key => $val){
- //读取省市区
- $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$val['school_id']));
- if($schoolInfo){
- $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
- $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
- $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
- if(isset($province->region_name)){
- $dataList[$key]['province']=$province->region_name;
- }else{
- $dataList[$key]['province']='';
- }
- if(isset($city->region_name)){
- $dataList[$key]['city']=$city->region_name;
- }else{
- $dataList[$key]['city']='';
- }
- if(isset($area->region_name)){
- $dataList[$key]['area']=$area->region_name;
- }else{
- $dataList[$key]['area']='';
- }
- }
- //读取学管
- $coachInfo=BusinessCoach::model()->find("school_id=:sid",array(':sid'=>$val['school_id']));
- if($coachInfo){
- $dataList[$key]['coach']=$coachInfo->real_name.'-'.$coachInfo->telephone;
- }else{
- $dataList[$key]['coach']='-';
- }
- }
- }
- $data=array(
- 'pages' => $pages,
- 'dataList' => $dataList,
- 'province'=>$provinceList,
- 'acceptSchoolOpen'=>$acceptSchoolOpen,
- 'condition' =>$condition,
- );
- return $this->render('list', $data);
- }
- public function actionSearchSchool(){
- $provinceId = (int)Req::post('province_id');
- $cityId = (int)Req::post('city_id');
- $areaId = (int)Req::post('area_id');
- $schoolName = Req::post('school_name');
- $page = (int)Req::post('page');
- if(!$page) $page=1;
- $where = array();
- if ($schoolName) {
- $where[]= " school_name like '%".$schoolName."%' ";
- }else{
- if ($provinceId) {
- $where[]= " province_id='{$provinceId}'";
- }
- if ($cityId) {
- $where[]= " city_id='{$cityId}'";
- }
- if ($areaId) {
- $where[]= " area_id='{$areaId}'";
- }
- }
- $whiteList=new AWhiteList();
- $schoolIds=$whiteList->getAllSchoolIds();
-
- // if($schoolIds){
- // $where[]= " school_id not in(".implode(',',$schoolIds).")";
- // }
- $where[]="client<>2 and status=0 ";
- $AList=new BusinessSchool();
- // 学校列表
- $totalCount = $AList->countSchool($where);
- $pageLimit=6;
- $pages['page']=$page;
- $pages['totalPage']=ceil($totalCount/$pageLimit);
- $pages['total']=$totalCount;
- $dataList=$AList->getList($where,$page,$pageLimit);
- $html='';
- if($dataList){
- $i=($page-1)*6+1;
- foreach ($dataList as $key => $val){
- $province=BusinessRegion::model()->findByPk($val['province_id']);
- $city=BusinessRegion::model()->findByPk($val['city_id']);
- $area=BusinessRegion::model()->findByPk($val['area_id']);
- $html.='<tr>';
- $html.='<td>'.$i.'</td>';
- $html.='<td>'.$val['school_name'].'</td>';
- if(isset($province->region_name)){
- $html.='<td>'.$province->region_name.'</td>';
- }else{
- $html.='<td></td>';
- }
- if(isset($city->region_name)){
- $html.='<td>'.$city->region_name.'</td>';
- }else{
- $html.='<td></td>';
- }
- if(isset($area->region_name)){
- $html.='<td>'.$area->region_name.'</td>';
- }else{
- $html.='<td></td>';
- }
-
- if(in_array($val['school_id'],$schoolIds)){
- $html.='<td class="control-school">添加</td>';
- }else{
- $html.='<td class="control-school"><a href="#" rel="'.$val['school_id'].'" name="'.$val['school_name'].'" class="theme addSchoolList"><i></i>添加</a></td>';
- }
- $html.='</tr>';
- $i++;
- }
- }
- $pageHtml=' <ul id="yw1" class="yiiPager">';
- $StartPage=$pages['page']-2;
- $EndPage=$pages['page']+2;
- if($StartPage<1){
- $StartPage=1;
- }
- if($EndPage>$pages['totalPage']){
- $EndPage=$pages['totalPage'];
- }
- if($pages['page']>1){
- $pageHtml.='<li class="previous page"><a href="#" rel="'.($pages['page']-1).'">上一页</a></li>';
- }
- for($i=$StartPage;$i<=$EndPage;$i++){
- if($pages['page']==$i){
- $pageHtml.= '<li class="page selected"><a href="#">'.$i.'</a></li>';
- }else{
- $pageHtml.= '<li class="page"><a href="#" rel="'.$i.'">'.$i.'</a></li>';
- }
- }
- if($pages['page']<$pages['totalPage']){
- $pageHtml.= '<li class="previous page"><a href="#" rel="'.($pages['page']+1).'">下一页</a></li>';
- }
- $pageHtml.="</ul>";
- $pageHtml.=" 共:".$totalCount."条";
- $data=array(
- 'pages'=>$pageHtml,
- 'list'=>$html
- );
- $return['status']=1;
- $return['msg']='读取';
- $return['data']=$data;
- exit(json_encode($return));
- }
- public function actionGetRegion(){
- $parentId=(int)Req::post('parent_id');
- $province=BusinessRegion::model()->findAll("parent_id=:pid",array(':pid'=>$parentId));
- $html='<option value="0">全部</option>';
- if($province){
- foreach ($province as $val){
- $html.='<option value="'.$val->region_id.'">'.$val->region_name.'</option>';
- }
- }
- $return['status']=1;
- $return['msg']='读取';
- $return['data']=$html;
- exit(json_encode($return));
- }
- //学校发送开启关闭
- public function actionSwitch(){
- $value=(int)Req::post('value');
- $return['status']=0;
- $data=array(
- 'accept_school_open'=>$value,
- );
- $rs=AssistSetting::model()->updateAssistSchoolSetting($data);
- if($rs){
- $return['status']=1;
- $return['msg']='设置成功';
- exit(json_encode($return));
- }else{
- $return['msg']='设置失败';
- exit(json_encode($return));
- }
- }
- //添加学校白名单
- public function actionAddWhiteList(){
- $school_id=(int)Req::post('school_id');
- $school_name=Req::post('school_name');
- $AList=new AWhiteList();
- if($AList->addSchool($school_id,$school_name)){
- $return['status']=1;
- $return['msg']='设置成功';
- exit(json_encode($return));
- }else{
- $return['status']=0;
- $return['msg']='设置失败';
- exit(json_encode($return));
- }
- }
- //移除学校名单
- public function actionRemove(){
- $school_id=(int)Req::post('school_id');
- if(!$school_id) {
- $return['status']=0;
- $return['msg']='学校id不能为空';
- exit(json_encode($return));
- }
- $AList=new AWhiteList();
-
- if($AList->deleteAll('school_id=:sid',array(':sid'=>$school_id))){
- $return['status']=1;
- $return['msg']='移除成功';
- exit(json_encode($return));
- }else{
- $return['status']=0;
- $return['msg']='移除失败';
- exit(json_encode($return));
- }
- }
- }
|