123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/12
- * Time: 上午10:49
- */
- //户型,资讯,相册 ,周边配套
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use backend\server\UploadFile;
- use common\models\CategoryHousetype as HouseType;
- use common\models\CategoryHousetype;
- use Yii;
- //use yii\filters\HostControl;
- use common\models\CategoryNews;
- use common\models\CategoryAlbum;
- use common\models\CategoryFacilities;
- class DictionaryController extends CommonController
- {
- // ===================================户型===========================================
- /*
- * 户型显示数据页面
- * */
- public function actionHousetype()
- {
- return $this->render('housetype');
- }
- /*
- * 户型获取数据
- * */
- public function actionHousetypeform()
- {
- $model = new HouseType();
- $row = $model->getList(Yii::$app->request->post());
- if ($row != null) {
- foreach ($row as &$val) {
- $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
- $val['update_at'] = date('Y-m-d H:i', $val['update_at']);
- }
- return Help::JsonData(0, '成功', $model->Total(), $row);
- }
- }
- /*
- * 添加户型页面
- * */
- public function actionHousetypeadd()
- {
- return $this->render('housetypeadd');
- }
- /*
- * 添加户型数据
- * */
- public function actionHousetypeaddform()
- {
- $model = new HouseType();
- $model->load(Yii::$app->request->post('data'), '');
- if (!$model->validate()) return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
- if ($model->save() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
- return Help::JsonCode(Help::ERROR, '添加失败');
- }
- /*
- * 修改户型界面
- * */
- public function actionHousetypeedit()
- {
- $model = new HouseType();
- $model->id = Yii::$app->request->get('id');
- $row = $model->getOne();
- if ($row != null) {
- return $this->render('housetypeedit', ['model' => $row]);
- }
- }
- /*
- * 修改户型数据
- * */
- public function actionHousetypeeditform()
- {
- $model = new HouseType();
- $model->load(Yii::$app->request->post('data'), '');
- if (!$model->validate()) return Help::JsonCode(Help::SUCCESS, '修改失败', $model->errors);
- $row = $model->FindById(Yii::$app->request->post('data')['id']);
- if ($row != null) {
- $row->huxing_name = $model->huxing_name;
- $row->sort = $model->sort;
- $row->state = $model->state;
- if ($row->save() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
- }
- return Help::JsonCode(Help::ERROR, '修改失败');
- }
- /*
- * 删除户型
- * */
- public function actionHosttypedel()
- {
- $model = new HouseType();
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- $row->del = 2;
- if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '删除成功');
- }
- return Help::JsonCode(Help::ERROR, '删除失败');
- }
- /*
- * 户型审核上架
- * */
- public function actionHousetypestate()
- {
- $input = Yii::$app->request->post();
- $query = CategoryHousetype::findOne($input['id']);
- if ($query != null) {
- if ($query->state == 1) {
- $query->state = 2;
- $msg = '下架成功';
- } else {
- $query->state = 1;
- $msg = '上架成功';
- }
- if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, $msg);
- }
- return Help::JsonCode(Help::ERROR, $msg);
- }
- /*
- * 户型排序
- * */
- public function actionHousetypesort()
- {
- $input = Yii::$app->request->post();
- $query = CategoryHousetype::findOne($input['id']);
- if ($query != null) {
- if (!is_numeric($input['sort'])) {
- return Help::JsonCode(Help::ERROR, '请输入数字');
- }
- $query->sort = $input['sort'];
- if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, '排序成功');
- }
- return Help::JsonCode(Help::ERROR, '排序失败');
- }
- // ===================================资讯===========================================
- /*
- * 资讯列表显示页面
- * */
- public function actionNews()
- {
- return $this->render('news');
- }
- /*
- * 资讯列表数据
- * */
- public function actionNewsform()
- {
- $model = new CategoryNews();
- $rows = $model->getList(Yii::$app->request->post());
- if ($rows != null) {
- $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['newsthumb'];
- foreach ($rows as &$val) {
- $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
- $val['update_at'] = date('Y-m-d H:i', $val['update_at']);
- // $val['recommend'] = Yii::$app->params['RecommendedState'][$val['recommend']];
- $val['img'] = $imgUrl . $val['img'];
- }
- return Help::JsonData(0, '成功', $model->Total(), $rows);
- }
- }
- /*
- * 添加资讯页面
- * */
- public function actionNewsadd()
- {
- return $this->render('newsadd');
- }
- /*
- * 添加资讯分类数据
- * */
- public function actionNewsaddform()
- {
- $model = new CategoryNews();
- $model->load(Yii::$app->request->post(), '');
- if ($model) {
- if (!$model->validate()) return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
- $url = Yii::$app->params['img_url']['news'];
- $img = UploadFile::InstanceImgName('img', $url);
- if (is_string($img)) {
- $model->img = $img;
- }
- if ($model->insert() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
- }
- return Help::JsonCode(Help::Error, '添加失败');
- }
- /*
- * 资讯修改页面
- * */
- public function actionNewsedit()
- {
- $model = new CategoryNews();
- $row = $model->FindById(Yii::$app->request->get('id'));
- if ($row != null) {
- $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['newsthumb'];
- $row['img'] = $imgUrl . $row['img'];
- return $this->render('newsedit', ['model' => $row]);
- }
- }
- /*
- * 资讯修改数据
- * */
- public function actionNewseditform()
- {
- $model = new CategoryNews();
- $model->load(Yii::$app->request->post(), '');
- if (!$model->validate()) return Help::JsonCode(Help::ERROR, '修改失败', $model->errors);
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- $row->setAttributes($model->attributes);
- $url = Yii::$app->params['img_url']['news'];
- $img = UploadFile::InstanceImgName('img', $url);
- if (is_string($img)) {
- UploadFile::delImg($url, $row->img);
- $row->img = $img;
- }
- if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
- }
- return Help::JsonCode(Help::ERROR, '修改失败');
- }
- /*
- * 资讯删除
- * */
- public function actionNewsdel()
- {
- $model = new CategoryNews();
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- $row->del = 2;
- if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '删除成功');
- }
- return Help::JsonCode(Help::ERROR, '删除失败');
- }
- //资讯审核
- public function actionNewsstate()
- {
- $model = new CategoryNews();
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- if ($row->state == 1) {
- $row->state = 2;
- } else {
- $row->state = 1;
- }
- if ($row->update(false) == true) return Help::JsonCode(Help::SUCCESS, '审核成功');
- }
- return Help::JsonCode(Help::ERROR, '审核失败');
- }
- /*
- * 2020.6.24 lyy 资讯设置排序
- * */
- public function actionNewssetsort()
- {
- $model = new CategoryNews();
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- $row->sort = Yii::$app->request->post('sort');
- if ($row->update(false) == true) return Help::JsonCode(Help::SUCCESS, '设置成功');
- }
- return Help::JsonCode(Help::ERROR, '设置失败');
- }
- // ===================================相册===========================================
- /*
- * 相册分类显示页面
- * */
- public function actionPhotoalbum()
- {
- return $this->render('photoalbum');
- }
- /*
- * 相册分类数据
- * */
- public function actionPhotoalbumform()
- {
- $model = new CategoryAlbum();
- $rows = $model->getList(Yii::$app->request->post());
- if ($rows != null) {
- foreach ($rows as &$val) {
- $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
- $val['update_at'] = date('Y-m-d H:i', $val['update_at']);
- }
- return Help::JsonData(0, '成功', $model->Total(), $rows);
- }
- return Help::JsonCode(Help::ERROR, '暂无数据');
- }
- /*
- * 添加相册分类页面
- * */
- public function actionPhotoalbumadd()
- {
- return $this->render('photoalbumadd');
- }
- /*
- * 添加相册分类数据
- * */
- public function actionPhotoalbumaddform()
- {
- $model = new CategoryAlbum();
- $model->load(Yii::$app->request->post('data'), '');
- if (!$model->validate()) return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
- if ($model->insert() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
- return Help::JsonCode(Help::ERROR, '添加失败');
- }
- /*
- * 修改相册分类页面
- * */
- public function actionPhotoalbumedit()
- {
- $model = new CategoryAlbum();
- $row = $model->FindById(Yii::$app->request->get('id'));
- if ($row != null) {
- return $this->render('photoalbumedit', ['model' => $row]);
- }
- }
- /*
- *修改相册分类数据
- * */
- public function actionPhotoalbumeditform()
- {
- $model = new CategoryAlbum();
- $model->load(Yii::$app->request->post('data'), '');
- if (!$model->validate()) return Help::JsonCode(Help::ERROR, '修改失败', $model->errors);
- $row = $model->FindById(Yii::$app->request->post('data')['id']);
- $row->name = $model->name;
- if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
- return Help::JsonCode(Help::ERROR, '修改失败');
- }
- /*
- * 删除相册分类
- * */
- public function actionPhotoalbumdel()
- {
- $model = new CategoryAlbum();
- $input = Yii::$app->request->post();
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- switch ($input['type']) {
- case 'del':
- $row->del = 2;
- $msg = '删除成功';
- break;
- case 'is_show':
- $row->is_show = $input['is_show'];
- if ($input['is_show'] == 2) {
- $msg = '下架成功';
- } else {
- $msg = '上架成功';
- }
- break;
- case 'sort':
- $row->sort = intval($input['sort']);
- $msg = '排序成功';
- break;
- }
- if ($row->save() == true) return Help::JsonCode(Help::SUCCESS, Yii::t('app', $msg));
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', '操作失败'));
- }
- // ===================================周边配套===========================================
- /*
- * 周边配套列表显示页面
- * */
- public function actionFacilities()
- {
- return $this->render('facilities');
- }
- /*
- * 周边配套列表数据
- * */
- public function actionFacilitiesform()
- {
- $model = new CategoryFacilities();
- $rows = $model->getList(Yii::$app->request->post());
- if ($rows != null) {
- foreach ($rows as &$val) {
- $val['create_at'] = date('Y-m-d', $val['create_at']);
- }
- return Help::JsonData(0, '成功', $model->Total(), $rows);
- }
- }
- /*
- * 周边配套数据添加页面
- * */
- public function actionFacilitiesadd()
- {
- return $this->render('facilitiesadd');
- }
- /*
- * 周边配套数据添加
- * */
- public function actionFacilitiesaddform()
- {
- $model = new CategoryFacilities();
- $model->scenario = 'add';
- $row = $model->Authenticator(Yii::$app->request->post());
- if (is_array($row)) return Help::JsonCode(Help::ERROR, '添加失败', $row);
- $url = Yii::$app->params['img_url']['facilities'];
- $img = \backend\server\UploadFile::InstanceImgName('img', $url);
- $imga = \backend\server\UploadFile::InstanceImgName('mobile_img', $url);
- $imgb = \backend\server\UploadFile::InstanceImgName('map_img', $url);
- if ($img != false) $row->img = $img;
- if ($imga != false) $row->mobile_img = $imga;
- if ($imgb != false) $row->map_img = $imgb;
- if ($row->insert() == true) return Help::JsonCode(Help::SUCCESS, '添加成功', $row);
- }
- /*
- * 周边配套修改页面
- * */
- public function actionFacilitiessave()
- {
- $model = new CategoryFacilities();
- $row = $model->FindById(Yii::$app->request->get('id'));
- if ($row != null) {
- if (!empty($row['img'])) {
- $row['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['facilities'] . $row['img'];
- }
- if (!empty($row['mobile_img'])) {
- $row['mobile_img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['facilities'] . $row['mobile_img'];
- }
- if (!empty($row['map_img'])) {
- $row['map_img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['facilities'] . $row['map_img'];
- }
- return $this->render('facilitiessave', ['model' => $row]);
- }
- }
- /*
- * 周边配套修改数据
- * */
- public function actionFacilitiessaveform()
- {
- $model = new CategoryFacilities();
- $input = Yii::$app->request->post();
- $check = $model->Authenticator($input);
- if (is_array($check)) return Help::JsonCode(Help::ERROR, '操作失败', $check);
- $row = $model->FindById($input['id']);
- if ($row != null) {
- $url = Yii::$app->params['img_url']['facilities'];
- $img = \backend\server\UploadFile::InstanceImgName('img', $url);
- $imga = \backend\server\UploadFile::InstanceImgName('mobile_img', $url);
- $imgb = \backend\server\UploadFile::InstanceImgName('map_img', $url);
- if ($img != false) {
- \backend\server\UploadFile::delImg($url, $row->img);
- $row->img = $img;
- }
- if ($imga != false) {
- \backend\server\UploadFile::delImg($url, $row->mobile_img);
- $row->mobile_img = $imga;
- }
- if ($imgb != false) {
- \backend\server\UploadFile::delImg($url, $row->map_img);
- $row->map_img = $imgb;
- }
- $save = Help::SetAttr($input, $check, $row);
- if ($save->save() == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
- }
- }
- /*
- * 周边配套删除数据
- * */
- public function actionFacilitiesdel()
- {
- $model = new CategoryFacilities();
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- // $url = Yii::$app->params['img_url']['facilities'];
- // \backend\server\UploadFile::delImg($url,$row->img);
- // \backend\server\UploadFile::delImg($url,$row->mobile_img);
- // \backend\server\UploadFile::delImg($url,$row->map_img);
- $row->del = 2;
- if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, '操作成功');
- }
- return Help::JsonCode(Help::ERROR, '操作失败');
- }
- /*
- * 周边配套审核上架
- * */
- public function actionFacilitiesstate()
- {
- $model = new CategoryFacilities();
- $input = Yii::$app->request->post();
- $query = $model->FindById($input['id']);
- if ($query != null) {
- if ($query->is_show == 1) {
- $query->is_show = 2;
- $msg = '下架成功';
- } else {
- $query->is_show = 1;
- $msg = '上架成功';
- }
- if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, $msg);
- }
- return Help::JsonCode(Help::ERROR, $msg);
- }
- /*
- * 周边配套
- * */
- public function actionFacilitiessort()
- {
- $input = Yii::$app->request->post();
- $query = CategoryFacilities::findOne($input['id']);
- if ($query != null) {
- if (!is_numeric($input['sort'])) {
- return Help::JsonCode(Help::ERROR, '请输入数字');
- }
- $query->sort = $input['sort'];
- if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, '排序成功');
- }
- return Help::JsonCode(Help::ERROR, '排序失败');
- }
- }
|