HouseServer.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <?php
  2. namespace wechat\server;
  3. use common\models\Developers;
  4. use common\models\House;
  5. use common\models\HouseAlbum;
  6. use common\models\HouseComment;
  7. use common\models\HouseCommentLikes;
  8. use common\models\HouseCommentreply;
  9. use common\models\Search;
  10. use wechat\base\Help;
  11. use Yii;
  12. use common\models\HouseNews;
  13. use common\models\CategoryLabel;
  14. use common\models\HousePermit;
  15. use common\models\HouseType;
  16. class HouseServer{
  17. public static function Search($abroad = 1)
  18. {
  19. //搜索内容
  20. $renderData = [];
  21. $CityModel = new \common\models\CategoryCity();
  22. $CityModel->pid = 0;
  23. $CityModel->state = 1;
  24. if(Yii::$app->hostserver->hostId != 0)
  25. {
  26. $CityModel->pid = Yii::$app->hostserver->hostId;
  27. }else{
  28. $CityModel->abroad = $abroad;
  29. }
  30. // $renderData['city'] = $CityModel->getList([],['city_name','id']);
  31. $renderData['city'] = $CityModel->getList([],['city_name','id','pinyin']);
  32. // p($renderData);
  33. $input = Yii::$app->request->get();
  34. if(!empty($input['city']))
  35. {
  36. $renderData['select_city'] = $CityModel->FindById($input['city']);
  37. }
  38. $PriceModel = new \common\models\HousesPrice();
  39. $renderData['price'] = $PriceModel->getList([],['id','price']);
  40. if(!empty($input['price']))
  41. {
  42. $renderData['select_price'] = $input['price'];
  43. }
  44. $TypeModel = new \common\models\CategoryHousetype();
  45. $renderData['type'] = $TypeModel->getList([],['id','huxing_name']);
  46. if(!empty($input['type']))
  47. {
  48. $renderData['select_type'] = $TypeModel->FindById($input['type']);
  49. }
  50. $zhutiModel = new \common\models\Characteristic();
  51. $renderData['zhuti'] = $zhutiModel->getList([],['id','name']);
  52. if(!empty($input['characteristic']))
  53. {
  54. $renderData['select_zhuti'] = $zhutiModel->FindById($input['characteristic']);
  55. }
  56. return $renderData;
  57. }
  58. //搜索
  59. public function SearchForm($input)
  60. {
  61. $query = new House();
  62. if(!empty($input['price']))
  63. {
  64. $query->price = $input['price'];
  65. }
  66. if(!empty($input['characteristic']))
  67. {
  68. $query->characteristic = $input['characteristic'];
  69. }
  70. if(!empty($input['name']))
  71. {
  72. $query->name = $input['name'];
  73. }
  74. //处理区域
  75. if(!empty($input['city']))
  76. {
  77. $CityModel = new \common\models\CategoryCity();
  78. $pro = $CityModel->FindById($input['city']);
  79. if($pro['pid'] == 0)
  80. {
  81. $r = $CityModel->GetAllSon($input['city'],['city_name','id']);
  82. if(!empty($r))
  83. {
  84. $input['city'] = array_column($r,'id');
  85. }
  86. }
  87. $query->city = $input['city'];
  88. }
  89. else if(empty($input['city']) && Yii::$app->hostserver->hostId !=0)
  90. {
  91. $query->city = (new \common\models\CategoryCity())->TestingId(Yii::$app->hostserver->hostId);
  92. }else if(empty($input['city']))
  93. {
  94. $CityModel = new \common\models\CategoryCity();
  95. $CityModel->pid = 0;
  96. $CityModel->state = 1;
  97. $CityModel->abroad = $input['abroad'];
  98. $mainCity = $CityModel->getList([],['id']);
  99. if($mainCity)
  100. {
  101. $city_Id = $CityModel->GetAllSon(array_column($mainCity,'id'),['id']);
  102. if(!empty($city_Id))
  103. {
  104. $query->city = array_column($city_Id,'id');
  105. }
  106. }
  107. }
  108. if(!empty($input['type']))
  109. {
  110. $type = \common\models\HouseType::find();
  111. $typeModel = $type->andWhere(['type_id'=>$input['type'],'del'=>1])->asArray()->all();
  112. if(!empty($typeModel))
  113. {
  114. $query->id = array_unique(array_column($typeModel,'hid'));
  115. }else{
  116. $query->id = 0;
  117. }
  118. }
  119. if(!empty($input['name']))
  120. {
  121. $arr = (new \common\api\HouseServer())->HouseNameConvert($input['name']);
  122. if(!empty($arr['pinyin']))
  123. {
  124. $query->pinyin = $arr['pinyin'];
  125. }
  126. if(!empty($arr['zhongwen']))
  127. {
  128. $query->name = $arr['zhongwen'];
  129. }
  130. $query->city = '';
  131. }
  132. if (!empty($input['hao'])){
  133. $data = $query->PcHouseList($input,['pfg_house.area','pfg_category_city.city_name','pfg_house.id','pfg_house.is_tel','pfg_house.city','pfg_house.price','pfg_house.name','pfg_house_detail.address','pfg_house_detail.developers','pfg_house_detail.main_units','pfg_house_detail.price_unit','pfg_house.thumb','pfg_house.sale_price','pfg_house.characteristic','pfg_pushm_mansion.haoqi','pfg_pushm_mansion.jingmi','pfg_pushm_mansion.reason','pfg_pushm_mansion.img as hao_img','pfg_developers.logo']);
  134. }else{
  135. $data = $query->PcHouseList($input,['pfg_house.area','pfg_category_city.city_name','pfg_house.id','pfg_house.is_tel','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.thumb','pfg_house.sale_price','pfg_house.characteristic','pfg_house.click_num']);
  136. }
  137. //豪宅总数
  138. if (!empty($input['hao'])){
  139. $count = $query->Count_Mansion();
  140. }else{
  141. //正常数据的整数
  142. $count = $query->PcHouseListTotal();
  143. }
  144. if($count<1)
  145. {
  146. $count = 0;
  147. }
  148. if($data != null) {
  149. // $Tel = new \common\models\CategoryTelCity();
  150. // $telRow = $Tel->QgetAll();
  151. //
  152. // $cityTel = [];
  153. // foreach ($telRow as &$v) {
  154. // $cityTel[$v['cid']] = explode(',', $v['tel']);
  155. // }
  156. $randArr = [];
  157. foreach ($data as &$val) {
  158. if($val['click_num'] < 100)
  159. {
  160. $val['click_num'] = rand(200,900);
  161. }
  162. $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'];
  163. if (!empty($val['hao_img'])){
  164. $val['hao_img'] = $imgUrl = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['housealbum'] . $val['hao_img'];
  165. }
  166. if (!empty($val['logo'])){
  167. $val['logo'] = $imgUrl = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['developers'] . $val['logo'];
  168. }
  169. $val['characteristic'] = \common\fm\HouseHandle::ChangeCharacteristic($val['characteristic']);
  170. $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  171. if(empty($val['is_tel']))
  172. {
  173. if(!empty($val['area']) && \common\fm\HouseHandle::ChangeCityTel($val['area']) != Yii::$app->params['default_dialtel']){
  174. $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['area']);
  175. }else{
  176. $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  177. }
  178. // $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  179. }
  180. else {
  181. $val['citytel'] = $val['is_tel'];
  182. }
  183. // if (isset($cityTel[$val['city']])) {
  184. // $rand = array_rand($cityTel[$val['city']], 1);
  185. // $val['citytel'] = $cityTel[$val['city']][$rand];
  186. //
  187. // } else {
  188. // $val['citytel'] = Yii::$app->params['default_dialtel'];
  189. // }
  190. }
  191. return ['data'=>$data,'count'=>$count];
  192. }
  193. }
  194. /*
  195. * 搜索楼盘名字
  196. * */
  197. public function SearchHouseName($input)
  198. {
  199. if(!empty($input['title']))
  200. {
  201. (new Search())->SaveSearch($input['title']);
  202. $query = new House();
  203. $arr = (new \common\api\HouseServer())->HouseNameConvert($input['title']);
  204. if(!empty($arr['pinyin']))
  205. {
  206. $query->pinyin = $arr['pinyin'];
  207. }
  208. if(!empty($arr['zhongwen']))
  209. {
  210. $query->name = $arr['zhongwen'];
  211. }
  212. $result = $query->HouseName();
  213. return $result;
  214. }
  215. }
  216. public function Details()
  217. {
  218. $input = Yii::$app->request->get();
  219. if(isset($input['hid']) && is_numeric($input['hid']))
  220. {
  221. //楼盘点击量
  222. $click = new \common\api\HouseServer();
  223. $click->HouseClick($input['hid']);
  224. $arr = [];
  225. //所有信息,后期优化显示字段
  226. $model = new House();
  227. $model->id = $input['hid'];
  228. $select = ['pfg_house.*','pfg_house_detail.*','pfg_category_city.city_name'];
  229. $arr['house'] = $model->Qdetails($select);
  230. // $arr['house']['info'] = strip_tags($arr['house']['info']);
  231. //楼盘点击量
  232. if(!empty($arr['house']))
  233. {
  234. //特色主题
  235. // $sub = new IndexServer();
  236. // $arr['characteristic'] = $sub->Subject(json_decode($arr['house']['characteristic']),3);
  237. if(isset($arr['house']['characteristic']))
  238. {
  239. $arr['characteristic'] = \common\fm\HouseHandle::ChangeCharacteristic($arr['house']['characteristic']);
  240. }
  241. //楼盘相册
  242. $queryAlbum = new HouseAlbum();
  243. $arr['album'] = $queryAlbum->Groupfind_Total(['hid'=>$input['hid']],4);
  244. //楼盘户型
  245. $queryType = new \common\models\HouseType();
  246. $queryType->hid = $input['hid'];
  247. $arr['type'] = $queryType->MgetList(2,['area','title','img','indoor_info']);
  248. //电话
  249. // $arr['house']['tel'] = $sub->RandTel( $arr['house']['city']);
  250. // $arr['house']['tel'] = \common\fm\HouseHandle::ChangeCityTel($arr['house']['city']);
  251. // if(empty($arr['house']['is_tel']))
  252. // {
  253. // $arr['house']['tel'] = \common\fm\HouseHandle::ChangeCityTel($arr['house']['city']);
  254. // }
  255. // else
  256. // {
  257. // $arr['house']['tel'] = $arr['house']['is_tel'];
  258. // }
  259. // $arr['house']['tel'] = Yii::$app->params['default_dialtel'];
  260. $arr['house']['tel'] = \common\fm\HouseHandle::ChangeCityTel($arr['house']['city']);
  261. if(empty($arr['house']['is_tel']))
  262. {
  263. //新增三级联动区域的电话获取修改
  264. if(!empty($arr['house']['area']) && \common\fm\HouseHandle::ChangeCityTel($arr['house']['area']) != Yii::$app->params['default_dialtel']){
  265. $arr['house']['tel'] = \common\fm\HouseHandle::ChangeCityTel($arr['house']['area']);
  266. }else{
  267. $arr['house']['tel'] = \common\fm\HouseHandle::ChangeCityTel($arr['house']['city']);
  268. }
  269. }
  270. else
  271. {
  272. $arr['house']['tel'] = $arr['house']['is_tel'];
  273. }
  274. $arr['house']['info'] = strip_tags($arr['house']['info']);
  275. //预售证书
  276. $certificate = new \common\models\HousePermit();
  277. $certificate->hid = $input['hid'];
  278. $arr['certificate'] = $certificate->FindNewest();
  279. //楼盘状态
  280. $arr['house']['state'] =Yii::$app->params['HouseSalesStatus'][$arr['house']['state']];
  281. //新闻
  282. $arr['news'] = $this->NewsDynamic($input);
  283. //推荐楼盘
  284. $model = new \common\models\House();
  285. $model->city = $arr['house']['city'];
  286. $model->is_push = 2;
  287. $arr['tuijian_house'] = $model->randList(3,['house_id'=>$arr['house']['id']]);
  288. if(!empty($arr['tuijian_house']))
  289. {
  290. foreach($arr['tuijian_house'] as &$val)
  291. {
  292. $val['characteristic'] = \common\fm\HouseHandle::ChangeCharacteristic($val['characteristic']);
  293. $val['tel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  294. $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'].'/'.'same';
  295. }
  296. }
  297. //楼盘点评
  298. $arr['remark'] = $this->getHouseRemarkList($input,2);
  299. return $arr;
  300. }
  301. }
  302. }
  303. public function NewsDynamic($input)
  304. {
  305. $model = new HouseNews();
  306. $model->hid =$input['hid'];
  307. $rows = $model->QgetNews(2);
  308. if($rows != null)
  309. {
  310. return $rows;
  311. }
  312. }
  313. //楼盘详情页数据
  314. public function ParamsDetails()
  315. {
  316. $input = Yii::$app->request->get();
  317. if(is_numeric($input['hid']))
  318. {
  319. $result = [];
  320. $model = new House();
  321. $model->id = $input['hid'];
  322. $result['house'] = $model->HousesAll();
  323. if($result['house'])
  324. {
  325. $sub = new IndexServer();
  326. $result['house']['characteristic'] = $sub->Subject(json_decode($result['house']['characteristic']),3);
  327. $result['house']['tel'] = $sub->RandTel($result['house']['city']);
  328. $result['house']['architecture_type'] = $this->ArchitectureType(json_decode($result['house']['architecture_type']));
  329. //预售证号
  330. $zheng = new HousePermit();
  331. $result['house']['zhengshu'] =$zheng->getList($input);
  332. return $result;
  333. }
  334. //价格历史
  335. // $price = new HousePriceRecord();
  336. // $price->hid = $input['hid'];
  337. // $result['house']['price_record'] = $price->getList([]);
  338. // p( $result['house']['price_record']);
  339. // $peitao = new HouseFacilities();
  340. // $peitao->hid = $input['hid'];
  341. // $pei = $peitao->InfoList();
  342. // if(!empty($pei))
  343. // {
  344. // $peiArr = [];
  345. // foreach ($pei as $key=>$val)
  346. // {
  347. // $peiArr[$val['name']]['name'][] = $val['pname'];
  348. // }
  349. // $result['peitao'] = $peiArr;
  350. // }
  351. }
  352. }
  353. /*
  354. * 建筑类别
  355. * */
  356. public function ArchitectureType($id)
  357. {
  358. if(!empty($id))
  359. {
  360. $model = new CategoryLabel();
  361. $model->id = $id;
  362. $model->type = 2;
  363. $rows = $model->getList([],['name']);
  364. if(!empty($rows))
  365. {
  366. return array_column($rows,'name');
  367. }
  368. }
  369. return [];
  370. }
  371. /*
  372. * 楼盘户型-分组
  373. * */
  374. public function HouseType()
  375. {
  376. $input = Yii::$app->request->get();
  377. $typeModel = new HouseType();
  378. $typeModel->hid =$input['hid'];
  379. $groupType = $typeModel->TypeGroup();
  380. return $groupType;
  381. }
  382. //楼盘户型分组数据
  383. public function HouseTypeGroupAll($input)
  384. {
  385. if(!empty($input['hid']) && !empty($input['type_id']))
  386. {
  387. $typeModel = new HouseType();
  388. $typeModel->hid = $input['hid'];
  389. $typeModel->type_id = $input['type_id'];
  390. $list = $typeModel->QgetList();
  391. if($list != null)
  392. {
  393. foreach ($list as &$val)
  394. {
  395. $val['img'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['housetypes'].$val['img'].Yii::$app->params['pfgwatermark'];
  396. }
  397. }
  398. return $list;
  399. }
  400. }
  401. //获取楼盘相册逻辑
  402. public function HouseAlbum()
  403. {
  404. $input = Yii::$app->request->get();
  405. \common\models\House::find();
  406. $queryAlbum = new HouseAlbum();
  407. $arr = $queryAlbum->AlbumGroup(['hid'=>$input['hid']]);
  408. return $arr;
  409. }
  410. //获取楼盘分类的所有相册信息
  411. public function HouseAlbumAll()
  412. {
  413. $input = Yii::$app->request->post();
  414. if(!empty($input['hid']) && is_numeric($input['hid']))
  415. {
  416. $queryAlbum = new HouseAlbum();
  417. $queryAlbum->hid = $input['hid'];
  418. $queryAlbum->album_id = $input['album_id'];
  419. $rows = $queryAlbum->getList();
  420. if($rows)
  421. {
  422. foreach($rows as &$val)
  423. {
  424. $val['img'] = Yii::$app->params['httpImg']['hosts']. Yii::$app->params['httpImg']['housealbums'].$val['img'].Yii::$app->params['pfgwatermark'];
  425. }
  426. return $rows;
  427. }
  428. }
  429. }
  430. //楼盘资讯
  431. public function HouseNewsList()
  432. {
  433. $input = Yii::$app->request->get();
  434. if(is_numeric($input['hid']))
  435. {
  436. $model = new HouseNews();
  437. $model->hid = $input['hid'];
  438. $result = $model->AllHouseNews();
  439. // foreach ($result as &$val)
  440. // {
  441. // $time_int = strtotime($val['open_time']);
  442. //
  443. // $val['y'] = date('Y',$time_int);
  444. // $val['md'] = date('m-d',$time_int);
  445. // $val['thumb'] = json_decode($val['thumb']);
  446. // }
  447. return $result;
  448. }
  449. }
  450. public function getHouseRemarkList($input,$page){
  451. $houseComment = new HouseComment();
  452. $houseCommentLikes = new HouseCommentLikes();
  453. $houseCommentReply = new HouseCommentreply();
  454. $houseComment->hid = $input['hid'];
  455. $houseCommentList = $houseComment->getHouseList($page);
  456. if($houseCommentList != null)
  457. {
  458. foreach($houseCommentList as &$value){
  459. $value['allremark'] = floor(($value['diduan']+$value['jiaotong']+$value['peitao']+$value['huanjing']+$value["xingjiabi"])/5);
  460. $value['mobile'] = preg_replace("/(\d{3})\d{4}(\d{2})/","\$1******\$3",$value['mobile']);
  461. $houseCommentLikes->hid = $value['hid'];
  462. $houseCommentLikes->hcid = $value['id'];
  463. $value['count_likes'] = $houseCommentLikes->Total();
  464. $value['reply'] = $houseCommentReply->getCommentReply($value['id']);
  465. }
  466. return $houseCommentList;
  467. }
  468. }
  469. }