HouseServer.php 31 KB

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