OthertelController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/3
  6. * Time: 下午5:14
  7. */
  8. namespace backend\controllers;
  9. use Yii;
  10. use backend\base\Help;
  11. use backend\base\CommonController;
  12. use common\models\CategoryTel;
  13. use common\models\CategoryTelCity;
  14. use common\models\CategoryCity;
  15. class OthertelController extends CommonController
  16. {
  17. /*
  18. * 其他管理-电话管理-首页
  19. * */
  20. public function actionHome()
  21. {
  22. $cityModel = $this->City();
  23. $idarr = [];
  24. foreach ($cityModel as $key=>$val){
  25. if($val['abroad']==2){
  26. $idarr[] = $val['id'];
  27. unset($cityModel[$key]);
  28. }
  29. }
  30. $cityModel[] = ['id'=>implode(',',$idarr),'city_name'=>'海外'];
  31. return $this->render('home',['city'=>$cityModel]);
  32. }
  33. /*
  34. * 其他管理-电话管理-首页数据
  35. * */
  36. public function actionHomeform()
  37. {
  38. $model = new CategoryTel();
  39. $input = Yii::$app->request->post();
  40. $rows = $model->getList($input);
  41. if($rows != null)
  42. {
  43. return Help::JsonData(0,'成功',0,$rows);
  44. }
  45. return Help::JsonCode(Help::ERROR,'暂无数据');
  46. }
  47. /*
  48. * 其他管理-电话管理-修改电话数据
  49. * */
  50. public function actionEditform()
  51. {
  52. $model = new CategoryTel();
  53. $input = Yii::$app->request->post('data');
  54. $input['name'] =Yii::$app->request->post('data')['name'];
  55. $input['tel'] =trim(Yii::$app->request->post('data')['tel'],',');
  56. $rows = $model->Authenticator($input);
  57. if(is_object($rows))
  58. {
  59. $row = $model->FindById($input['id']);
  60. if($row != null)
  61. {
  62. $authMoel = Help::SetAttr($input,$rows,$row);
  63. if($authMoel->save()) return Help::JsonCode(Help::SUCCESS,'修改成功');
  64. }
  65. }
  66. return Help::JsonCode(Help::ERROR,'修改失败',$rows);
  67. }
  68. /*
  69. * 其他管理-电话管理-修改电话页面
  70. * */
  71. public function actionEdit()
  72. {
  73. $model = new CategoryTel();
  74. $row = $model->FindById(Yii::$app->request->get('id'));
  75. $cityModel = $this->City();
  76. if($row != null) return $this->render('edit',['model'=>$row,'city'=>$cityModel]);
  77. }
  78. /*
  79. * 其他管理-电话管理-添加电话页面
  80. * */
  81. public function actionAdd()
  82. {
  83. $cityModel = $this->City();
  84. return $this->render('add',['city'=>$cityModel]);
  85. }
  86. /*
  87. * 其他管理-电话管理-添加电话数据
  88. * */
  89. public function actionAddform()
  90. {
  91. $model = new CategoryTel();
  92. $input['name'] =Yii::$app->request->post('data')['name'];
  93. $input['tel'] =trim(Yii::$app->request->post('data')['tel'],',');
  94. $rows = $model->Authenticator($input);
  95. if(is_object($rows))
  96. {
  97. if($rows->save() == true) return Help::JsonCode(Help::SUCCESS,'添加成功');
  98. }
  99. return Help::JsonCode(Help::ERROR,'添加失败',$rows);
  100. }
  101. /*
  102. * 其他管理-电话管理-删除
  103. * */
  104. public function actionDel()
  105. {
  106. $model = new CategoryTel();
  107. $row = $model->FindById(Yii::$app->request->post('id'));
  108. if($row != null)
  109. {
  110. $row->del = 2;
  111. if($row->update() == true) return Help::JsonCode(Help::SUCCESS,'删除成功');
  112. }
  113. return Help::JsonCode(Help::ERROR,'删除失败');
  114. }
  115. /*
  116. * 其他管理-区域电话列表显示页面
  117. * */
  118. public function actionCitytelhome()
  119. {
  120. $city = new CategoryCity();
  121. $city = $city->SortgetList([]);
  122. return $this->render('citytelhome',['city'=>$city]);
  123. }
  124. /*
  125. * 其他管理-区域电话列表数据
  126. * */
  127. public function actionCitytelhomeform()
  128. {
  129. $input = Yii::$app->request->get();
  130. $model = new CategoryCity();
  131. $query = $model->telList($input);
  132. if(!empty($query))
  133. {
  134. return Help::JsonData(0,'成功', $model->telTotal(),$query);
  135. }
  136. return Help::JsonCode(Help::ERROR,'暂无数据');
  137. }
  138. /*
  139. * 其他管理-区域电话归属
  140. * */
  141. public function actionCityascription()
  142. {
  143. $model = new CategoryTel();
  144. $rows = $model->getList();
  145. $TelCity= new \common\models\CategoryTelCity();
  146. $TelCity->cid = Yii::$app->request->get('id');
  147. $city = $TelCity->findByOne();
  148. foreach ($rows as &$val)
  149. {
  150. if($val['id'] == $city['tid']){
  151. $val['checked'] = 'checked';
  152. }
  153. }
  154. return $this->render('cityascription',['id'=>Yii::$app->request->get('id'),'tellist'=>$rows]);
  155. }
  156. /*
  157. * 其他管理-添加区域电话归属
  158. * */
  159. public function actionAddcityascription()
  160. {
  161. $model = new \common\models\CategoryTelCity();
  162. // $model->tid = Yii::$app->request->post('tid');
  163. $model->cid = Yii::$app->request->post('cid');
  164. $row = $model->findByOne();
  165. if($row != null)
  166. {
  167. $row->tid = Yii::$app->request->post('tid');
  168. $result = $row->save(false);
  169. }
  170. else
  171. {
  172. $model->tid = Yii::$app->request->post('tid');
  173. $model->cid = Yii::$app->request->post('cid');
  174. $result = $model->save();
  175. }
  176. if($result == true) return Help::JsonCode(Help::SUCCESS,'操作成功');
  177. return Help::JsonCode(Help::ERROR,'操作失败');
  178. }
  179. //-------------------------------------------------------------------------------------------------
  180. private function City()
  181. {
  182. $city = new \common\models\CategoryCity();
  183. $city->state = 1;
  184. $city->pid = 0;
  185. $cityModel = $city->getList([]);
  186. return $cityModel;
  187. }
  188. }