ZtController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/1/2
  6. * Time: 10:34
  7. */
  8. namespace backend\controllers;
  9. use Yii;
  10. use backend\base\CommonController;
  11. use backend\base\Help;
  12. use backend\server\UploadFile;
  13. use common\models\PushhouseType;
  14. use common\models\PushplaceType;
  15. class ZtController extends CommonController
  16. {
  17. public function actionHome()
  18. {
  19. return $this->render('home');
  20. }
  21. public function actionHomeform()
  22. {
  23. // p($this->cache['zt']);
  24. $model = new \common\models\SpecialTopic();
  25. $rows = $model->getList(Yii::$app->request->post());
  26. $imgUrl = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['push_lb'];
  27. if(!empty($rows['data']))
  28. {
  29. array_walk($rows['data'],function(&$val) use ($imgUrl){
  30. $val['hids'] = implode(',',json_decode($val['hids'],true));
  31. list($val['pc_img'],$val['m_img']) = [(empty($val['pc_img'])? '' : $imgUrl.$val['pc_img']),(empty($val['m_img'])? '' : $imgUrl.$val['m_img'])];
  32. });
  33. return Help::JsonData(0,'成功',$rows['count'],$rows['data']);
  34. }
  35. return Help::JsonCode(Help::ERROR,'暂无数据');
  36. }
  37. public function actionAdd()
  38. {
  39. return $this->render('add');
  40. }
  41. public function actionAddform()
  42. {
  43. $model = new \common\models\SpecialTopic();
  44. $input = Yii::$app->request->post();
  45. $url = Yii::$app->params['img_url']['push_lb'];
  46. $img = UploadFile::InstanceImgName('img',$url);
  47. $img1 = UploadFile::InstanceImgName('img1',$url);
  48. if(empty($input['hid'])) return Help::JsonCode(Help::ERROR,'请选择推送的楼盘');
  49. $input['hids'] = json_encode($input['hid']);
  50. if(is_string($img) && is_string($img1)){
  51. list($input['pc_img'],$input['m_img']) = [$img,$img1];
  52. }
  53. $model->load($input,'');
  54. if($model->validate() && $model->save()){
  55. return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  56. }
  57. return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_error'),$model->errors);
  58. }
  59. public function actionEdit()
  60. {
  61. $model = new \common\models\SpecialTopic();
  62. $zid = Yii::$app->request->get('id');
  63. $row = $model::findOne($zid);
  64. $imgUrl = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['push_lb'];
  65. if(!empty($row)){
  66. $hmodel = new \common\models\House();
  67. $query = $hmodel::find();
  68. $hid = json_decode($row['hids'],true);
  69. $house = $query->select(['id','name'])->andWhere(['id'=>$hid])->asArray()->all();
  70. list($row['pc_img'],$row['m_img']) = [(empty($row['pc_img'])? '' : $imgUrl.$row['pc_img']),(empty($row['m_img'])? '' : $imgUrl.$row['m_img'])];
  71. }
  72. // p($house);die;
  73. return $this->render('edit',['model'=>$row,'house'=>$house]);
  74. }
  75. public function actionEditform()
  76. {
  77. $model = new \common\models\SpecialTopic();
  78. $input = Yii::$app->request->post();
  79. $row = $model::findOne($input['id']);
  80. $url = Yii::$app->params['img_url']['push_lb'];
  81. if(empty($input['hid'])) return Help::JsonCode(Help::ERROR,'请选择推送的楼盘');
  82. if(!empty($_FILES)){
  83. if(!empty($_FILES['img']['name'])){
  84. UploadFile::delImg($url,$row->pc_img);
  85. $img = UploadFile::InstanceImgName('img',$url);
  86. is_string($img)? $input['pc_img'] = $img : '' ;
  87. }
  88. if(!empty($_FILES['img1']['name'])){
  89. UploadFile::delImg($url,$row->m_img);
  90. $img1 = UploadFile::InstanceImgName('img1',$url);
  91. is_string($img1)? $input['m_img'] = $img1 : '' ;
  92. }
  93. }
  94. $input['hids'] = json_encode($input['hid']);
  95. $row->load($input,'');
  96. if($row->validate() && $row->save()){
  97. return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  98. }
  99. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'),$row->errors);
  100. }
  101. public function actionDel()
  102. {
  103. // p('没做');die;
  104. $input = Yii::$app->request->post();
  105. $model = new \common\models\SpecialTopic();
  106. $url = Yii::$app->params['img_url']['push_lb'];
  107. $row = $model::findOne($input['id']);
  108. if(!empty($row)){
  109. empty($row->pc_img)? '' : UploadFile::delImg($url,$row->pc_img);
  110. empty($row->m_img)? '' : UploadFile::delImg($url,$row->m_img);
  111. $row->delete();
  112. return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  113. }
  114. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  115. }
  116. /*
  117. * ********************写字楼专题***********************
  118. * */
  119. public function actionGulfcitystate()
  120. {
  121. $input = Yii::$app->request->post();
  122. if (is_numeric($input['id'])) {
  123. $row = PushplaceType::findOne($input['id']);
  124. $row->state = $input['state'];
  125. if ($row->update(false)) return Help::JsonCode(Help::SUCCESS, '设置成功');
  126. return Help::JsonCode(Help::SUCCESS, '设置失败');
  127. } else {
  128. return Help::JsonCode(Help::SUCCESS, '设置失败');
  129. }
  130. }
  131. public function actionGulfcitysort()
  132. {
  133. $input = Yii::$app->request->post();
  134. if (is_numeric($input['id'])) {
  135. $row = PushplaceType::findOne($input['id']);
  136. $row->sort = $input['sort'];
  137. if ($row->update(false)) return Help::JsonCode(Help::SUCCESS, '排序成功');
  138. return Help::JsonCode(Help::SUCCESS, '排序失败');
  139. } else {
  140. return Help::JsonCode(Help::SUCCESS, '排序失败');
  141. }
  142. }
  143. public function actionGulfcitydel()
  144. {
  145. $id = Yii::$app->request->post('id');
  146. if (is_numeric($id)) {
  147. if (PushplaceType::findOne($id)->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  148. return Help::JsonCode(Help::ERROR, '删除失败');
  149. } else {
  150. return Help::JsonCode(Help::ERROR, '删除失败');
  151. }
  152. }
  153. //海南站专题别墅
  154. public function actionHainanville()
  155. {
  156. return $this->render('hainanville');
  157. }
  158. public function actionHainanvilleform()
  159. {
  160. $data = PushplaceType::find()->where(['type' => 1])->asArray()->all();
  161. return help::JsonData(0, '成功', 0, $data);
  162. }
  163. public function actionHainanvillestate()
  164. {
  165. $input = Yii::$app->request->post();
  166. if (is_numeric($input['id'])) {
  167. $row = PushplaceType::findOne($input['id']);
  168. $row->state = $input['state'];
  169. if ($row->update(false)) return Help::JsonCode(Help::SUCCESS, '设置成功');
  170. return Help::JsonCode(Help::SUCCESS, '设置失败');
  171. } else {
  172. return Help::JsonCode(Help::SUCCESS, '设置失败');
  173. }
  174. }
  175. public function actionTohainanvilleadd()
  176. {
  177. $input = Yii::$app->request->post('data');
  178. $row = PushplaceType::find();
  179. if (!$row->where(['title' => $input['title'], 'type' => 1])->exists()) {
  180. $query = new PushplaceType();
  181. $query->title = $input['title'];
  182. $query->type = 1;
  183. if ($query->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  184. Help::JsonCode(Help::ERROR, '添加失败');
  185. } else {
  186. return Help::JsonCode(Help::SUCCESS, '地区已存在');
  187. }
  188. }
  189. public function actionHainanvilleadd()
  190. {
  191. return $this->render('hainanvilleadd');
  192. }
  193. public function actionHainanvillegl()
  194. {
  195. $id = Yii::$app->request->get('id');
  196. return $this->render('hainanvillegl', ['id' => $id]);
  197. }
  198. public function actionHainanvilleglform()
  199. {
  200. $previd = Yii::$app->request->get('previd');
  201. $data = PushhouseType::find()
  202. ->select('pfg_pushhouse_type.*,pfg_pushplace_type.title,pfg_house.name,')
  203. ->where(['pfg_pushhouse_type.previd' => $previd, 'pfg_pushhouse_type.type' => 2])
  204. ->leftJoin('pfg_house', 'pfg_house.id = pfg_pushhouse_type.hid')
  205. ->leftJoin('pfg_pushplace_type', 'pfg_pushplace_type.id = pfg_pushhouse_type.previd')
  206. ->orderBy(['pfg_pushhouse_type.sort' => SORT_DESC])->asArray()->all();
  207. return help::JsonData(0, '成功', 0, $data);
  208. }
  209. public function actionHainanvillegladd()
  210. {
  211. $previd = Yii::$app->request->get('previd');
  212. return $this->render('hainanvillegladd', ['previd' => $previd]);
  213. }
  214. public function actionGulfcitygledit()
  215. {
  216. $id = Yii::$app->request->get('id');
  217. $data = PushhouseType::find()
  218. ->select('pfg_pushhouse_type.*,pfg_house.name,')
  219. ->where(['pfg_pushhouse_type.id' => $id])
  220. ->leftJoin('pfg_house', 'pfg_house.id = pfg_pushhouse_type.hid')
  221. ->asArray()->one();
  222. return $this->render('gulfcitygledit', ['data' => $data]);
  223. }
  224. public function actionGulfcitygleditto()
  225. {
  226. $input = Yii::$app->request->post('data');
  227. $row = PushhouseType::find();
  228. if (!$row->where("id <> {$input['id']} AND previd = {$input['previd']} AND hid = {$input['hid']}")->exists()) {
  229. $query = PushhouseType::findOne($input['id']);
  230. $query->hid = $input['hid'];
  231. if ($query->update(false)) return Help::JsonCode(Help::SUCCESS, '编辑成功');
  232. return Help::JsonCode(Help::SUCCESS, '编辑失败');
  233. } else {
  234. return Help::JsonCode(Help::ERROR, '楼盘已存在');
  235. }
  236. }
  237. public function actionHainanvillegladdto()
  238. {
  239. $input = Yii::$app->request->post('data');
  240. $row = PushhouseType::find();
  241. if (!$row->where(['previd' => $input['previd'], 'type' => 2, 'hid' => $input['hid']])->exists()) {
  242. $query = new PushhouseType();
  243. $query->hid = $input['hid'];
  244. $query->previd = $input['previd'];
  245. $query->type = 2;
  246. if ($query->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  247. Help::JsonCode(Help::ERROR, '添加失败');
  248. } else {
  249. Help::JsonCode(Help::ERROR, '楼盘已存在');
  250. }
  251. }
  252. public function actionTohainanvilleedit()
  253. {
  254. $input = Yii::$app->request->post('data');
  255. $rows = PushplaceType::find();
  256. if (!$rows->where(['type' => 1, 'title' => $input['title']])->exists()) {
  257. $qurey = PushplaceType::findOne($input['id']);
  258. $qurey->title = $input['title'];
  259. if ($qurey->update(false)) return Help::JsonCode(Help::SUCCESS, '编辑成功');
  260. return Help::JsonCode(Help::ERROR, '编辑失败');
  261. } else {
  262. return Help::JsonCode(Help::SUCCESS, '地区已存在');
  263. }
  264. }
  265. public function actionGulfcityglstate()
  266. {
  267. $input = Yii::$app->request->post();
  268. if (is_numeric($input['id'])) {
  269. $row = PushhouseType::findOne($input['id']);
  270. $row->state = $input['state'];
  271. if ($row->update(false)) return Help::JsonCode(Help::SUCCESS, '设置成功');
  272. return Help::JsonCode(Help::SUCCESS, '设置失败');
  273. } else {
  274. return Help::JsonCode(Help::SUCCESS, '设置失败');
  275. }
  276. }
  277. public function actionGulfcityglsort()
  278. {
  279. $input = Yii::$app->request->post();
  280. if (is_numeric($input['id'])) {
  281. $row = PushhouseType::findOne($input['id']);
  282. $row->sort = $input['sort'];
  283. if ($row->update(false)) return Help::JsonCode(Help::SUCCESS, '排序成功');
  284. return Help::JsonCode(Help::SUCCESS, '排序失败');
  285. } else {
  286. return Help::JsonCode(Help::SUCCESS, '排序失败');
  287. }
  288. }
  289. public function actionGulfcitygldel()
  290. {
  291. $id = Yii::$app->request->post('id');
  292. if (is_numeric($id)) {
  293. if (PushhouseType::findOne($id)->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  294. return Help::JsonCode(Help::ERROR, '删除失败');
  295. } else {
  296. return Help::JsonCode(Help::ERROR, '删除失败');
  297. }
  298. }
  299. public function actionOfficezt()
  300. {
  301. return $this->render('officezt');
  302. }
  303. //获取地区列表
  304. public function actionOfficeztform()
  305. {
  306. $dataInfo = PushplaceType::find()
  307. ->where(['type' => 4])
  308. ->orderBy(['sort' => SORT_DESC])
  309. ->asArray()->all();
  310. return help::JsonData(0, '成功', 0, $dataInfo);
  311. }
  312. public function actionOfficeztadd()
  313. {
  314. return $this->render('officeztadd');
  315. }
  316. public function actionOfficeztaddform()
  317. {
  318. $input = Yii::$app->request->post('data');
  319. $rows = PushplaceType::find();
  320. if (!$rows->where(['type' => 4, 'title' => $input['title']])->exists()) {
  321. $query = new PushplaceType();
  322. $query->title = $input['title'];
  323. $query->type = 4;
  324. if ($query->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  325. Help::JsonCode(Help::ERROR, '添加失败');
  326. } else {
  327. return Help::JsonCode(Help::ERROR, '地区已存在');
  328. }
  329. }
  330. public function actionOfficeztdel()
  331. {
  332. $id = Yii::$app->request->post('id');
  333. $rows = PushplaceType::findOne($id);
  334. if ($rows->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  335. Help::JsonCode(Help::ERROR, '删除失败');
  336. }
  337. public function actionOfficeztedit()
  338. {
  339. $id = Yii::$app->request->get('id');
  340. $data = PushplaceType::findOne($id);
  341. return $this->render('officeztedit', ['data' => $data]);
  342. }
  343. public function actionOfficezteditform()
  344. {
  345. $input = Yii::$app->request->post();
  346. $rows = PushplaceType::findOne($input['id']);
  347. $rows->title = $input['title'];
  348. if ($rows->update(false)) return Help::JsonCode(Help::SUCCESS, '编辑成功');
  349. Help::JsonCode(Help::ERROR, '编辑失败');
  350. }
  351. public function actionOfficeztgl()
  352. {
  353. $id = Yii::$app->request->get('id');
  354. return $this->render('officeztgl', ['id' => $id]);
  355. }
  356. public function actionOfficeztglform()
  357. {
  358. $previd = Yii::$app->request->get('previd');
  359. $data = PushhouseType::find()
  360. ->select('pfg_pushhouse_type.*,pfg_pushplace_type.title,pfg_house.name,')
  361. ->where(['pfg_pushhouse_type.previd' => $previd, 'pfg_pushhouse_type.type' => 4])
  362. ->leftJoin('pfg_house', 'pfg_house.id = pfg_pushhouse_type.hid')
  363. ->leftJoin('pfg_pushplace_type', 'pfg_pushplace_type.id = pfg_pushhouse_type.previd')
  364. ->orderBy(['pfg_pushhouse_type.sort' => SORT_DESC])->asArray()->all();
  365. return help::JsonData(0, '成功', 0, $data);
  366. }
  367. public function actionOfficeztgladd()
  368. {
  369. $id = Yii::$app->request->get('id');
  370. return $this->render('officeztgladd', ['id' => $id]);
  371. }
  372. public function actionOfficeztgladdform()
  373. {
  374. $input = Yii::$app->request->post('data');
  375. $row = PushhouseType::find();
  376. if (!$row->where(['previd' => $input['previd'], 'type' => 4, 'hid' => $input['hid']])->exists()) {
  377. $query = new PushhouseType();
  378. $query->hid = $input['hid'];
  379. $query->previd = $input['previd'];
  380. $query->type = 4;
  381. if ($query->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  382. Help::JsonCode(Help::ERROR, '添加失败');
  383. } else {
  384. Help::JsonCode(Help::ERROR, '楼盘已存在');
  385. }
  386. }
  387. public function actionHainanvilledel()
  388. {
  389. $id = Yii::$app->request->post('id');
  390. if (is_numeric($id)) {
  391. if (PushplaceType::findOne($id)->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  392. return Help::JsonCode(Help::ERROR, '删除失败');
  393. } else {
  394. return Help::JsonCode(Help::ERROR, '删除失败');
  395. }
  396. }
  397. public function actionHainanvilleedit()
  398. {
  399. $id = Yii::$app->request->get('id');
  400. $data = PushplaceType::findOne($id);
  401. return $this->render('hainanvilleedit', ['data' => $data]);
  402. }
  403. }