IndexController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace frontend\controllers;
  3. use common\models\Brand;
  4. use common\models\MiniRotation;
  5. use frontend\base\CommonController;
  6. use frontend\server\IndexServer;
  7. use frontend\server\HouseServer;
  8. use common\models\Characteristic;
  9. use frontend\base\Help;
  10. use Yii;
  11. class IndexController extends CommonController
  12. {
  13. public function actionIndex ()
  14. {
  15. // $IndexModel = new IndexServer();
  16. // $city = $IndexModel->CityList(); //区域
  17. //
  18. // $price = $IndexModel->PriceList(); //价格区间
  19. //
  20. // $sub = $IndexModel->Subject(); //特色主题
  21. //
  22. // $type = $IndexModel->HouseType(); //楼盘户型
  23. //
  24. // $lunbo = $IndexModel->Lunbo(); //轮播图
  25. //
  26. // $Hotactivity = $IndexModel->Hotactivity(); //热门活动
  27. //
  28. // $pushCity = $IndexModel->getPushCity( 5 ); //获取首页推送地区栏位区域数据
  29. //
  30. // $Choice = $IndexModel->Choice(); //本周精选
  31. //
  32. // $hotHouse = $IndexModel->HotHouse(); //热销楼盘
  33. // $cityInfo = $IndexModel->CityInfo(); //区域介绍
  34. // $KnowledgeBase = $IndexModel->getKnowledgeBase(); //知识库
  35. //
  36. // $pushaerial = $IndexModel->getPushAerial( 4 );
  37. //
  38. // $recommendcat = $IndexModel->RecommendCat(); //精选新房
  39. // $recommendcatone = $IndexModel->RecommendCatOne(); //精选新房根据地区读一条 大坑,注意排序
  40. // $tuijian = new \common\models\PushHousesale();
  41. // $tuijian->type = 2;
  42. // $Hot = $tuijian->Homegetlist( 4 );
  43. //
  44. // $Ctype = $IndexModel->Characteristic();
  45. // $news = $IndexModel->newsColumn();
  46. // $CityPrice = $IndexModel->Pricetrend();
  47. // $Gouf = $IndexModel->Goufang( 5 );
  48. // $newsGouf = $IndexModel->Goufang( 6 );
  49. // $Villa = $IndexModel->Villa(); //别墅专区
  50. //获取当前模块
  51. $IndexModel = new IndexServer();
  52. $city = $IndexModel->CityList(); //热门区域
  53. $price = $IndexModel->PriceList(); //价格区间
  54. $BrandModel = new Brand();
  55. $brand = $BrandModel->getPcSearchBrand(1, 12); //品牌筛选
  56. $hotHouse = $IndexModel->getHomeHotHouse(6); //首页热门楼盘
  57. $VrHouse = $IndexModel->getVrHouse(4); //首页VR全景看房推送
  58. $pushCity = $IndexModel->getPushCity(5); //获取首页推送地区栏位区域数据
  59. $pushaerial = $IndexModel->getPushAerial(4); //获取首页航拍看房推送
  60. $voluntarilylive = $IndexModel->getVoluntarilylive(3); //自动获取直播回放3个
  61. $allcity = $IndexModel->getAllCityList(); //获取所有地区
  62. $pushnews = $IndexModel->getPushNews(5); //获取推送资讯栏目
  63. $readhouseword = $IndexModel->getPushTitle(3,8); //首页热搜词
  64. $gourylist = $IndexModel->getPushTitle(4,3); //首页优惠团购列表
  65. $lunbo = $IndexModel->Lunbo( 5); //轮播图
  66. $choice = $IndexModel->Lunbo(2); //本周精选
  67. return $this->render( 'index' ,[
  68. 'city' => $city,
  69. 'price' => $price,
  70. 'lb' => $lunbo,
  71. 'brand' => $brand,
  72. 'hotHouse' => $hotHouse,
  73. 'VrHouse' => $VrHouse,
  74. 'pushCity' => $pushCity,
  75. 'pushaerial'=>$pushaerial,
  76. 'voluntarilylive'=>$voluntarilylive,
  77. 'allcity'=>$allcity,
  78. 'pushnews'=>$pushnews,
  79. 'readhouseword'=>$readhouseword,
  80. 'gourylist'=>$gourylist,
  81. 'choice'=>$choice
  82. ]);
  83. }
  84. public function actionRecommendlist ()
  85. {
  86. $model = new \common\models\PushHouserecommend();
  87. $input = Yii::$app->request->get();
  88. if ( !empty( Yii::$app->request->get( 'city' ) ) ) {
  89. $cityModel = new \common\models\CategoryCity();
  90. $city_ids = $cityModel->TestingId( Yii::$app->request->get( 'city' ) );
  91. $input[ 'city' ] = $city_ids;
  92. }
  93. $recommend = $model->getList( $input );
  94. foreach ( $recommend as $k => $v ) {
  95. $recommend[ $k ][ 'characteristic' ] = $this->Subject( json_decode( $v[ 'characteristic' ] ) , 3 );
  96. }
  97. $recommendData[ 'recommend' ] = $recommend;
  98. $IndexModel = new IndexServer();
  99. $recommendData[ 'city' ] = $IndexModel->CityList();
  100. if ( !empty( $recommendData ) ) {
  101. return Help::JsonCode( Help::SUCCESS , '成功' , $recommendData );
  102. }
  103. return Help::JsonCode( Help::ERROR , '暂无数据' );
  104. }
  105. public function actionSearch ()
  106. {
  107. $IndexModel = new IndexServer();
  108. $city = $IndexModel->CityList(); //区域
  109. $price = $IndexModel->PriceList(); //价格区间
  110. $sub = $IndexModel->Subject(); //特色主题
  111. $type = $IndexModel->HouseType(); //楼盘户型
  112. $tuijian = new \common\models\PushHousesale();
  113. $tuijian->type = 2;
  114. $Hot = $tuijian->Homegetlist( 4 );
  115. $tuijian->type = 4;
  116. $sea = $tuijian->Homegetlist( 6 );
  117. //热门区域
  118. $hotcity = ( new MiniRotation() )->getAll( 4 , 3 );
  119. return $this->renderPartial( 'search' , [ 'city' => $city ,
  120. 'price' => $price ,
  121. 'type' => $type ,
  122. 'sub' => $sub ,
  123. 'hot' => $Hot ,
  124. 'sea' => $sea ,
  125. 'hotcity' => $hotcity ,
  126. ] );
  127. }
  128. /*
  129. * 弹窗搜索结果
  130. * */
  131. public function actionSearchresult ()
  132. {
  133. $model = new HouseServer();
  134. $res = $model->SearchHouseName( Yii::$app->request->get() );
  135. if ( !empty( $res ) ) {
  136. return Help::JsonCode( Help::SUCCESS , '成功' , $res );
  137. }
  138. return Help::JsonCode( Help::ERROR , '暂无数据' );
  139. }
  140. /**
  141. * 区域价格走势
  142. */
  143. public function actionCityprice ()
  144. {
  145. $model = new \common\models\PushCityprice();
  146. $model->city_id = Yii::$app->request->get( 'id' );
  147. $rows = $model->CityRecordPrice();
  148. if ( !empty( $rows ) ) {
  149. $arr = [];
  150. foreach ( $rows as &$val ) {
  151. // $timestrap = strtotime($val['price_at']);
  152. $time = $val[ 'price_at' ];
  153. $val[ 'price_at' ] = trim( date( 'm' , $time ) . '月' , '0' );
  154. $arr[ 'price_at_n' ][] = trim( date( 'Y' , $time ) . '年' , '0' );
  155. $arr[ 'categories' ][] = $val[ 'price_at' ];
  156. $arr[ 'data' ][] = $val[ 'price' ];
  157. $arr[ 'region' ][] = $val[ 'city_name' ];
  158. }
  159. return Help::JsonCode( Help::SUCCESS , '成功' , $arr );
  160. }
  161. }
  162. /**
  163. * 楼盘价格走势
  164. */
  165. public function actionHouseprice ()
  166. {
  167. $input = Yii::$app->request->post();
  168. if ( is_numeric( $input[ 'id' ] ) ) {
  169. $model = new \common\models\HousePriceRecord();
  170. $model->hid = $input[ 'id' ];
  171. $rows = $model->getList( [] );
  172. if ( !empty( $rows ) ) {
  173. $arr = [];
  174. foreach ( $rows as $val ) {
  175. $arr[ 'categories' ][] = $val[ 'create_time' ];
  176. $arr[ 'data' ][] = $val[ 'price' ];
  177. $arr[ 'unit' ][] = $val[ 'price_unit' ];
  178. }
  179. return Help::JsonCode( Help::SUCCESS , '成功' , $arr );
  180. }
  181. }
  182. return Help::JsonCode( Help::ERROR , '失败' );
  183. }
  184. public function actionAa ()
  185. {
  186. phpinfo();
  187. }
  188. //特色主题 超过3个随机返回3个元素
  189. public function Subject ( $id , $num = 3 )
  190. {
  191. $char = new Characteristic();
  192. if ( is_array( $id ) && !empty( $id ) ) {
  193. $char->id = $id;
  194. }
  195. $charMode = array_column( $char->getList( [] , [ 'id' , 'name' ] ) , 'name' , 'id' );
  196. if ( $charMode != null ) {
  197. $count = count( $charMode );
  198. $arr = [];
  199. if ( $count >= 3 ) {
  200. $rand = array_rand( $charMode , $num );
  201. foreach ( $rand as $key => $val ) {
  202. $arr[ $key ] = $charMode[ $val ];
  203. }
  204. } else {
  205. $arr = $charMode;
  206. }
  207. return $arr;
  208. }
  209. }
  210. }