PushfreshController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/5/29
  6. * Time: 上午11:35
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\base\Help;
  11. use backend\server\UploadFile;
  12. use Yii;
  13. use common\models\PushFreshimg;
  14. use common\models\PushFreshcity;
  15. use common\models\PushFreshcityhouse;
  16. class PushfreshController extends CommonController
  17. {
  18. /*
  19. * 新房- 大图 页面
  20. * */
  21. public function actionFreshimg()
  22. {
  23. return $this->render('freshimg');
  24. }
  25. /*
  26. * 新房- 大图 数据
  27. * */
  28. public function actionFreshimgform()
  29. {
  30. $url = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['fresh'];
  31. $model = new PushFreshimg();
  32. $rows = $model->getList(Yii::$app->request->post());
  33. if(!empty($rows))
  34. {
  35. foreach ($rows as &$val)
  36. {
  37. $val['img'] = $url.$val['img'];
  38. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  39. }
  40. return Help::JsonData(0,Yii::t('app','get_error'),$model->Total(),$rows);
  41. }
  42. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  43. }
  44. /*
  45. * 新房- 大图 添加页面
  46. * */
  47. public function actionFreshimgadd()
  48. {
  49. return $this->render('freshimgadd');
  50. }
  51. /*
  52. * 新房- 大图 添加数据
  53. * */
  54. public function actionFreshimgaddform()
  55. {
  56. $model = new PushFreshimg();
  57. $input = Yii::$app->request->post();
  58. $auth = $model->Authenticator($input);
  59. if(is_object($auth))
  60. {
  61. Yii::$app->params['img_url']['fresh'];
  62. $img = UploadFile::InstanceImgName('img', Yii::$app->params['img_url']['fresh']);
  63. if(is_string($img))
  64. {
  65. $auth->img = $img;
  66. }
  67. if($auth->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  68. }
  69. return Help::JsonCode(Help::ERROR,Yii::t('app','add_erroe'),$auth);
  70. }
  71. /*
  72. * 新房- 大图 修改页面
  73. * */
  74. public function actionFreshimgedit()
  75. {
  76. $input = Yii::$app->request->get();
  77. $model = new PushFreshimg();
  78. $row = $model->FindById($input['id']);
  79. if(!empty($row))
  80. {
  81. $row['img'] = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['fresh'].$row['img'];
  82. return $this->render('freshimgedit',['model'=>$row]);
  83. }
  84. }
  85. /*
  86. * 新房- 大图 修改数据
  87. * */
  88. public function actionFresheditform()
  89. {
  90. $input = Yii::$app->request->post();
  91. $model = new PushFreshimg();
  92. $auth = $model->Authenticator($input);
  93. if(is_object($auth))
  94. {
  95. $row = $model->FindById($input['id']);
  96. if(!empty($row))
  97. {
  98. $row = Help::SetAttr($input,$auth,$row);
  99. $url = Yii::$app->params['img_url']['fresh'];;
  100. $img = UploadFile::InstanceImgName('img',$url);
  101. if(is_string($img))
  102. {
  103. UploadFile::delImg($url,$row->img);
  104. $row->img = $img;
  105. }
  106. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  107. }
  108. }
  109. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  110. }
  111. /*
  112. * 新房- 大图 删除和隐藏
  113. * */
  114. public function actionFreshdelandsow()
  115. {
  116. $model = new PushFreshimg();
  117. $input = Yii::$app->request->post();
  118. $row = $model->FindById($input['id']);
  119. if($row != null)
  120. {
  121. switch ($input['type'])
  122. {
  123. case 'show':
  124. if($row->is_show == 1)
  125. {
  126. $row->is_show = 2;
  127. }
  128. else if($row->is_show == 2)
  129. {
  130. $row->is_show = 1;
  131. }
  132. break;
  133. case 'del':
  134. $row->del = 2;
  135. break;
  136. }
  137. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  138. }
  139. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  140. }
  141. /*
  142. * 新房 - 推荐楼盘区域页面
  143. * */
  144. public function actionFreshcity()
  145. {
  146. return $this->render('freshcity');
  147. }
  148. /*
  149. * 新房 - 推荐楼盘区域数据
  150. * */
  151. public function actionFreshcityform()
  152. {
  153. $model = new PushFreshcity();
  154. $rows = $model->getList(Yii::$app->request->post());
  155. if(!empty($rows))
  156. {
  157. foreach ($rows as &$val)
  158. {
  159. $val['img'] = Yii::$app->params['httpImg']['host']. Yii::$app->params['httpImg']['city'].$val['img'];
  160. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  161. }
  162. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  163. }
  164. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  165. }
  166. /*
  167. * 新房 - 推荐楼盘区域 添加页面
  168. * */
  169. public function actionFreshcityadd()
  170. {
  171. return $this->render('freshcityadd');
  172. }
  173. /*
  174. * 新房 - 推荐楼盘区域 添加数据
  175. * */
  176. public function actionFreshcityaddform()
  177. {
  178. $input = Yii::$app->request->post();
  179. $model = new PushFreshcity();
  180. $auth = $model->Authenticator($input);
  181. if(is_object($auth))
  182. {
  183. $img = UploadFile::InstanceImgName('img',Yii::$app->params['img_url']['city']);
  184. if(is_string($img))
  185. {
  186. $auth->img = $img;
  187. }
  188. if($auth->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  189. }
  190. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$auth);
  191. }
  192. /*
  193. * 新房 - 推荐楼盘区域 修改页面
  194. * */
  195. public function actionFreshcityedit()
  196. {
  197. $model = new PushFreshcity();
  198. $row = $model->FindById(Yii::$app->request->get('id'));
  199. if(!empty($row))
  200. {
  201. $row['img'] = Yii::$app->params['httpImg']['host']. Yii::$app->params['httpImg']['city'].$row['img'];
  202. return $this->render('freshcityedit',['model'=>$row,'name'=>Yii::$app->request->get('name')]);
  203. }
  204. }
  205. /*
  206. * 新房 - 推荐楼盘区域 修改数据
  207. * */
  208. public function actionFreshcityeditform()
  209. {
  210. $model = new PushFreshcity();
  211. $input = Yii::$app->request->post();
  212. $auth = $model->Authenticator($input);
  213. if(is_object($auth))
  214. {
  215. $row = $model->FindById($input['id']);
  216. if(!empty($row))
  217. {
  218. $rows = Help::SetAttr($input,$auth,$row);
  219. $img = UploadFile::InstanceImgName('img',Yii::$app->params['img_url']['city']);
  220. if(is_string($img))
  221. {
  222. UploadFile::delImg(Yii::$app->params['img_url']['city'],$row->img);
  223. $rows->img = $img;
  224. }
  225. if($rows->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  226. }
  227. }
  228. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'),$auth);
  229. }
  230. public function actionCitydelandshow()
  231. {
  232. $model = new PushFreshcity();
  233. $input = Yii::$app->request->post();
  234. $row = $model->FindById($input['id']);
  235. if($row != null)
  236. {
  237. switch ($input['type'])
  238. {
  239. case 'show':
  240. if($row->is_show == 1)
  241. {
  242. $row->is_show = 2;
  243. }
  244. else if($row->is_show == 2)
  245. {
  246. $row->is_show = 1;
  247. }
  248. break;
  249. case 'del':
  250. $row->del = 2;
  251. break;
  252. case 'sort':
  253. $row->sort = $input['sort'];
  254. break;
  255. }
  256. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  257. }
  258. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  259. }
  260. /*
  261. * 新房 - 推荐楼盘区域 关联楼盘
  262. * */
  263. public function actionCityhouse()
  264. {
  265. return $this->render('cityhouse',['id'=>Yii::$app->request->get('id')]);
  266. }
  267. /*
  268. * 新房 - 推荐楼盘区域 关联楼盘
  269. * */
  270. public function actionCityhouseform()
  271. {
  272. $model = new PushFreshcityhouse();
  273. $rows = $model->getList(Yii::$app->request->post());
  274. if(!empty($rows))
  275. {
  276. $model->city_id = Yii::$app->request->post('city_id');
  277. foreach ($rows as &$val)
  278. {
  279. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  280. }
  281. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  282. }
  283. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  284. }
  285. /*
  286. * 新房 - 推荐楼盘区域 关联楼盘
  287. * */
  288. public function actionCityhouseadd()
  289. {
  290. return $this->render('cityhouseadd',['id'=>Yii::$app->request->get('id')]);
  291. }
  292. /*
  293. * 新房 - 推荐楼盘区域 关联楼盘
  294. * */
  295. public function actionCityhouseaddform()
  296. {
  297. $model = new PushFreshcityhouse();
  298. $auth = $model->Authenticator(Yii::$app->request->post());
  299. if(is_object($auth))
  300. {
  301. if($auth->save())
  302. {
  303. return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  304. }
  305. }
  306. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$auth);
  307. }
  308. /*
  309. * 新房 - 推荐楼盘区域 关联楼盘 删除和禁用
  310. * */
  311. public function actionCityhousedelandshow()
  312. {
  313. $model = new PushFreshcityhouse();
  314. $input = Yii::$app->request->post();
  315. $row = $model->FindById($input['id']);
  316. if($row != null)
  317. {
  318. switch ($input['type'])
  319. {
  320. case 'show':
  321. if($row->is_show == 1)
  322. {
  323. $row->is_show = 2;
  324. }
  325. else if($row->is_show == 2)
  326. {
  327. $row->is_show = 1;
  328. }
  329. break;
  330. case 'del':
  331. $row->del = 2;
  332. break;
  333. case 'sort':
  334. $row->sort = $input['sort'];
  335. break;
  336. }
  337. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  338. }
  339. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  340. }
  341. }