MapController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace mobile\controllers;
  3. use mobile\base\CommonController;
  4. use mobile\base\Help;
  5. use Yii;
  6. use mobile\server\HouseServer;
  7. class MapController extends CommonController{
  8. /*地图*/
  9. public function actionMap()
  10. {
  11. $privince=$this->province();
  12. return $this->render('mapindex',['privince'=>$privince]);
  13. }
  14. private function province()
  15. {
  16. $city = new \common\models\CategoryCity();
  17. $city->abroad = 1;
  18. $city->state = 1;
  19. $city->pid = 0;
  20. $province = $city->getList([]);
  21. return $province;
  22. }
  23. /**地区 价格 特色 户型--->因改版V2此方法字18年11月26日废掉*/
  24. public function actionGetprovince()
  25. {
  26. $input=Yii::$app->request->post();
  27. if(empty($input)) return false;
  28. switch ($input['typeName'])
  29. {
  30. case 'area':
  31. $city = new \common\models\CategoryCity();
  32. $city->state = 1;
  33. $city->pid = 0;
  34. $province = $city->getList([]);
  35. if(!empty($province)) return Help::JsonCode(Help::SUCCESS,'成功',$province);
  36. break;
  37. case 'price':
  38. $PriceModel = new \common\models\HousesPrice();
  39. $price = $PriceModel->getList([],['id','price']);
  40. if(!empty($price)) return Help::JsonCode(Help::SUCCESS,'成功',$price);
  41. break;
  42. case 'characteristic':
  43. $zhutiModel = new \common\models\Characteristic();
  44. $theme = $zhutiModel->getList([],['id','name']);
  45. if(!empty($theme)) return Help::JsonCode(Help::SUCCESS,'成功',$theme);
  46. break;
  47. case 'type':
  48. $TypeModel = new \common\models\CategoryHousetype();
  49. $TypeModel->state=1;
  50. $type = $TypeModel->getList([],['id','huxing_name']);
  51. if(!empty($type)) return Help::JsonCode(Help::SUCCESS,'成功',$type);
  52. break;
  53. }
  54. }
  55. /*传入父id获取城市*/
  56. public function actionGetcity()
  57. {
  58. $model = new \common\models\CategoryCity();
  59. $input = Yii::$app->request->post();
  60. $model->pid = $input['city'];
  61. $rows = $model->getList([],['id','city_name','ll']); //获取所有子类
  62. $rows=$this->houseCount($rows);
  63. if(!empty($rows)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','get_success'),$rows);
  64. }
  65. private function houseCount($city)
  66. {
  67. if(!is_array($city)) return false;
  68. $rows=[];
  69. $input=[];
  70. // p($city);
  71. $cityId = array_column($city,'id');
  72. $query = \common\models\House::find();
  73. $query->select(["count('city') as num",'city']);
  74. $query->andWhere(['city'=>$cityId]);
  75. $query->andWhere(['del'=>1]);
  76. $query->andWhere(['is_view'=>1]);
  77. $query->groupBy('city');
  78. $cityCount = $query->asArray()->all();
  79. if($cityCount)
  80. {
  81. $cityRows = array_column($cityCount,'num','city');
  82. foreach ($city as &$val)
  83. {
  84. $val['number'] = isset($cityRows[$val['id']]) ? $cityRows[$val['id']] : 0;
  85. $val['point'] = $val['ll'];
  86. $val['name'] = $val['city_name'];
  87. }
  88. return $city;
  89. }
  90. return false;
  91. // $model = new HouseServer();
  92. // foreach($city as $k=>$v)
  93. // {
  94. // $city[$k]['city']=$v['id'];
  95. // $rows[$k] = $model->SearchForm($city[$k]);
  96. // }
  97. // foreach($rows as $key=>$val)
  98. // {
  99. // foreach($val['data'] as $kk=>$vv)
  100. // {
  101. // $input[$key]['id']=$vv['city'];
  102. // $input[$key]['name']=$vv['city_name'];
  103. // $input[$key]['point']=$vv['ll'];
  104. // $input[$key]['number']=$val['count'];
  105. // }
  106. // }
  107. }
  108. /*加载楼盘*/
  109. public function actionHouselist()
  110. {
  111. $model = new \common\models\House();
  112. $input = Yii::$app->request->post();
  113. $input['limit'] = 20;
  114. if(isset($input['city']) && !empty($input['city']))
  115. {
  116. $city = (new \common\models\CategoryCity())->getCityNameTurnId($input);
  117. if($city)
  118. {
  119. $model->city = $city['id'];
  120. }
  121. }
  122. $data = $model->PcHouseList($input,['pfg_category_city.city_name','pfg_category_city.ll','pfg_house.id','pfg_house.city','pfg_house.price','pfg_house.name','pfg_house_detail.address','pfg_house_detail.main_units','pfg_house_detail.price_unit','pfg_house_detail.longitude_latitude','pfg_house.thumb','pfg_house.sale_price','pfg_house.characteristic']);
  123. if($data != null) {
  124. $characteristic = new \common\models\Characteristic();
  125. $charList = $characteristic->getList([]);
  126. $characteristicId = array_column($charList, 'name', 'id');
  127. $chara = array_column($data, 'characteristic', 'id');
  128. $charaArrs = [];
  129. //处理特色主题
  130. foreach ($chara as $key => $val) {
  131. $arr = json_decode($val, true);
  132. if (is_array($arr) && !empty($arr)) {
  133. foreach ($arr as $k => $v) {
  134. if (isset($characteristicId[$v])) {
  135. $charaArrs[$key][$k] = $characteristicId[$v];
  136. }
  137. }
  138. }
  139. }
  140. $Tel = new \common\models\CategoryTelCity();
  141. $telRow = $Tel->QgetAll();
  142. $cityTel = [];
  143. foreach ($telRow as &$v) {
  144. $cityTel[$v['cid']] = explode(',', $v['tel']);
  145. }
  146. $randArr = [];
  147. foreach ($data as &$val) {
  148. $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'].'/'.'same';
  149. if (isset($charaArrs[$val['id']])) {
  150. //随机选择3个特色主题
  151. if (count($charaArrs[$val['id']]) > 3) {
  152. $ranChar = array_rand($charaArrs[$val['id']], 3);
  153. $randArr[] = $charaArrs[$val['id']][$ranChar[0]];
  154. $randArr[] = $charaArrs[$val['id']][$ranChar[1]];
  155. $randArr[] = $charaArrs[$val['id']][$ranChar[2]];
  156. $val['characteristic'] = $randArr;
  157. $randArr = [];
  158. } else {
  159. $val['characteristic'] = $charaArrs[$val['id']];
  160. }
  161. }
  162. if (isset($cityTel[$val['city']])) {
  163. $rand = array_rand($cityTel[$val['city']], 1);
  164. $val['citytel'] = $cityTel[$val['city']][$rand];
  165. } else {
  166. $val['citytel'] = Yii::$app->params['default_dialtel'];
  167. }
  168. }
  169. $rows = ['data'=>$data];
  170. }
  171. if(!empty($rows))
  172. {
  173. return Help::JsonCode(Help::SUCCESS,'成功',$rows);
  174. }
  175. return Help::JsonCode(Help::ERROR,'暂无数据');
  176. }
  177. private function cityNameId($cityname)
  178. {
  179. $model = new \common\models\CategoryCity();
  180. $row=$model->getCityNameTurnId($cityname);
  181. if($row) return $row;
  182. $row['city']=$row['id'];
  183. return $row;
  184. }
  185. /*搜索*/
  186. public function actionSearch()
  187. {
  188. $model = new HouseServer();
  189. $rows = $model->SearchForm(Yii::$app->request->post('input'));
  190. if(!empty($rows['data']))
  191. {
  192. return Help::JsonData(Help::SUCCESS,'成功',$rows['count'],$rows);
  193. }
  194. return Help::JsonCode(Help::ERROR,'暂无相关楼盘数据');
  195. }
  196. /*详情*/
  197. public function actionDetails()
  198. {
  199. $model = new HouseServer();
  200. $row = $model->Details();
  201. $arr=[];
  202. if(!empty($row))
  203. {
  204. $arr['id']=$row['house']['id'];
  205. $arr['name']=$row['house']['name'];
  206. $arr['state']=$row['house']['state'];
  207. $arr['thumb']=Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$row['house']['thumb'].'/pfgwatermark';
  208. $arr['sale_price']=$row['house']['sale_price'];
  209. $arr['price_unit']=$row['house']['price_unit'];
  210. $arr['main_units']=$row['house']['main_units'];
  211. $arr['city_name']=$row['house']['city_name'];
  212. $arr['characteristic']=$row['characteristic'];
  213. return Help::JsonCode(Help::SUCCESS,'成功',$arr);
  214. }
  215. return Help::JsonCode(Help::ERROR,'暂无相关楼盘数据');
  216. }
  217. }