DictionaryController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/12
  6. * Time: 上午10:49
  7. */
  8. //户型,资讯,相册 ,周边配套
  9. namespace backend\controllers;
  10. use backend\base\CommonController;
  11. use backend\base\Help;
  12. use backend\server\UploadFile;
  13. use common\models\CategoryHousetype as HouseType;
  14. use common\models\CategoryHousetype;
  15. use Yii;
  16. //use yii\filters\HostControl;
  17. use common\models\CategoryNews;
  18. use common\models\CategoryAlbum;
  19. use common\models\CategoryFacilities;
  20. class DictionaryController extends CommonController
  21. {
  22. // ===================================户型===========================================
  23. /*
  24. * 户型显示数据页面
  25. * */
  26. public function actionHousetype()
  27. {
  28. return $this->render('housetype');
  29. }
  30. /*
  31. * 户型获取数据
  32. * */
  33. public function actionHousetypeform()
  34. {
  35. $model = new HouseType();
  36. $row = $model->getList(Yii::$app->request->post());
  37. if ($row != null) {
  38. foreach ($row as &$val) {
  39. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  40. $val['update_at'] = date('Y-m-d H:i', $val['update_at']);
  41. }
  42. return Help::JsonData(0, '成功', $model->Total(), $row);
  43. }
  44. }
  45. /*
  46. * 添加户型页面
  47. * */
  48. public function actionHousetypeadd()
  49. {
  50. return $this->render('housetypeadd');
  51. }
  52. /*
  53. * 添加户型数据
  54. * */
  55. public function actionHousetypeaddform()
  56. {
  57. $model = new HouseType();
  58. $model->load(Yii::$app->request->post('data'), '');
  59. if (!$model->validate()) return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
  60. if ($model->save() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
  61. return Help::JsonCode(Help::ERROR, '添加失败');
  62. }
  63. /*
  64. * 修改户型界面
  65. * */
  66. public function actionHousetypeedit()
  67. {
  68. $model = new HouseType();
  69. $model->id = Yii::$app->request->get('id');
  70. $row = $model->getOne();
  71. if ($row != null) {
  72. return $this->render('housetypeedit', ['model' => $row]);
  73. }
  74. }
  75. /*
  76. * 修改户型数据
  77. * */
  78. public function actionHousetypeeditform()
  79. {
  80. $model = new HouseType();
  81. $model->load(Yii::$app->request->post('data'), '');
  82. if (!$model->validate()) return Help::JsonCode(Help::SUCCESS, '修改失败', $model->errors);
  83. $row = $model->FindById(Yii::$app->request->post('data')['id']);
  84. if ($row != null) {
  85. $row->huxing_name = $model->huxing_name;
  86. $row->sort = $model->sort;
  87. $row->state = $model->state;
  88. if ($row->save() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
  89. }
  90. return Help::JsonCode(Help::ERROR, '修改失败');
  91. }
  92. /*
  93. * 删除户型
  94. * */
  95. public function actionHosttypedel()
  96. {
  97. $model = new HouseType();
  98. $row = $model->FindById(Yii::$app->request->post('id'));
  99. if ($row != null) {
  100. $row->del = 2;
  101. if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '删除成功');
  102. }
  103. return Help::JsonCode(Help::ERROR, '删除失败');
  104. }
  105. /*
  106. * 户型审核上架
  107. * */
  108. public function actionHousetypestate()
  109. {
  110. $input = Yii::$app->request->post();
  111. $query = CategoryHousetype::findOne($input['id']);
  112. if ($query != null) {
  113. if ($query->state == 1) {
  114. $query->state = 2;
  115. $msg = '下架成功';
  116. } else {
  117. $query->state = 1;
  118. $msg = '上架成功';
  119. }
  120. if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, $msg);
  121. }
  122. return Help::JsonCode(Help::ERROR, $msg);
  123. }
  124. /*
  125. * 户型排序
  126. * */
  127. public function actionHousetypesort()
  128. {
  129. $input = Yii::$app->request->post();
  130. $query = CategoryHousetype::findOne($input['id']);
  131. if ($query != null) {
  132. if (!is_numeric($input['sort'])) {
  133. return Help::JsonCode(Help::ERROR, '请输入数字');
  134. }
  135. $query->sort = $input['sort'];
  136. if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, '排序成功');
  137. }
  138. return Help::JsonCode(Help::ERROR, '排序失败');
  139. }
  140. // ===================================资讯===========================================
  141. /*
  142. * 资讯列表显示页面
  143. * */
  144. public function actionNews()
  145. {
  146. return $this->render('news');
  147. }
  148. /*
  149. * 资讯列表数据
  150. * */
  151. public function actionNewsform()
  152. {
  153. $model = new CategoryNews();
  154. $rows = $model->getList(Yii::$app->request->post());
  155. if ($rows != null) {
  156. $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['newsthumb'];
  157. foreach ($rows as &$val) {
  158. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  159. $val['update_at'] = date('Y-m-d H:i', $val['update_at']);
  160. // $val['recommend'] = Yii::$app->params['RecommendedState'][$val['recommend']];
  161. $val['img'] = $imgUrl . $val['img'];
  162. }
  163. return Help::JsonData(0, '成功', $model->Total(), $rows);
  164. }
  165. }
  166. /*
  167. * 添加资讯页面
  168. * */
  169. public function actionNewsadd()
  170. {
  171. return $this->render('newsadd');
  172. }
  173. /*
  174. * 添加资讯分类数据
  175. * */
  176. public function actionNewsaddform()
  177. {
  178. $model = new CategoryNews();
  179. $model->load(Yii::$app->request->post(), '');
  180. if ($model) {
  181. if (!$model->validate()) return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
  182. $url = Yii::$app->params['img_url']['news'];
  183. $img = UploadFile::InstanceImgName('img', $url);
  184. if (is_string($img)) {
  185. $model->img = $img;
  186. }
  187. if ($model->insert() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
  188. }
  189. return Help::JsonCode(Help::Error, '添加失败');
  190. }
  191. /*
  192. * 资讯修改页面
  193. * */
  194. public function actionNewsedit()
  195. {
  196. $model = new CategoryNews();
  197. $row = $model->FindById(Yii::$app->request->get('id'));
  198. if ($row != null) {
  199. $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['newsthumb'];
  200. $row['img'] = $imgUrl . $row['img'];
  201. return $this->render('newsedit', ['model' => $row]);
  202. }
  203. }
  204. /*
  205. * 资讯修改数据
  206. * */
  207. public function actionNewseditform()
  208. {
  209. $model = new CategoryNews();
  210. $model->load(Yii::$app->request->post(), '');
  211. if (!$model->validate()) return Help::JsonCode(Help::ERROR, '修改失败', $model->errors);
  212. $row = $model->FindById(Yii::$app->request->post('id'));
  213. if ($row != null) {
  214. $row->setAttributes($model->attributes);
  215. $url = Yii::$app->params['img_url']['news'];
  216. $img = UploadFile::InstanceImgName('img', $url);
  217. if (is_string($img)) {
  218. UploadFile::delImg($url, $row->img);
  219. $row->img = $img;
  220. }
  221. if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
  222. }
  223. return Help::JsonCode(Help::ERROR, '修改失败');
  224. }
  225. /*
  226. * 资讯删除
  227. * */
  228. public function actionNewsdel()
  229. {
  230. $model = new CategoryNews();
  231. $row = $model->FindById(Yii::$app->request->post('id'));
  232. if ($row != null) {
  233. $row->del = 2;
  234. if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '删除成功');
  235. }
  236. return Help::JsonCode(Help::ERROR, '删除失败');
  237. }
  238. //资讯审核
  239. public function actionNewsstate()
  240. {
  241. $model = new CategoryNews();
  242. $row = $model->FindById(Yii::$app->request->post('id'));
  243. if ($row != null) {
  244. if ($row->state == 1) {
  245. $row->state = 2;
  246. } else {
  247. $row->state = 1;
  248. }
  249. if ($row->update(false) == true) return Help::JsonCode(Help::SUCCESS, '审核成功');
  250. }
  251. return Help::JsonCode(Help::ERROR, '审核失败');
  252. }
  253. /*
  254. * 2020.6.24 lyy 资讯设置排序
  255. * */
  256. public function actionNewssetsort()
  257. {
  258. $model = new CategoryNews();
  259. $row = $model->FindById(Yii::$app->request->post('id'));
  260. if ($row != null) {
  261. $row->sort = Yii::$app->request->post('sort');
  262. if ($row->update(false) == true) return Help::JsonCode(Help::SUCCESS, '设置成功');
  263. }
  264. return Help::JsonCode(Help::ERROR, '设置失败');
  265. }
  266. // ===================================相册===========================================
  267. /*
  268. * 相册分类显示页面
  269. * */
  270. public function actionPhotoalbum()
  271. {
  272. return $this->render('photoalbum');
  273. }
  274. /*
  275. * 相册分类数据
  276. * */
  277. public function actionPhotoalbumform()
  278. {
  279. $model = new CategoryAlbum();
  280. $rows = $model->getList(Yii::$app->request->post());
  281. if ($rows != null) {
  282. foreach ($rows as &$val) {
  283. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  284. $val['update_at'] = date('Y-m-d H:i', $val['update_at']);
  285. }
  286. return Help::JsonData(0, '成功', $model->Total(), $rows);
  287. }
  288. return Help::JsonCode(Help::ERROR, '暂无数据');
  289. }
  290. /*
  291. * 添加相册分类页面
  292. * */
  293. public function actionPhotoalbumadd()
  294. {
  295. return $this->render('photoalbumadd');
  296. }
  297. /*
  298. * 添加相册分类数据
  299. * */
  300. public function actionPhotoalbumaddform()
  301. {
  302. $model = new CategoryAlbum();
  303. $model->load(Yii::$app->request->post('data'), '');
  304. if (!$model->validate()) return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
  305. if ($model->insert() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
  306. return Help::JsonCode(Help::ERROR, '添加失败');
  307. }
  308. /*
  309. * 修改相册分类页面
  310. * */
  311. public function actionPhotoalbumedit()
  312. {
  313. $model = new CategoryAlbum();
  314. $row = $model->FindById(Yii::$app->request->get('id'));
  315. if ($row != null) {
  316. return $this->render('photoalbumedit', ['model' => $row]);
  317. }
  318. }
  319. /*
  320. *修改相册分类数据
  321. * */
  322. public function actionPhotoalbumeditform()
  323. {
  324. $model = new CategoryAlbum();
  325. $model->load(Yii::$app->request->post('data'), '');
  326. if (!$model->validate()) return Help::JsonCode(Help::ERROR, '修改失败', $model->errors);
  327. $row = $model->FindById(Yii::$app->request->post('data')['id']);
  328. $row->name = $model->name;
  329. if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
  330. return Help::JsonCode(Help::ERROR, '修改失败');
  331. }
  332. /*
  333. * 删除相册分类
  334. * */
  335. public function actionPhotoalbumdel()
  336. {
  337. $model = new CategoryAlbum();
  338. $input = Yii::$app->request->post();
  339. $row = $model->FindById(Yii::$app->request->post('id'));
  340. if ($row != null) {
  341. switch ($input['type']) {
  342. case 'del':
  343. $row->del = 2;
  344. $msg = '删除成功';
  345. break;
  346. case 'is_show':
  347. $row->is_show = $input['is_show'];
  348. if ($input['is_show'] == 2) {
  349. $msg = '下架成功';
  350. } else {
  351. $msg = '上架成功';
  352. }
  353. break;
  354. case 'sort':
  355. $row->sort = intval($input['sort']);
  356. $msg = '排序成功';
  357. break;
  358. }
  359. if ($row->save() == true) return Help::JsonCode(Help::SUCCESS, Yii::t('app', $msg));
  360. }
  361. return Help::JsonCode(Help::ERROR, Yii::t('app', '操作失败'));
  362. }
  363. // ===================================周边配套===========================================
  364. /*
  365. * 周边配套列表显示页面
  366. * */
  367. public function actionFacilities()
  368. {
  369. return $this->render('facilities');
  370. }
  371. /*
  372. * 周边配套列表数据
  373. * */
  374. public function actionFacilitiesform()
  375. {
  376. $model = new CategoryFacilities();
  377. $rows = $model->getList(Yii::$app->request->post());
  378. if ($rows != null) {
  379. foreach ($rows as &$val) {
  380. $val['create_at'] = date('Y-m-d', $val['create_at']);
  381. }
  382. return Help::JsonData(0, '成功', $model->Total(), $rows);
  383. }
  384. }
  385. /*
  386. * 周边配套数据添加页面
  387. * */
  388. public function actionFacilitiesadd()
  389. {
  390. return $this->render('facilitiesadd');
  391. }
  392. /*
  393. * 周边配套数据添加
  394. * */
  395. public function actionFacilitiesaddform()
  396. {
  397. $model = new CategoryFacilities();
  398. $model->scenario = 'add';
  399. $row = $model->Authenticator(Yii::$app->request->post());
  400. if (is_array($row)) return Help::JsonCode(Help::ERROR, '添加失败', $row);
  401. $url = Yii::$app->params['img_url']['facilities'];
  402. $img = \backend\server\UploadFile::InstanceImgName('img', $url);
  403. $imga = \backend\server\UploadFile::InstanceImgName('mobile_img', $url);
  404. $imgb = \backend\server\UploadFile::InstanceImgName('map_img', $url);
  405. if ($img != false) $row->img = $img;
  406. if ($imga != false) $row->mobile_img = $imga;
  407. if ($imgb != false) $row->map_img = $imgb;
  408. if ($row->insert() == true) return Help::JsonCode(Help::SUCCESS, '添加成功', $row);
  409. }
  410. /*
  411. * 周边配套修改页面
  412. * */
  413. public function actionFacilitiessave()
  414. {
  415. $model = new CategoryFacilities();
  416. $row = $model->FindById(Yii::$app->request->get('id'));
  417. if ($row != null) {
  418. if (!empty($row['img'])) {
  419. $row['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['facilities'] . $row['img'];
  420. }
  421. if (!empty($row['mobile_img'])) {
  422. $row['mobile_img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['facilities'] . $row['mobile_img'];
  423. }
  424. if (!empty($row['map_img'])) {
  425. $row['map_img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['facilities'] . $row['map_img'];
  426. }
  427. return $this->render('facilitiessave', ['model' => $row]);
  428. }
  429. }
  430. /*
  431. * 周边配套修改数据
  432. * */
  433. public function actionFacilitiessaveform()
  434. {
  435. $model = new CategoryFacilities();
  436. $input = Yii::$app->request->post();
  437. $check = $model->Authenticator($input);
  438. if (is_array($check)) return Help::JsonCode(Help::ERROR, '操作失败', $check);
  439. $row = $model->FindById($input['id']);
  440. if ($row != null) {
  441. $url = Yii::$app->params['img_url']['facilities'];
  442. $img = \backend\server\UploadFile::InstanceImgName('img', $url);
  443. $imga = \backend\server\UploadFile::InstanceImgName('mobile_img', $url);
  444. $imgb = \backend\server\UploadFile::InstanceImgName('map_img', $url);
  445. if ($img != false) {
  446. \backend\server\UploadFile::delImg($url, $row->img);
  447. $row->img = $img;
  448. }
  449. if ($imga != false) {
  450. \backend\server\UploadFile::delImg($url, $row->mobile_img);
  451. $row->mobile_img = $imga;
  452. }
  453. if ($imgb != false) {
  454. \backend\server\UploadFile::delImg($url, $row->map_img);
  455. $row->map_img = $imgb;
  456. }
  457. $save = Help::SetAttr($input, $check, $row);
  458. if ($save->save() == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
  459. }
  460. }
  461. /*
  462. * 周边配套删除数据
  463. * */
  464. public function actionFacilitiesdel()
  465. {
  466. $model = new CategoryFacilities();
  467. $row = $model->FindById(Yii::$app->request->post('id'));
  468. if ($row != null) {
  469. // $url = Yii::$app->params['img_url']['facilities'];
  470. // \backend\server\UploadFile::delImg($url,$row->img);
  471. // \backend\server\UploadFile::delImg($url,$row->mobile_img);
  472. // \backend\server\UploadFile::delImg($url,$row->map_img);
  473. $row->del = 2;
  474. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, '操作成功');
  475. }
  476. return Help::JsonCode(Help::ERROR, '操作失败');
  477. }
  478. /*
  479. * 周边配套审核上架
  480. * */
  481. public function actionFacilitiesstate()
  482. {
  483. $model = new CategoryFacilities();
  484. $input = Yii::$app->request->post();
  485. $query = $model->FindById($input['id']);
  486. if ($query != null) {
  487. if ($query->is_show == 1) {
  488. $query->is_show = 2;
  489. $msg = '下架成功';
  490. } else {
  491. $query->is_show = 1;
  492. $msg = '上架成功';
  493. }
  494. if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, $msg);
  495. }
  496. return Help::JsonCode(Help::ERROR, $msg);
  497. }
  498. /*
  499. * 周边配套
  500. * */
  501. public function actionFacilitiessort()
  502. {
  503. $input = Yii::$app->request->post();
  504. $query = CategoryFacilities::findOne($input['id']);
  505. if ($query != null) {
  506. if (!is_numeric($input['sort'])) {
  507. return Help::JsonCode(Help::ERROR, '请输入数字');
  508. }
  509. $query->sort = $input['sort'];
  510. if ($query->update() == true) return Help::JsonCode(Help::SUCCESS, '排序成功');
  511. }
  512. return Help::JsonCode(Help::ERROR, '排序失败');
  513. }
  514. }