123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/4/19
- * Time: 上午10:52
- */
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use Yii;
- use common\models\CategoryCity;
- use backend\server\UploadFile;
- use common\models\CityDetails;
- class RoutinecityController extends CommonController
- {
- /*
- * 常规管理-区域介绍-首页
- * */
- public function actionIndex()
- {
- $model = new CategoryCity();
- $city = $model->getList([]);
- return $this->render('index',['city'=>$city]);
- }
- /*
- * 常规管理-区域介绍-首页获取数据
- * */
- public function actionIndexform()
- {
- $model = new CityDetails();
- $city = Yii::$app->request->post('city');
- if(!empty($city))
- {
- $model->city_id = $city;
- }
- $rows = $model->getList(Yii::$app->request->post());
- if($rows != null)
- {
- return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
- }
- return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
- }
- /*
- * 常规管理-区域介绍- 区域添加页面
- * */
- public function actionCityadd()
- {
- $model = new CategoryCity();
- $city = $model->getList([]);
- return $this->render('cityadd',['city'=>$city]);
- }
- /*
- * 常规管理-区域介绍- 区域添加数据
- * */
- public function actionCityaddform()
- {
- $model = new \common\models\CityDetails();
- $input = Yii::$app->request->post();
- $result = $model->Authenticator($input);
- if(is_object($result))
- {
- $url = Yii::$app->params['img_url']['city'];
- $img = UploadFile::InstanceImgName('img',$url);
- if(is_string($img))
- {
- $result->thumb = $img;
- }
- $img_bg = UploadFile::InstanceImgName('img_bg',$url);
- if(is_string($img_bg))
- {
- $result->background_img = $img_bg;
- }
- $imgs = UploadFile::InstancesImgName('imgs',$url);
- if(is_array($imgs))
- {
- $result->img = json_encode($imgs);
- }
- if($result->save(false) == true) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
- }
- return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$result);
- }
- /*
- * 常规管理-区域介绍- 区域修改页面
- * */
- public function actionCityedit()
- {
- $model = new CategoryCity();
- $city = $model->getList([]);
- $detals = new CityDetails();
- $row = $detals->FingById(Yii::$app->request->get('id'));
- $url = Yii::$app->params['httpImg']['host']. Yii::$app->params['httpImg']['city'];
- if(is_string($row['img']))
- {
- $row['img'] = json_decode($row['img']);
- }
- return $this->render('cityedit',['city'=>$city,'details'=>$row,'url'=>$url]);
- }
- /*
- * 常规管理-区域介绍- 区域修改数据
- * */
- public function actionCityeditform()
- {
- $model = new CityDetails();
- $input = Yii::$app->request->post();
- $result = $model->Authenticator($input);
- if(is_object($result))
- {
- $row = $model->FingById($input['id']);
- if($row == null) return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
- $row = Help::SetAttr($input,$model,$row);
- $url = Yii::$app->params['img_url']['city'];
- $img = UploadFile::InstanceImgName('img',$url);
- if(is_string($img))
- {
- UploadFile::delImg($url, $row->thumb);
- $row->thumb = $img;
- }
- $img_bg = UploadFile::InstanceImgName('img_bg',$url);
- if(is_string($img_bg))
- {
- UploadFile::delImg($url, $row->background_img);
- $row->background_img = $img_bg;
- }
- if(isset($input['imgsdel']) && !empty($input['imgsdel']))
- {
- $row['img'] = json_decode($row['img']);
- $arrDelImg = array_values(array_diff( $row['img'],$input['imgsdel']));
- $row->img = json_encode($arrDelImg);
- }
- $imgs = UploadFile::InstancesImgName('imgs',$url);
- if(is_array($imgs))
- {
- if(!empty($row->img))
- {
- $arrAddImg = array_merge($imgs,json_decode($row->img));
- }
- else
- {
- $arrAddImg = $imgs;
- }
- if(count($arrAddImg) > 3) return Help::JsonCode(Help::ERROR,'只能上传3张区域图集');
- // foreach ($imgs as $val)
- // {
- // UploadFile::delImg($url,$val);
- // }
- $row->img = json_encode($arrAddImg);
- }
- if(!empty($arrAddImg) && !empty($arrDelImg))
- {
- $merge = array_merge($arrAddImg,$arrDelImg);
- $merge = array_unique($merge);
- if(count($merge) >3) return Help::JsonCode(Help::ERROR,'只能上传3张区域图集');
- $row->img = json_encode($merge);
- }
- if($row->save(false) == true) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
- }
- return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'),$result);
- }
- /*
- * 常规管理-区域介绍-删除
- * */
- public function actionCitydel()
- {
- $model = new CityDetails();
- $input = Yii::$app->request->post();
- $row = $model->FingById($input['id']);
- if($row != null)
- {
- $row->del = 2;
- if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
- }
- return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
- }
- }
|