PushrecommendController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace backend\controllers;
  3. use backend\base\CommonController;
  4. use backend\base\Help;
  5. use common\models\PushHousesale;
  6. use Yii;
  7. use common\models\PushRecommend;
  8. use common\models\PushHouserecommend;
  9. class PushrecommendController extends CommonController
  10. {
  11. /*
  12. * 页面显示
  13. * */
  14. public function actionIndex()
  15. {
  16. return $this->render('index');
  17. }
  18. /**数据读取*/
  19. public function actionIndexform()
  20. {
  21. $model = new PushRecommend();
  22. $rows = $model->adminList(Yii::$app->request->post());
  23. if(!empty($rows))
  24. {
  25. foreach($rows as &$val)
  26. {
  27. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  28. }
  29. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  30. }
  31. }
  32. /*
  33. * 加载楼盘 - 数据
  34. * */
  35. public function actionHouseloadform()
  36. {
  37. $model = new PushHouserecommend();
  38. $input = Yii::$app->request->post();
  39. $result = $model->getHouseList($input);
  40. if($result != null)
  41. {
  42. foreach ($result as &$val)
  43. {
  44. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  45. }
  46. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total($input),$result);
  47. }
  48. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  49. }
  50. /*
  51. * 加载楼盘 - 批量删除
  52. * */
  53. public function actionHouseloaddelall()
  54. {
  55. //接收表单数据
  56. $input = Yii::$app->request->post();
  57. $delall = PushHouserecommend::deleteAll(['id'=>$input['id']]);
  58. if ($delall){
  59. return Help::JsonCode(Help::SUCCESS,'批量删除成功');
  60. }
  61. return Help::JsonCode(Help::ERROR,'批量删除失败');
  62. }
  63. /*
  64. * 优选新房栏目添加
  65. * */
  66. public function actionAddform()
  67. {
  68. $model = new PushRecommend();
  69. $model->scenario = 'add';
  70. $recommend = $model->Authenticator(Yii::$app->request->post());
  71. if(is_object($recommend) && $recommend->insert() == true)
  72. {
  73. return Help::JsonCode(Help::SUCCESS,'添加成功');
  74. }
  75. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$recommend);
  76. }
  77. public function actionAdd()
  78. {
  79. $city=$this->City();
  80. return $this->render('add',['city'=>$city]);
  81. }
  82. public function actionEdit()
  83. {
  84. $model = new PushRecommend();
  85. $city=$this->City();
  86. $row = $model->FindById(Yii::$app->request->get('id'));
  87. return $this->render('edit',['city'=>$city,'row'=>$row]);
  88. }
  89. public function actionEditform()
  90. {
  91. $model = new PushRecommend();
  92. $row = $model->findOne(Yii::$app->request->post('id'));
  93. if($row != null)
  94. {
  95. $row->title = Yii::$app->request->post('title');
  96. $row->city = Yii::$app->request->post('city');
  97. if($row->save()) return Help::JsonCode(Help::SUCCESS,'关键词修改成功');
  98. }
  99. return Help::JsonCode(Help::ERROR,'关键词修改失败');
  100. }
  101. public function actionLoadhouse()
  102. {
  103. return $this->render('loadhouse',['cat_id'=>Yii::$app->request->get('cat_id')]);
  104. }
  105. private function City()
  106. {
  107. $city = new \common\models\CategoryCity();
  108. $city->state = 1;
  109. $city->pid = 0;
  110. $cityModel = $city->getList([]);
  111. return $cityModel;
  112. }
  113. /*
  114. * 推送优选新房 - 数据
  115. * */
  116. public function actionGetHoustform()
  117. {
  118. $model = new PushHousesale();
  119. $input = Yii::$app->request->post();
  120. $result = $model->getList($input);
  121. if($result != null)
  122. {
  123. foreach ($result as &$val)
  124. {
  125. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  126. }
  127. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total($input),$result);
  128. }
  129. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  130. }
  131. /*
  132. * 推送优选新房 - 添加
  133. */
  134. public function actionHouseadd()
  135. {
  136. return $this->render('houseadd',['cat_id'=>Yii::$app->request->get('cat_id')]);
  137. }
  138. //添加楼盘
  139. public function actionHouseaddform()
  140. {
  141. $input = Yii::$app->request->post();
  142. $model = new PushHouserecommend();
  143. $model->scenario = 'add';
  144. $validate = $model->Authenticator($input);
  145. if(is_object($validate))
  146. {
  147. $validate->city = \common\models\House::find()->select(['pfg_category_city.pid'])->leftJoin('pfg_category_city','pfg_house.city = pfg_category_city.id')->andWhere(['pfg_house.id'=>$input['hid']])->asArray()->one()['pid'];
  148. if($validate->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  149. }
  150. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$validate);
  151. }
  152. public function actionDelshow()
  153. {
  154. $model = new PushHouserecommend();
  155. $input = Yii::$app->request->post();
  156. $row = $model->FindById($input['id']);
  157. if($row != null)
  158. {
  159. switch ($input['type'])
  160. {
  161. case 'show':
  162. if($row->is_show == 1)
  163. {
  164. $row->is_show = 2;
  165. }
  166. else if($row->is_show == 2)
  167. {
  168. $row->is_show = 1;
  169. }
  170. break;
  171. case 'del':
  172. $row->del = 2;
  173. break;
  174. case 'sort':
  175. if(is_numeric($input['sort']))
  176. {
  177. $row->sort = $input['sort'];
  178. }
  179. break;
  180. }
  181. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  182. }
  183. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  184. }
  185. public function actionCatdelshow()
  186. {
  187. $model = new PushRecommend();
  188. $input = Yii::$app->request->post();
  189. $row = $model->FindById($input['id']);
  190. if($row != null)
  191. {
  192. switch ($input['type'])
  193. {
  194. case 'show':
  195. if($row->is_show == 1)
  196. {
  197. $row->is_show = 2;
  198. }
  199. else if($row->is_show == 2)
  200. {
  201. $row->is_show = 1;
  202. }
  203. break;
  204. case 'del':
  205. $row->del = 2;
  206. break;
  207. case 'sort':
  208. if(is_numeric($input['sort']))
  209. {
  210. $row->sort = $input['sort'];
  211. }
  212. break;
  213. }
  214. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  215. }
  216. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  217. }
  218. /*
  219. * 优选新房 - 批量删除
  220. * */
  221. public function actionHousedelall()
  222. {
  223. $input = Yii::$app->request->post();
  224. $delall = PushHouserecommend::deleteAll(['id'=>$input['id']]);
  225. if ($delall){
  226. return Help::JsonCode(Help::SUCCESS,'批量删除成功');
  227. }
  228. return Help::JsonCode(Help::ERROR,'批量删除失败');
  229. }
  230. /********************below author:eit end***********************/
  231. }