HouseServer.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/20
  6. * Time: 下午3:21
  7. */
  8. namespace frontend\server;
  9. use common\fm\HouseHandle;
  10. use common\fm\Opencc;
  11. use common\models\CategoryCity;
  12. use common\models\House;
  13. use common\models\News;
  14. use common\models\HouseNumber;
  15. use common\models\Search;
  16. use common\models\Video;
  17. use Yii;
  18. use common\models\HouseAlbum;
  19. use common\models\Characteristic;
  20. use common\models\HouseType;
  21. use common\models\HouseFacilities;
  22. use common\models\HouseNews;
  23. use common\models\CategoryLabel;
  24. use common\models\PushHousesale;
  25. use common\models\HousePermit;
  26. use common\models\HousePriceRecord;
  27. use common\models\HouseComment;
  28. use common\models\HouseCommentLikes;
  29. use common\models\HouseCommentreply;
  30. class HouseServer
  31. {
  32. /*
  33. * 搜索楼盘名字
  34. * */
  35. public function SearchHouseName($input)
  36. {
  37. if (!empty($input['title'])) {
  38. (new Search())->SaveSearchPC($input['title']);
  39. $query = new House();
  40. $arr = (new \common\api\HouseServer())->HouseNameConvert($input['title']);
  41. if (!empty($arr['pinyin'])) {
  42. $query->pinyin = $arr['pinyin'];
  43. }
  44. if (!empty($arr['zhongwen'])) {
  45. $query->name = $arr['zhongwen'];
  46. }
  47. $result = $query->HouseName();
  48. return $result;
  49. }
  50. }
  51. public function Search($input)
  52. {
  53. $query = new House();
  54. //搜索条件
  55. if (!empty($input['zhuti']) && $input['zhuti'] != 0) {
  56. $query->characteristic = $input['zhuti'];
  57. }
  58. if (!empty($input['characteristic']) && $input['characteristic'] != 0) {
  59. $query->characteristic = $input['characteristic'];
  60. }
  61. if (!empty($input['price']) && $input['price'] != 0) {
  62. $query->price = $input['price'];
  63. }
  64. if (!empty($input['type']) && $input['type'] != 0) {
  65. $query->type = $input['type'];
  66. }
  67. // if(!empty($input['pricesort']) && $input['pricesort'] != 0)
  68. // {
  69. // $query->pricesort = $input['pricesort'];
  70. // }
  71. if (!empty($input['pinyin'])) {
  72. $query->pinyin = $input['pinyin'];
  73. } else {
  74. if (!empty($input['name'])) {
  75. $query->name = $input['name'];
  76. }
  77. }
  78. //VR看房
  79. if (!empty($input['vrread']) && $input['vrread'] != 0) {
  80. $idList = array_column((new \common\models\Vr())->getColumnHid(), 'hid');
  81. $query->id = $idList;
  82. }
  83. if (!empty($input['city']) && $input['city'] != 0) {
  84. $query->city = $input['city'];
  85. }
  86. //处理价格区间
  87. if (!empty($query->price)) {
  88. $price = \common\models\HousesPrice::find();
  89. $priceModel = $price->andWhere(['id' => $query->price])->one();
  90. if ($priceModel != null) {
  91. $query->price = $priceModel->price;
  92. }
  93. }
  94. //户型
  95. if (!empty($query->type)) {
  96. $type = new \common\models\HouseType();
  97. $type->type_id = $query->type;
  98. $typeModel = $type->getList(['hid']);
  99. if (!empty($typeModel)) {
  100. $query->id = array_unique(array_column($typeModel, 'hid'));
  101. } else {
  102. $query->id = 0; //处理 ID没有的情况下,不查询该条件
  103. }
  104. }
  105. // if (!empty($input['name'])) {
  106. // $arr = (new \common\api\HouseServer())->HouseNameConvert($input['name']);
  107. // if (!empty($arr['pinyin'])) {
  108. // $query->pinyin = $arr['pinyin'];
  109. // }
  110. // if (!empty($arr['zhongwen'])) {
  111. // $query->name = $arr['zhongwen'];
  112. // }
  113. // $query->city = '';
  114. // }
  115. $data = $query->QgetList(['pfg_house_detail.video_url', 'pfg_house_detail.preferential', 'pfg_house_detail.panorama', 'pfg_house.is_tel', 'pfg_house.area', 'pfg_category_city.city_name', '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.thumb', 'pfg_house.sale_price', 'pfg_house.characteristic', 'pfg_house_detail.longitude_latitude'], $input);
  116. if ($data['data'] != null) {
  117. foreach ($data['data'] as &$val) {
  118. $val['characteristic'] = \common\fm\HouseHandle::ChangeCharacteristic($val['characteristic']);
  119. $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  120. if (empty($val['is_tel'])) {
  121. if (!empty($val['area']) && \common\fm\HouseHandle::ChangeCityTel($val['area']) != Yii::$app->params['default_dialtel']) {
  122. $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['area']);
  123. } else {
  124. $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  125. }
  126. } else {
  127. $val['citytel'] = $val['is_tel'];
  128. }
  129. //查询是否单独设置楼盘号码
  130. if (!empty(HouseNumber::SearchNumber($val['id']))) {
  131. $val['citytel'] = HouseNumber::SearchNumber($val['id']);
  132. }
  133. // if(empty($val['is_tel']))
  134. // {
  135. // $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  136. //
  137. // }
  138. // else
  139. // {
  140. // $val['citytel'] = $val['is_tel'];
  141. // }
  142. // $val['video'] = $this->Video($val['id']);
  143. }
  144. return $data;
  145. }
  146. }
  147. public function Details()
  148. {
  149. $input = Yii::$app->request->get();
  150. $arr = [];
  151. $seo = [];
  152. $seo['province'] = '海南省';
  153. $model = new House();
  154. $model->id = $input['hid'];
  155. $select = ['pfg_house.*', 'pfg_house_detail.*', 'pfg_category_city.city_name', 'pfg_category_city.pid as city_pid'];
  156. $arr['house'] = $model->Qdetails($select);
  157. if (empty($arr['house'])) return false;
  158. //楼盘点击量
  159. $click = new \common\api\HouseServer();
  160. $click->HouseClick($input['hid']);
  161. if (!empty($arr['house'])) {
  162. $seo['city'] = $arr['house']['city_name'];
  163. if (!empty($arr['house']['city_pid'])) {
  164. $cityModel = new CategoryCity();
  165. $city = $cityModel->FindById($arr['house']['city_pid']);
  166. $seo['province'] = $city['city_name'];
  167. }
  168. $arr['seo'] = $seo;
  169. $arr['characteristic'] = $this->Subject(json_decode($arr['house']['characteristic']), 3);
  170. $queryAlbum = new HouseAlbum();
  171. $arr['album'] = $queryAlbum->AlbumGroup(['hid' => $input['hid']]);
  172. $arr['album_find'] = $queryAlbum->Groupfind(['hid' => $input['hid']]);
  173. //直播视频
  174. $arr['house']['live'] = (new \common\models\Live())->GetOneLiveByHouse($input['hid']);
  175. $perModel = new HousePermit();
  176. $perModel->hid = $input['hid'];
  177. $arr['permit'] = $perModel->FindNewest();
  178. //户型图
  179. $queryType = new HouseType();
  180. $queryType->hid = $input['hid'];
  181. $arr['type'] = $queryType->RandList(['area', 'indoor_info', 'title', 'type_id', 'img','hid'], 4);
  182. //户型分类
  183. $arr['type_grouy'] = $queryType->TypeGroup();
  184. if (empty($arr['house']['is_tel'])) {
  185. //新增三级联动区域的电话获取修改
  186. if (!empty($arr['house']['area']) && $this->RandTel($arr['house']['area']) != Yii::$app->params['default_dialtel']) {
  187. $arr['house']['tel'] = $this->RandTel($arr['house']['area']);
  188. } else {
  189. $arr['house']['tel'] = $this->RandTel($arr['house']['city']);
  190. }
  191. } else {
  192. $arr['house']['tel'] = $arr['house']['is_tel'];
  193. }
  194. $arr['house']['state'] = Yii::$app->params['HouseSalesStatus'][$arr['house']['state']];
  195. $arr['news'] = (new News())->getHouseNews($arr['house']['name'], 2);
  196. //建筑类别
  197. $architecture_type = new CategoryLabel();
  198. $architecture_type->type = 2;
  199. $arr['architecture_type'] = array_column($architecture_type->getList([], ['id', 'name']), 'name', 'id');
  200. $arr['house']['architecture_type'] = json_decode($arr['house']['architecture_type'], true);
  201. $vr3d = $this->Vr3d($arr['house']['id']);
  202. $vrcount = \common\models\Vr::find()->where(['hid' => $arr['house']['id'], 'state' => 1, 'type' => 1])->count();
  203. if(!empty($arr['house']['panorama'])){
  204. $vrcount += 1;
  205. }
  206. if($vrcount > 0){
  207. array_unshift($arr['type_grouy'], ['huxing_name' => 'VR看房', 'num' => $vrcount, 'hid' => $arr['house']['id'], 'type_id' => 'vr']);
  208. }
  209. if (!empty($vr3d)) {
  210. $arr['house']['panorama'] = $vr3d['path'];
  211. $arr['house']['panorama_img'] = $vr3d['img'];
  212. } else {
  213. if ($arr['house']['panorama_img']) {
  214. $arr['house']['panorama_img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['house_video'] . $arr['house']['panorama_img'] . '/same';
  215. } else {
  216. $arr['house']['panorama_img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $arr['house']['thumb'] . '/same';
  217. }
  218. }
  219. if (!empty($arr['house']['video_url'])) {
  220. if (!empty($arr['house']['video_img'])) {
  221. $arr['house']['video_img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['house_video'] . $arr['house']['video_img'] . '/same';
  222. } else {
  223. $arr['house']['video_img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $arr['house']['thumb'] . '/same';
  224. }
  225. }
  226. } else {
  227. return false;
  228. }
  229. return $arr;
  230. }
  231. public function Vr3d($hid)
  232. {
  233. $data = \common\models\Vr::find()->where(['hid' => $hid, 'state' => 1, 'type' => 1])->select(['img', 'name', 'path'])->orderBy(['sort' => SORT_DESC])->asArray()->one();
  234. if (!empty($data)) {
  235. $data['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['video'] . $data['img'];
  236. }
  237. return $data;
  238. }
  239. public function NewsDynamic($input)
  240. {
  241. $model = new HouseNews();
  242. $model->hid = $input['hid'];
  243. $houseNewsInfo = $model->getHidList();
  244. $nids = array_column($houseNewsInfo, 'nid');
  245. $newsModel = new News();
  246. $newsModel->hid = $input['hid'];
  247. $result = $newsModel->getNewsListHouse($nids, 2);
  248. if ($result != null) {
  249. return $result;
  250. }
  251. }
  252. public function GetInput($input)
  253. {
  254. $Arr = [];
  255. $Arr['title'] = $input['name'];
  256. $Arr['ip'] = Yii::$app->request->userIP;
  257. return $Arr;
  258. }
  259. //Video楼盘视频
  260. public function Video($Id)
  261. {
  262. $data = Video::find()->select(['video_url', 'thumb'])
  263. ->andWhere(['del' => 1])->andWhere(['state' => 1])->andWhere(['hid' => $Id])
  264. ->orderBy(['create_at' => SORT_DESC])->asArray()->one();
  265. return $data;
  266. }
  267. /****Live楼盘直播视频****/
  268. public function GetLiveInfo($hid)
  269. {
  270. $data = \common\models\Live::find()
  271. ->select('id,hid,video_url,img')
  272. ->andWhere(['hid' => $hid])
  273. ->asArray()->one();
  274. return $data;
  275. }
  276. //楼盘详情页数据
  277. public function ParamsDetails()
  278. {
  279. $input = Yii::$app->request->get();
  280. if (is_numeric($input['hid'])) {
  281. $result = [];
  282. $model = new House();
  283. $model->id = $input['hid'];
  284. $result['house'] = $model->HousesAll();
  285. $result['house']['characteristic'] = \common\fm\HouseHandle::ChangeCharacteristic($result['house']['characteristic']);
  286. // $this->Subject(json_decode($result['house']['characteristic']),4);
  287. if (empty($result['house']['is_tel'])) {
  288. if (!empty($result['house']['area']) && HouseHandle::ChangeCityTel($result['house']['area']) != Yii::$app->params['default_dialtel']) {
  289. $result['house']['tel'] = \common\fm\HouseHandle::ChangeCityTel($result['house']['area']);
  290. } else {
  291. $result['house']['tel'] = \common\fm\HouseHandle::ChangeCityTel($result['house']['city']);
  292. }
  293. } else {
  294. $result['house']['tel'] = $result['house']['is_tel'];
  295. }
  296. //查询是否单独设置楼盘号码
  297. if (!empty(HouseNumber::SearchNumber($result['house']['id']))) {
  298. $result['house']['tel'] = HouseNumber::SearchNumber($result['house']['id']);
  299. }
  300. $result['house']['architecture_type'] = $this->ArchitectureType(json_decode($result['house']['architecture_type']), 2);
  301. //预售证号
  302. $zheng = new HousePermit();
  303. $result['house']['zhengshu'] = $zheng->getList($input);
  304. //价格历史
  305. $price = new HousePriceRecord();
  306. $price->hid = $input['hid'];
  307. $result['house']['price_record'] = $price->getList([]);
  308. $peitao = new HouseFacilities();
  309. $peitao->hid = $input['hid'];
  310. $pei = $peitao->InfoList();
  311. if (!empty($pei)) {
  312. $peiArr = [];
  313. foreach ($pei as $key => $val) {
  314. $peiArr[$val['name']]['name'][] = $val['pname'];
  315. }
  316. $result['peitao'] = $peiArr;
  317. }
  318. return $result;
  319. }
  320. }
  321. //获取楼盘相册逻辑
  322. public function Album()
  323. {
  324. $input = Yii::$app->request->get();
  325. $queryAlbum = new HouseAlbum();
  326. $arr['album'] = $queryAlbum->AlbumGroup(['hid' => $input['hid']]);
  327. foreach ($arr['album'] as $key => $val) {
  328. $arr['data'][$val['album_id']] = $queryAlbum::find()->andWhere(['album_id' => $val['album_id']])->andWhere(['hid' => $input['hid']])->andWhere(['del' => 1])->orderBy(['sort' => SORT_DESC, 'id' => SORT_DESC])->limit(3)->asArray()->all();
  329. $arr['album_id'][$val['album_id']] = $val['name'];
  330. }
  331. return $arr;
  332. }
  333. //获取楼盘相册信息
  334. public function AlbumType()
  335. {
  336. $input = Yii::$app->request->get();
  337. $queryAlbum = new HouseAlbum();
  338. $arr['album'] = $queryAlbum->AlbumGroup(['hid' => $input['hid']]);
  339. $queryAlbum->hid = $input['hid'];
  340. $queryAlbum->album_id = Yii::$app->request->get('album_id', $arr['album'][0]['album_id']);
  341. $arr['data'] = $queryAlbum->getList();
  342. if (!empty($arr['data'])) {
  343. foreach ($arr['data'] as &$val) {
  344. $val['img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['housealbums'] . $val['img'] . Yii::$app->params['pfgwatermark'];
  345. }
  346. }
  347. $arr['selectalbumtype'] = Yii::$app->request->get('album_id', $arr['album'][0]['album_id']);
  348. return $arr;
  349. }
  350. //获取楼盘分类的所有相册信息
  351. public function AlbumAll()
  352. {
  353. $input = Yii::$app->request->post();
  354. $queryAlbum = new HouseAlbum();
  355. $queryAlbum->hid = $input['hid'];
  356. $queryAlbum->album_id = $input['album_id'];
  357. $rows = $queryAlbum->getList();
  358. if ($rows != null) {
  359. foreach ($rows as &$val) {
  360. $val['img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['housealbums'] . $val['img'] . Yii::$app->params['pfgwatermark'];
  361. }
  362. return $rows;
  363. }
  364. }
  365. /*相册获取*/
  366. public function GetAlbumAll($input)
  367. {
  368. $queryAlbum = new HouseAlbum();
  369. $queryAlbum->hid = $input['hid'];
  370. $queryAlbum->album_id = $input['album_id'];
  371. $rows = $queryAlbum->getList();
  372. if ($rows != null) {
  373. foreach ($rows as &$val) {
  374. $val['img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['housealbums'] . $val['img'] . Yii::$app->params['pfgwatermark'];
  375. }
  376. return $rows;
  377. }
  378. }
  379. //楼盘户型分组
  380. public function Type()
  381. {
  382. $input = Yii::$app->request->get();
  383. $typeModel = new HouseType();
  384. $typeModel->hid = $input['hid'];
  385. $groupType = $typeModel->TypeGroup();
  386. $vrcount = \common\models\Vr::find()->where(['hid' => $input['hid'], 'state' => 1, 'type' => 1])->count();
  387. $houseModel = new House();
  388. $houseModel->id = $input['hid'];
  389. $house720 = $houseModel->HousesAll();
  390. if(!empty($house720['panorama'])){
  391. $vrcount+=1;
  392. }
  393. if($vrcount > 0 || !empty($house720['panorama'])){
  394. array_unshift($groupType, ['huxing_name' => 'VR看房', 'num' => $vrcount, 'hid' => $input['hid'], 'type_id' => 'vr']);
  395. }
  396. return $groupType;
  397. }
  398. /**
  399. * 楼盘户型数据
  400. * @param $input
  401. * @param bool $tr
  402. * @return mixed
  403. */
  404. public function TypeAll($input, $tr = true)
  405. {
  406. if ($input['type_id'] == 'vr') {
  407. $input['type_id'] = '';
  408. $list = (new \common\models\Vr())->getListAndVr($input);
  409. $houseModel = new House();
  410. $houseModel->id = $input['hid'];
  411. $house720 = $houseModel->HousesAll();
  412. if(!empty($house720['panorama'])){
  413. array_unshift($list, ['title' => '720VR全景看房', 'area' => '全景','indoor_info'=>'全景', 'hid' => $input['hid'], 'type_id' => 'vr','panorama'=>$house720['panorama'],'panorama_img'=>$house720['panorama_img'],'thumb'=>$house720['thumb']]);
  414. }
  415. }elseif($input['type_id'] == 'all'){
  416. $typeModel = new HouseType();
  417. $typeModel->hid = $input['hid'];
  418. // $typeModel->type_id = $input['type_id'];
  419. if ($tr == true) {
  420. $list = $typeModel->QgetList(4);
  421. } else {
  422. $list = $typeModel->getList();
  423. }
  424. $input['type_id'] = '';
  425. $list_vr = (new \common\models\Vr())->getListAndVr($input);
  426. $houseModel = new House();
  427. $houseModel->id = $input['hid'];
  428. $house720 = $houseModel->HousesAll();
  429. if(!empty($house720['panorama'])){
  430. array_unshift($list_vr, ['title' => '720VR全景看房', 'area' => '全景','indoor_info'=>'全景', 'hid' => $input['hid'], 'type_id' => 'vr','panorama'=>$house720['panorama'],'panorama_img'=>$house720['panorama_img'],'thumb'=>$house720['thumb']]);
  431. }
  432. $list = array_merge($list_vr,$list);
  433. }else{
  434. $typeModel = new HouseType();
  435. $typeModel->hid = $input['hid'];
  436. $typeModel->type_id = $input['type_id'];
  437. if ($tr == true) {
  438. $list = $typeModel->QgetList(4);
  439. } else {
  440. $list = $typeModel->getList();
  441. }
  442. }
  443. if ($list != null) {
  444. foreach ($list as &$val) {
  445. $val['title'] = Opencc::Convert($val['title']);
  446. $val['area'] = Opencc::Convert($val['area']);
  447. $val['indoor_info'] = Opencc::Convert($val['indoor_info']);
  448. if (!empty($val['path'])) {
  449. $val['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['video'] . $val['img'];
  450. $val['type_id'] = 'vr';
  451. } elseif(!empty($val['panorama'])){
  452. if ($val['panorama_img']) {
  453. $val['img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['house_video'] . $val['panorama_img'] . '/same';
  454. } else {
  455. $val['img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  456. }
  457. }else {
  458. $val['img'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['housetypes'] . $val['img'] . '/same';
  459. }
  460. }
  461. }
  462. return $list;
  463. }
  464. //楼盘公共信息
  465. public function PublicDetails()
  466. {
  467. $input = Yii::$app->request->get();
  468. $houseModel = new House();
  469. $houseModel->id = $input['hid'];
  470. $houseRow = $houseModel->OneDetails(['id', 'name', 'state', 'city', 'characteristic', 'thumb', 'is_tel']);
  471. if ($houseRow != null) {
  472. // $houseRow['city'] = '';
  473. if (!empty($houseRow['city'])) {
  474. $cityModel = new \common\models\CategoryCity();
  475. $houseRow['seo'] = $cityModel->FatherSon($houseRow['city']);
  476. if (empty($houseRow['seo']['city'])) {
  477. $houseRow['seo']['city'] = '';
  478. }
  479. }
  480. //猜你喜欢
  481. $houseModel->id = '';
  482. $houseModel->city = $houseRow['city'];
  483. $houseRow['randhouse'] = $houseModel->randList(4);
  484. $houseRow['state'] = Yii::$app->params['HouseSalesStatus'][$houseRow['state']];
  485. $houseRow['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $houseRow['thumb'];
  486. //特色主题
  487. $subject = \common\fm\HouseHandle::ChangeCharacteristic($houseRow['characteristic']);
  488. // $this->Subject(json_decode($houseRow['characteristic'],true));
  489. $houseRow['characteristic'] = $subject;
  490. //随机电话
  491. if (empty($houseRow['is_tel'])) {
  492. $houseRow['tel'] = $this->RandTel($houseRow['city']);
  493. } else {
  494. $houseRow['tel'] = $houseRow['is_tel'];
  495. }
  496. return $houseRow;
  497. }
  498. }
  499. //楼盘随机电话
  500. public function RandTel($city)
  501. {
  502. if (!empty($city)) {
  503. $tel = new \common\models\CategoryTelCity();
  504. $tel->cid = $city;
  505. $telModel = $tel->CityTelOne();
  506. if (!empty($telModel['tel'])) {
  507. $telArr = explode(',', $telModel['tel']);
  508. $randNum = array_rand($telArr, 1);
  509. return $telArr[$randNum];
  510. }
  511. }
  512. return Yii::$app->params['default_dialtel'];
  513. // $tel = new \common\models\CategoryTelCity();
  514. // $tel->cid = $city;
  515. // $telModel = $tel->CityTelOne();
  516. // if(!empty($telModel['tel']))
  517. // {
  518. // $telArr = explode(',',$telModel['tel']);
  519. // $randNum = array_rand($telArr,1);
  520. // return $telArr[$randNum];
  521. // }
  522. // return Yii::$app->params['default_dialtel'];
  523. }
  524. //特色主题 超过3个随机返回3个元素
  525. public function Subject($id, $num = 3)
  526. {
  527. if (empty($id) || !is_array($id)) return [];
  528. $char = new Characteristic();
  529. $char->id = $id;
  530. // if(is_array($id) && !empty($id))
  531. // {
  532. // $char->id = $id;
  533. // }
  534. $charMode = array_column($char->getList([], ['id', 'name']), 'name', 'id');
  535. if ($charMode != null) {
  536. $count = count($charMode);
  537. $arr = [];
  538. if ($count >= $num) {
  539. $rand = array_rand($charMode, $num);
  540. foreach ($rand as $key => $val) {
  541. $arr[$key] = $charMode[$val];
  542. }
  543. } else {
  544. $arr = $charMode;
  545. }
  546. return $arr;
  547. }
  548. }
  549. public function ArchitectureType($id, $type = null)
  550. {
  551. if (!empty($id)) {
  552. $model = new CategoryLabel();
  553. $model->id = $id;
  554. $model->type = $type;
  555. $rows = $model->getList([], ['name']);
  556. if (!empty($rows)) {
  557. return array_column($rows, 'name');
  558. }
  559. }
  560. return [];
  561. }
  562. //楼盘资讯
  563. public function HouseNewsList()
  564. {
  565. $input = Yii::$app->request->get();
  566. if (is_numeric($input['hid'])) {
  567. $model = new HouseNews();
  568. $model->hid = $input['hid'];
  569. $houseNewsInfo = $model->getHidList();
  570. $nids = array_column($houseNewsInfo, 'nid');
  571. $newsModel = new News();
  572. $newsModel->hid = $input['hid'];
  573. $result = $newsModel->getNewsListHouse($nids);
  574. foreach ($result as &$val) {
  575. $time_int = strtotime($val['open_time']);
  576. $val['d'] = date('d', $time_int);
  577. $val['ym'] = date('Y-m', $time_int);
  578. $val['thumb'] = json_decode($val['thumb'], true);
  579. }
  580. return $result;
  581. }
  582. }
  583. /*
  584. * 递归区域
  585. * */
  586. public function RecursionCity()
  587. {
  588. }
  589. public function distinguishHouse($input)
  590. {
  591. switch ($input['type']) {
  592. case 'tuijian':
  593. $model = new PushHousesale();
  594. $model->type = 3;
  595. $result = $model->Homegetlist(4);
  596. break;
  597. case 'price':
  598. $model = new House();
  599. $model->is_push = 2;
  600. $model->sale_price = $input['content'];
  601. $a['sale_price'] = $input['content'];
  602. $a['page'] = $input['id'];
  603. $a['limit'] = 4;
  604. $result = $model->HomegetList(4, $a);
  605. if (empty($result)) {
  606. $_model = clone $model;
  607. $model->is_push = 1;
  608. $result = $model->HomegetList(4, $a);
  609. }
  610. break;
  611. case 'quyu':
  612. $model = new House();
  613. $model->is_push = 2;
  614. $model->city = $input['content'];
  615. $a['page'] = $input['id'];
  616. $a['limit'] = 4;
  617. $result = $model->HomegetList(4, $a);
  618. if (empty($result)) {
  619. $_model = clone $model;
  620. $model->is_push = 1;
  621. $result = $model->HomegetList(4, $a);
  622. }
  623. break;
  624. }
  625. if (!empty($result)) {
  626. foreach ($result as &$val) {
  627. $val['price_zj'] = HouseHandle::priceUnit($val['price_unit']);
  628. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'];
  629. }
  630. return $result;
  631. }
  632. }
  633. /*
  634. * 地图搜索,后期优化搜索代码
  635. * */
  636. public function MapSearch($input)
  637. {
  638. $query = new House();
  639. //搜索条件
  640. if (!empty($input)) {
  641. foreach ($input as $a => $b) {
  642. if ($a == 'zhuti') {
  643. $a = 'characteristic';
  644. }
  645. if (isset($query->$a)) {
  646. $query->$a = $b;
  647. }
  648. }
  649. }
  650. //处理价格区间
  651. if (!empty($query->price)) {
  652. $price = \common\models\HousesPrice::find();
  653. $priceModel = $price->andWhere(['id' => $query->price])->one();
  654. if ($priceModel != null) {
  655. $query->price = $priceModel->price;
  656. }
  657. }
  658. //户型
  659. if (!empty($query->type)) {
  660. $type = \common\models\HouseType::find();
  661. $typeModel = $type->andWhere(['type_id' => $query->type, 'del' => 1])->asArray()->all();
  662. $query->id = array_unique(array_column($typeModel, 'hid'));
  663. }
  664. $data = $query->MapSearch(['pfg_category_city.city_name', '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.thumb', 'pfg_house.sale_price', 'pfg_house.characteristic', 'pfg_house_detail.longitude_latitude']);
  665. if ($data != null) {
  666. // $characteristic = new \common\models\Characteristic();
  667. // $charList = $characteristic->getList([]);
  668. // $characteristicId = array_column($charList,'name','id');
  669. // $chara = array_column($data,'characteristic','id');
  670. // $charaArrs = [];
  671. // //处理特色主题
  672. // foreach ($chara as $key=>$val)
  673. // {
  674. // $arr = json_decode($val,true);
  675. // if(is_array($arr) && !empty($arr))
  676. // {
  677. // foreach ($arr as $k=>$v)
  678. // {
  679. // if(isset($characteristicId[$v]))
  680. // {
  681. // $charaArrs[$key][$k] = $characteristicId[$v];
  682. // }
  683. // }
  684. // }
  685. // }
  686. //
  687. // $Tel = new \common\models\CategoryTelCity();
  688. // $telRow = $Tel->QgetAll();
  689. //
  690. // $cityTel = [];
  691. // foreach ($telRow as &$v)
  692. // {
  693. // $cityTel[$v['cid']] = explode(',',$v['tel']);
  694. // }
  695. //
  696. // $randArr = [];
  697. foreach ($data as &$val) {
  698. $val['characteristic'] = \common\fm\HouseHandle::ChangeCharacteristic($val['characteristic']);
  699. // if(isset($charaArrs[$val['id']]))
  700. // {
  701. // //随机选择3个特色主题
  702. // if(count($charaArrs[$val['id']]) > 3)
  703. // {
  704. // $ranChar = array_rand($charaArrs[$val['id']],3);
  705. // $randArr[] = $charaArrs[$val['id']][$ranChar[0]];
  706. // $randArr[] = $charaArrs[$val['id']][$ranChar[1]];
  707. // $randArr[] = $charaArrs[$val['id']][$ranChar[2]];
  708. // $val['characteristic'] = $randArr;
  709. // $randArr= [];
  710. // }
  711. // else
  712. // {
  713. // $val['characteristic'] = $charaArrs[$val['id']];
  714. // }
  715. //
  716. // }
  717. if (!empty($cityTel[$val['city']][0])) {
  718. $val['citytel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
  719. // $rand = array_rand($cityTel[$val['city']],1);
  720. // $val['citytel'] =$cityTel[$val['city']][$rand];
  721. } else {
  722. $val['citytel'] = Yii::$app->params['default_dialtel'];
  723. }
  724. }
  725. return $data;
  726. }
  727. }
  728. public function getHouseRemarkList($input, $page)
  729. {
  730. $houseComment = new HouseComment();
  731. $houseCommentLikes = new HouseCommentLikes();
  732. $houseCommentReply = new HouseCommentreply();
  733. $houseComment->hid = $input['hid'];
  734. $houseCommentList = $houseComment->getHouseList($page);
  735. if ($houseCommentList != null) {
  736. foreach ($houseCommentList as &$value) {
  737. $value['allremark'] = floor(($value['diduan'] + $value['jiaotong'] + $value['peitao'] + $value['huanjing'] + $value["xingjiabi"]) / 5);
  738. $value['mobile'] = preg_replace("/(\d{3})\d{4}(\d{2})/", "\$1******\$3", $value['mobile']);
  739. $houseCommentLikes->hid = $value['hid'];
  740. $houseCommentLikes->hcid = $value['id'];
  741. $value['count_likes'] = $houseCommentLikes->Total();
  742. $value['reply'] = $houseCommentReply->getCommentReply($value['id']);
  743. }
  744. return $houseCommentList;
  745. }
  746. }
  747. public function getHouseListByCity($city, $limit = null)
  748. {
  749. $cityList = (new CategoryCity())->getTongSonList($city);
  750. $model = new House();
  751. $model->city = $cityList;
  752. $data = $model->getCityHouseList(6);
  753. foreach ($data as &$val) {
  754. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  755. $val['tel'] = $this->RandTel($val['city']);
  756. $news = (new News())->getHouseNewByHid($val['id'], 1);
  757. if (!empty($news)) {
  758. $val['news_name'] = $news[0]['subject'];
  759. $val['news_id'] = $news[0]['id'];
  760. }
  761. }
  762. return $data;
  763. }
  764. }