AssistSchoolController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. class AssistSchoolController extends AssistController
  3. {
  4. public function actionIndex()
  5. {
  6. $provinceId = (int)Req::get('province_id');
  7. $cityId = (int)Req::get('city_id');
  8. $areaId = (int)Req::get('area_id');
  9. $schoolName = Req::get('school_name');
  10. $page = (int)Req::get('page');
  11. //读取所有省份,用于搜索
  12. $provinceList=BusinessRegion::model()->findAll("parent_id=1");
  13. if(!$page) $page=1;
  14. $where = array();
  15. $condition=array();
  16. if($schoolName){
  17. $where[]= " school_name like '%".$schoolName."%' ";
  18. $condition['school_name']=$schoolName;
  19. }else{
  20. if ($provinceId) {
  21. $where[]= " province_id='{$provinceId}'";
  22. $condition['province_id']=$provinceId;
  23. }
  24. if ($cityId) {
  25. $where[]= " city_id='{$cityId}'";
  26. $condition['city_id']=$cityId;
  27. }
  28. if ($areaId) {
  29. $where[]= " area_id='{$areaId}'";
  30. $condition['area_id']=$areaId;
  31. }
  32. }
  33. //读取学校开关
  34. $setting=AssistSetting::model()->getAssistSetting();
  35. if($setting){
  36. $acceptSchoolOpen=$setting['accept_school_open'];
  37. }else{
  38. $acceptSchoolOpen=0;
  39. }
  40. $schoolIds=array();
  41. if($where){
  42. $schoolIds=BusinessSchool::model()->getSchoolIdByCondition($where);
  43. if(!$schoolIds){
  44. $data=array(
  45. 'pages' => array(),
  46. 'dataList' => array(),
  47. 'province'=>$provinceList,
  48. 'acceptSchoolOpen'=>$acceptSchoolOpen,
  49. 'condition' =>$condition,
  50. );
  51. // debug($data);
  52. return $this->render('list', $data);
  53. }
  54. }
  55. $AList=new AWhiteList();
  56. // 任务列表
  57. $totalCount = $AList->countSchool($schoolIds);
  58. $pageLimit=10;
  59. $pages['page']=$page;
  60. $pages['totalPage']=ceil($totalCount/$pageLimit);
  61. $pages['total']=$totalCount;
  62. //$pages = new Pagination(['totalCount' => $totalCount, 'pageSize' => 10]);
  63. //$dataList=ATask::model()->find(implode(' and ',$where),$param)->offset($pages->offset)->limit($pages->limit)->asArray()->all();
  64. $dataList=$AList->getList($schoolIds,$page,$pageLimit);
  65. if($dataList){
  66. foreach ($dataList as $key => $val){
  67. //读取省市区
  68. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$val['school_id']));
  69. if($schoolInfo){
  70. $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
  71. $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
  72. $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
  73. if(isset($province->region_name)){
  74. $dataList[$key]['province']=$province->region_name;
  75. }else{
  76. $dataList[$key]['province']='';
  77. }
  78. if(isset($city->region_name)){
  79. $dataList[$key]['city']=$city->region_name;
  80. }else{
  81. $dataList[$key]['city']='';
  82. }
  83. if(isset($area->region_name)){
  84. $dataList[$key]['area']=$area->region_name;
  85. }else{
  86. $dataList[$key]['area']='';
  87. }
  88. }
  89. //读取学管
  90. $coachInfo=BusinessCoach::model()->find("school_id=:sid",array(':sid'=>$val['school_id']));
  91. if($coachInfo){
  92. $dataList[$key]['coach']=$coachInfo->real_name.'-'.$coachInfo->telephone;
  93. }else{
  94. $dataList[$key]['coach']='-';
  95. }
  96. }
  97. }
  98. $data=array(
  99. 'pages' => $pages,
  100. 'dataList' => $dataList,
  101. 'province'=>$provinceList,
  102. 'acceptSchoolOpen'=>$acceptSchoolOpen,
  103. 'condition' =>$condition,
  104. );
  105. return $this->render('list', $data);
  106. }
  107. public function actionSearchSchool(){
  108. $provinceId = (int)Req::post('province_id');
  109. $cityId = (int)Req::post('city_id');
  110. $areaId = (int)Req::post('area_id');
  111. $schoolName = Req::post('school_name');
  112. $page = (int)Req::post('page');
  113. if(!$page) $page=1;
  114. $where = array();
  115. if ($schoolName) {
  116. $where[]= " school_name like '%".$schoolName."%' ";
  117. }else{
  118. if ($provinceId) {
  119. $where[]= " province_id='{$provinceId}'";
  120. }
  121. if ($cityId) {
  122. $where[]= " city_id='{$cityId}'";
  123. }
  124. if ($areaId) {
  125. $where[]= " area_id='{$areaId}'";
  126. }
  127. }
  128. $whiteList=new AWhiteList();
  129. $schoolIds=$whiteList->getAllSchoolIds();
  130. // if($schoolIds){
  131. // $where[]= " school_id not in(".implode(',',$schoolIds).")";
  132. // }
  133. $where[]="client<>2 and status=0 ";
  134. $AList=new BusinessSchool();
  135. // 学校列表
  136. $totalCount = $AList->countSchool($where);
  137. $pageLimit=6;
  138. $pages['page']=$page;
  139. $pages['totalPage']=ceil($totalCount/$pageLimit);
  140. $pages['total']=$totalCount;
  141. $dataList=$AList->getList($where,$page,$pageLimit);
  142. $html='';
  143. if($dataList){
  144. $i=($page-1)*6+1;
  145. foreach ($dataList as $key => $val){
  146. $province=BusinessRegion::model()->findByPk($val['province_id']);
  147. $city=BusinessRegion::model()->findByPk($val['city_id']);
  148. $area=BusinessRegion::model()->findByPk($val['area_id']);
  149. $html.='<tr>';
  150. $html.='<td>'.$i.'</td>';
  151. $html.='<td>'.$val['school_name'].'</td>';
  152. if(isset($province->region_name)){
  153. $html.='<td>'.$province->region_name.'</td>';
  154. }else{
  155. $html.='<td></td>';
  156. }
  157. if(isset($city->region_name)){
  158. $html.='<td>'.$city->region_name.'</td>';
  159. }else{
  160. $html.='<td></td>';
  161. }
  162. if(isset($area->region_name)){
  163. $html.='<td>'.$area->region_name.'</td>';
  164. }else{
  165. $html.='<td></td>';
  166. }
  167. if(in_array($val['school_id'],$schoolIds)){
  168. $html.='<td class="control-school">添加</td>';
  169. }else{
  170. $html.='<td class="control-school"><a href="#" rel="'.$val['school_id'].'" name="'.$val['school_name'].'" class="theme addSchoolList"><i></i>添加</a></td>';
  171. }
  172. $html.='</tr>';
  173. $i++;
  174. }
  175. }
  176. $pageHtml=' <ul id="yw1" class="yiiPager">';
  177. $StartPage=$pages['page']-2;
  178. $EndPage=$pages['page']+2;
  179. if($StartPage<1){
  180. $StartPage=1;
  181. }
  182. if($EndPage>$pages['totalPage']){
  183. $EndPage=$pages['totalPage'];
  184. }
  185. if($pages['page']>1){
  186. $pageHtml.='<li class="previous page"><a href="#" rel="'.($pages['page']-1).'">上一页</a></li>';
  187. }
  188. for($i=$StartPage;$i<=$EndPage;$i++){
  189. if($pages['page']==$i){
  190. $pageHtml.= '<li class="page selected"><a href="#">'.$i.'</a></li>';
  191. }else{
  192. $pageHtml.= '<li class="page"><a href="#" rel="'.$i.'">'.$i.'</a></li>';
  193. }
  194. }
  195. if($pages['page']<$pages['totalPage']){
  196. $pageHtml.= '<li class="previous page"><a href="#" rel="'.($pages['page']+1).'">下一页</a></li>';
  197. }
  198. $pageHtml.="</ul>";
  199. $pageHtml.=" 共:".$totalCount."条";
  200. $data=array(
  201. 'pages'=>$pageHtml,
  202. 'list'=>$html
  203. );
  204. $return['status']=1;
  205. $return['msg']='读取';
  206. $return['data']=$data;
  207. exit(json_encode($return));
  208. }
  209. public function actionGetRegion(){
  210. $parentId=(int)Req::post('parent_id');
  211. $province=BusinessRegion::model()->findAll("parent_id=:pid",array(':pid'=>$parentId));
  212. $html='<option value="0">全部</option>';
  213. if($province){
  214. foreach ($province as $val){
  215. $html.='<option value="'.$val->region_id.'">'.$val->region_name.'</option>';
  216. }
  217. }
  218. $return['status']=1;
  219. $return['msg']='读取';
  220. $return['data']=$html;
  221. exit(json_encode($return));
  222. }
  223. //学校发送开启关闭
  224. public function actionSwitch(){
  225. $value=(int)Req::post('value');
  226. $return['status']=0;
  227. $data=array(
  228. 'accept_school_open'=>$value,
  229. );
  230. $rs=AssistSetting::model()->updateAssistSchoolSetting($data);
  231. if($rs){
  232. $return['status']=1;
  233. $return['msg']='设置成功';
  234. exit(json_encode($return));
  235. }else{
  236. $return['msg']='设置失败';
  237. exit(json_encode($return));
  238. }
  239. }
  240. //添加学校白名单
  241. public function actionAddWhiteList(){
  242. $school_id=(int)Req::post('school_id');
  243. $school_name=Req::post('school_name');
  244. $AList=new AWhiteList();
  245. if($AList->addSchool($school_id,$school_name)){
  246. $return['status']=1;
  247. $return['msg']='设置成功';
  248. exit(json_encode($return));
  249. }else{
  250. $return['status']=0;
  251. $return['msg']='设置失败';
  252. exit(json_encode($return));
  253. }
  254. }
  255. //移除学校名单
  256. public function actionRemove(){
  257. $school_id=(int)Req::post('school_id');
  258. if(!$school_id) {
  259. $return['status']=0;
  260. $return['msg']='学校id不能为空';
  261. exit(json_encode($return));
  262. }
  263. $AList=new AWhiteList();
  264. if($AList->deleteAll('school_id=:sid',array(':sid'=>$school_id))){
  265. $return['status']=1;
  266. $return['msg']='移除成功';
  267. exit(json_encode($return));
  268. }else{
  269. $return['status']=0;
  270. $return['msg']='移除失败';
  271. exit(json_encode($return));
  272. }
  273. }
  274. }