ZtController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. public function actionTohainanvilleedit()
  154. {
  155. $input = Yii::$app->request->post('data');
  156. $rows = PushplaceType::find();
  157. if (!$rows->where(['type' => 1, 'title' => $input['title']])->exists()) {
  158. $qurey = PushplaceType::findOne($input['id']);
  159. $qurey->title = $input['title'];
  160. if ($qurey->update(false)) return Help::JsonCode(Help::SUCCESS, '编辑成功');
  161. return Help::JsonCode(Help::ERROR, '编辑失败');
  162. } else {
  163. return Help::JsonCode(Help::SUCCESS, '地区已存在');
  164. }
  165. }
  166. public function actionGulfcityglstate()
  167. {
  168. $input = Yii::$app->request->post();
  169. if (is_numeric($input['id'])) {
  170. $row = PushhouseType::findOne($input['id']);
  171. $row->state = $input['state'];
  172. if ($row->update(false)) return Help::JsonCode(Help::SUCCESS, '设置成功');
  173. return Help::JsonCode(Help::SUCCESS, '设置失败');
  174. } else {
  175. return Help::JsonCode(Help::SUCCESS, '设置失败');
  176. }
  177. }
  178. public function actionGulfcityglsort()
  179. {
  180. $input = Yii::$app->request->post();
  181. if (is_numeric($input['id'])) {
  182. $row = PushhouseType::findOne($input['id']);
  183. $row->sort = $input['sort'];
  184. if ($row->update(false)) return Help::JsonCode(Help::SUCCESS, '排序成功');
  185. return Help::JsonCode(Help::SUCCESS, '排序失败');
  186. } else {
  187. return Help::JsonCode(Help::SUCCESS, '排序失败');
  188. }
  189. }
  190. public function actionGulfcitygldel()
  191. {
  192. $id = Yii::$app->request->post('id');
  193. if (is_numeric($id)) {
  194. if (PushhouseType::findOne($id)->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  195. return Help::JsonCode(Help::ERROR, '删除失败');
  196. } else {
  197. return Help::JsonCode(Help::ERROR, '删除失败');
  198. }
  199. }
  200. public function actionOfficezt()
  201. {
  202. return $this->render('officezt');
  203. }
  204. //获取地区列表
  205. public function actionOfficeztform()
  206. {
  207. $dataInfo = PushplaceType::find()
  208. ->where(['type' => 4])
  209. ->orderBy(['sort' => SORT_DESC])
  210. ->asArray()->all();
  211. return help::JsonData(0, '成功', 0, $dataInfo);
  212. }
  213. public function actionOfficeztadd()
  214. {
  215. return $this->render('officeztadd');
  216. }
  217. public function actionOfficeztaddform()
  218. {
  219. $input = Yii::$app->request->post('data');
  220. $rows = PushplaceType::find();
  221. if (!$rows->where(['type' => 4, 'title' => $input['title']])->exists()) {
  222. $query = new PushplaceType();
  223. $query->title = $input['title'];
  224. $query->type = 4;
  225. if ($query->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  226. Help::JsonCode(Help::ERROR, '添加失败');
  227. } else {
  228. return Help::JsonCode(Help::ERROR, '地区已存在');
  229. }
  230. }
  231. public function actionOfficeztdel()
  232. {
  233. $id = Yii::$app->request->post('id');
  234. $rows = PushplaceType::findOne($id);
  235. if ($rows->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  236. Help::JsonCode(Help::ERROR, '删除失败');
  237. }
  238. public function actionOfficeztedit()
  239. {
  240. $id = Yii::$app->request->get('id');
  241. $data = PushplaceType::findOne($id);
  242. return $this->render('officeztedit', ['data' => $data]);
  243. }
  244. public function actionOfficezteditform()
  245. {
  246. $input = Yii::$app->request->post();
  247. $rows = PushplaceType::findOne($input['id']);
  248. $rows->title = $input['title'];
  249. if ($rows->update(false)) return Help::JsonCode(Help::SUCCESS, '编辑成功');
  250. Help::JsonCode(Help::ERROR, '编辑失败');
  251. }
  252. public function actionOfficeztgl()
  253. {
  254. $id = Yii::$app->request->get('id');
  255. return $this->render('officeztgl', ['id' => $id]);
  256. }
  257. public function actionOfficeztglform()
  258. {
  259. $previd = Yii::$app->request->get('previd');
  260. $data = PushhouseType::find()
  261. ->select('pfg_pushhouse_type.*,pfg_pushplace_type.title,pfg_house.name,')
  262. ->where(['pfg_pushhouse_type.previd' => $previd, 'pfg_pushhouse_type.type' => 4])
  263. ->leftJoin('pfg_house', 'pfg_house.id = pfg_pushhouse_type.hid')
  264. ->leftJoin('pfg_pushplace_type', 'pfg_pushplace_type.id = pfg_pushhouse_type.previd')
  265. ->orderBy(['pfg_pushhouse_type.sort' => SORT_DESC])->asArray()->all();
  266. return help::JsonData(0, '成功', 0, $data);
  267. }
  268. public function actionOfficeztgladd()
  269. {
  270. $id = Yii::$app->request->get('id');
  271. return $this->render('officeztgladd', ['id' => $id]);
  272. }
  273. public function actionOfficeztgladdform()
  274. {
  275. $input = Yii::$app->request->post('data');
  276. $row = PushhouseType::find();
  277. if (!$row->where(['previd' => $input['previd'], 'type' => 4, 'hid' => $input['hid']])->exists()) {
  278. $query = new PushhouseType();
  279. $query->hid = $input['hid'];
  280. $query->previd = $input['previd'];
  281. $query->type = 4;
  282. if ($query->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  283. Help::JsonCode(Help::ERROR, '添加失败');
  284. } else {
  285. Help::JsonCode(Help::ERROR, '楼盘已存在');
  286. }
  287. }
  288. }