MapController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/26
  6. * Time: 上午11:13
  7. */
  8. namespace frontend\controllers;
  9. use frontend\base\CommonController;
  10. use frontend\base\Help;
  11. use Yii;
  12. use frontend\server\IndexServer;
  13. class MapController extends CommonController
  14. {
  15. public function actionHome()
  16. {
  17. $IndexModel = new IndexServer();
  18. $sub = $IndexModel->Subject();
  19. $price = $IndexModel->PriceList();
  20. $type = $IndexModel->HouseType();
  21. $city = new \common\models\CategoryCity();
  22. $city->pid = 0;
  23. $city->state = 1;
  24. $city->abroad = 1;
  25. $citylist = $city->getList([]);
  26. return $this->render('home',['sub'=>$sub,'price'=>$price,'type'=>$type,'city'=>$citylist]);
  27. }
  28. public function actionDetails()
  29. {
  30. return $this->render('details');
  31. }
  32. public function actionHouselist()
  33. {
  34. $model = new \common\models\House();
  35. $input = Yii::$app->request->post();
  36. $input['is_view']=1;
  37. if(!empty($input['data']['content']))
  38. {
  39. $str = $input['data']['content'];
  40. $mb = mb_strlen($str,'utf-8');
  41. $st = strlen($str);
  42. if($st==$mb)
  43. {
  44. $input['pinyin'] = $str;
  45. }
  46. else
  47. {
  48. $input['name'] = $input['data']['content'];
  49. }
  50. }
  51. if(!empty($input['data']['city']))
  52. {
  53. $input['city'] = $input['data']['city'];
  54. }
  55. if(!empty($input['data']['price']))
  56. {
  57. $input['price'] = $input['data']['price'];
  58. }
  59. if(!empty($input['data']['houseType']))
  60. {
  61. $type = new \common\models\HouseType();
  62. $type->type_id = $input['data']['houseType'];
  63. $typeModel = $type->getList(['hid']);
  64. if(!empty($typeModel))
  65. {
  66. $input['id'] = array_unique(array_column($typeModel,'hid'));
  67. }
  68. }
  69. if(!empty($input['data']['trait']))
  70. {
  71. $input['characteristic'] = $input['data']['trait'];
  72. }
  73. $input['sort'] = 'map';
  74. $rows = $model->getList($input);
  75. if(!empty($rows))
  76. {
  77. $h = new \frontend\server\HouseServer();
  78. foreach ($rows as &$val)
  79. {
  80. $val['characteristic'] = $h->Subject(json_encode($val['characteristic']),3);
  81. $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'];
  82. }
  83. return Help::JsonData(Help::SUCCESS,'成功',$model->getListTotal($input),$rows);
  84. }
  85. return Help::JsonCode(Help::ERROR,'暂无相关楼盘信息');
  86. }
  87. //省份
  88. public function actionProvince()
  89. {
  90. //省份
  91. $cityQueryPid = \common\models\CategoryCity::find()->andWhere(['pid'=>0])->andWhere(['<>','ll','null'])->andWhere(['del'=>1,'state'=>1])->asArray()->all();
  92. $pid = array_column($cityQueryPid,'city_name','id');
  93. $pidll = array_column($cityQueryPid,'ll','id');
  94. //所有区域
  95. $cityQuerySon = \common\models\CategoryCity::find()->andWhere(['<>','pid',0])->andWhere(['state'=>1])->asArray()->all();
  96. $arr = [];
  97. foreach ($cityQuerySon as $val)
  98. {
  99. if(array_key_exists($val['pid'],$pid))
  100. {
  101. $arr[$val['pid']]['city'] = $pid[$val['pid']];
  102. $arr[$val['pid']]['cityid'][] = $val['id'];
  103. $arr[$val['pid']]['pid'] = $val['pid'];
  104. $arr[$val['pid']]['point'] = $pidll[$val['pid']];
  105. $arr[$val['pid']]['rank'] = 1;
  106. }
  107. }
  108. $arr = array_values($arr);
  109. if(!empty($arr))
  110. {
  111. foreach ($arr as &$val)
  112. {
  113. $val['count'] = \common\models\House::find()->andWhere(['city'=>$val['cityid']])->andWhere(['del'=>1,'state'=>1])->andWhere(['is_view'=>1])->count();
  114. }
  115. return Help::JsonCode(Help::SUCCESS,'成功',$arr);
  116. }
  117. return Help::JsonCode(Help::ERROR,'暂无资料');
  118. }
  119. //区域
  120. public function actionCity()
  121. {
  122. $cityQueryPid = \common\models\CategoryCity::find()->select(['id','city_name','ll'])->andFilterWhere(['pid'=>Yii::$app->request->get('pid')])->andWhere(['del'=>1])->asArray()->all();
  123. $arr = [];
  124. foreach ($cityQueryPid as $key=>$val)
  125. {
  126. $arr[$key]['city'] = $val['city_name'];
  127. $arr[$key]['pid'] = $val['id'];
  128. $arr[$key]['point'] = $val['ll'];
  129. $arr[$key]['rank'] = 2;
  130. $arr[$key]['count'] = \common\models\House::find()->andWhere(['city'=>$val['id']])->andWhere(['del'=>1])->andWhere(['is_view'=>1])->count();
  131. }
  132. if(!empty($arr))
  133. {
  134. return Help::JsonCode(Help::SUCCESS,'成功',$arr);
  135. }
  136. return Help::JsonCode(Help::ERROR,'暂无资料');
  137. }
  138. //区域楼盘
  139. public function actionCityhouse()
  140. {
  141. $input = Yii::$app->request->get('pid');
  142. $model = new \common\models\House();
  143. $model->city = Yii::$app->request->get('pid');
  144. $rows = $model->CityHouse();
  145. if(!empty($rows))
  146. {
  147. $arr = [];
  148. foreach ($rows as $key=>$val)
  149. {
  150. $arr[$key]['title'] = $val['name'];
  151. $arr[$key]['hx'] = $val['main_units'];
  152. $arr[$key]['dq'] = '['.$val['city_name'].']';
  153. $arr[$key]['point'] = str_replace(',','|',$val['longitude_latitude']);
  154. $arr[$key]['isOpen'] = 0;
  155. $arr[$key]['icon']['w'] = 21;
  156. $arr[$key]['icon']['h'] = 21;
  157. $arr[$key]['icon']['l'] = 0;
  158. $arr[$key]['icon']['w'] = 0;
  159. $arr[$key]['icon']['t'] = 0;
  160. $arr[$key]['icon']['x'] = 0;
  161. $arr[$key]['icon']['lb'] = 5;
  162. $arr[$key]['content']['pic'] = !empty($val['sale_price']) ? $val['sale_price'].$val['price_unit'] : '待定';
  163. $arr[$key]['content']['add'] = $val['address'];
  164. $arr[$key]['content']['href'] = '/house/'.$val['id'].'/';
  165. $arr[$key]['content']['img'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'];
  166. }
  167. return Help::JsonCode(Help::SUCCESS,'成功',$arr);
  168. }
  169. }
  170. public function actionPidcity()
  171. {
  172. $city = new \common\models\CategoryCity();
  173. $city->pid = Yii::$app->request->post('id');
  174. $citylist = $city->getList([]);
  175. if(!empty($citylist))
  176. {
  177. return Help::JsonCode(Help::SUCCESS,'成功',$citylist);
  178. }
  179. return Help::JsonCode(Help::ERROR,'失败');
  180. }
  181. }