RoutinecityController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/19
  6. * Time: 上午10:52
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\base\Help;
  11. use Yii;
  12. use common\models\CategoryCity;
  13. use backend\server\UploadFile;
  14. use common\models\CityDetails;
  15. class RoutinecityController extends CommonController
  16. {
  17. /*
  18. * 常规管理-区域介绍-首页
  19. * */
  20. public function actionIndex()
  21. {
  22. $model = new CategoryCity();
  23. $city = $model->getList([]);
  24. return $this->render('index',['city'=>$city]);
  25. }
  26. /*
  27. * 常规管理-区域介绍-首页获取数据
  28. * */
  29. public function actionIndexform()
  30. {
  31. $model = new CityDetails();
  32. $city = Yii::$app->request->post('city');
  33. if(!empty($city))
  34. {
  35. $model->city_id = $city;
  36. }
  37. $rows = $model->getList(Yii::$app->request->post());
  38. if($rows != null)
  39. {
  40. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  41. }
  42. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  43. }
  44. /*
  45. * 常规管理-区域介绍- 区域添加页面
  46. * */
  47. public function actionCityadd()
  48. {
  49. $model = new CategoryCity();
  50. $city = $model->getList([]);
  51. return $this->render('cityadd',['city'=>$city]);
  52. }
  53. /*
  54. * 常规管理-区域介绍- 区域添加数据
  55. * */
  56. public function actionCityaddform()
  57. {
  58. $model = new \common\models\CityDetails();
  59. $input = Yii::$app->request->post();
  60. $result = $model->Authenticator($input);
  61. if(is_object($result))
  62. {
  63. $url = Yii::$app->params['img_url']['city'];
  64. $img = UploadFile::InstanceImgName('img',$url);
  65. if(is_string($img))
  66. {
  67. $result->thumb = $img;
  68. }
  69. $img_bg = UploadFile::InstanceImgName('img_bg',$url);
  70. if(is_string($img_bg))
  71. {
  72. $result->background_img = $img_bg;
  73. }
  74. $imgs = UploadFile::InstancesImgName('imgs',$url);
  75. if(is_array($imgs))
  76. {
  77. $result->img = json_encode($imgs);
  78. }
  79. if($result->save(false) == true) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  80. }
  81. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$result);
  82. }
  83. /*
  84. * 常规管理-区域介绍- 区域修改页面
  85. * */
  86. public function actionCityedit()
  87. {
  88. $model = new CategoryCity();
  89. $city = $model->getList([]);
  90. $detals = new CityDetails();
  91. $row = $detals->FingById(Yii::$app->request->get('id'));
  92. $url = Yii::$app->params['httpImg']['host']. Yii::$app->params['httpImg']['city'];
  93. if(is_string($row['img']))
  94. {
  95. $row['img'] = json_decode($row['img']);
  96. }
  97. return $this->render('cityedit',['city'=>$city,'details'=>$row,'url'=>$url]);
  98. }
  99. /*
  100. * 常规管理-区域介绍- 区域修改数据
  101. * */
  102. public function actionCityeditform()
  103. {
  104. $model = new CityDetails();
  105. $input = Yii::$app->request->post();
  106. $result = $model->Authenticator($input);
  107. if(is_object($result))
  108. {
  109. $row = $model->FingById($input['id']);
  110. if($row == null) return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  111. $row = Help::SetAttr($input,$model,$row);
  112. $url = Yii::$app->params['img_url']['city'];
  113. $img = UploadFile::InstanceImgName('img',$url);
  114. if(is_string($img))
  115. {
  116. UploadFile::delImg($url, $row->thumb);
  117. $row->thumb = $img;
  118. }
  119. $img_bg = UploadFile::InstanceImgName('img_bg',$url);
  120. if(is_string($img_bg))
  121. {
  122. UploadFile::delImg($url, $row->background_img);
  123. $row->background_img = $img_bg;
  124. }
  125. if(isset($input['imgsdel']) && !empty($input['imgsdel']))
  126. {
  127. $row['img'] = json_decode($row['img']);
  128. $arrDelImg = array_values(array_diff( $row['img'],$input['imgsdel']));
  129. $row->img = json_encode($arrDelImg);
  130. }
  131. $imgs = UploadFile::InstancesImgName('imgs',$url);
  132. if(is_array($imgs))
  133. {
  134. if(!empty($row->img))
  135. {
  136. $arrAddImg = array_merge($imgs,json_decode($row->img));
  137. }
  138. else
  139. {
  140. $arrAddImg = $imgs;
  141. }
  142. if(count($arrAddImg) > 3) return Help::JsonCode(Help::ERROR,'只能上传3张区域图集');
  143. // foreach ($imgs as $val)
  144. // {
  145. // UploadFile::delImg($url,$val);
  146. // }
  147. $row->img = json_encode($arrAddImg);
  148. }
  149. if(!empty($arrAddImg) && !empty($arrDelImg))
  150. {
  151. $merge = array_merge($arrAddImg,$arrDelImg);
  152. $merge = array_unique($merge);
  153. if(count($merge) >3) return Help::JsonCode(Help::ERROR,'只能上传3张区域图集');
  154. $row->img = json_encode($merge);
  155. }
  156. if($row->save(false) == true) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  157. }
  158. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'),$result);
  159. }
  160. /*
  161. * 常规管理-区域介绍-删除
  162. * */
  163. public function actionCitydel()
  164. {
  165. $model = new CityDetails();
  166. $input = Yii::$app->request->post();
  167. $row = $model->FingById($input['id']);
  168. if($row != null)
  169. {
  170. $row->del = 2;
  171. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  172. }
  173. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  174. }
  175. }