JsonController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <?php
  2. namespace mobile\controllers;
  3. use common\fm\HouseHandle;
  4. use common\models\CategoryCity;
  5. use common\models\CategoryTelCity;
  6. use common\models\Characteristic;
  7. use common\models\House;
  8. use common\models\HousePermit;
  9. use common\models\News;
  10. use common\models\PushHothouse;
  11. use mobile\base\Help;
  12. use mobile\base\BaseController;
  13. use mobile\server\HouseServer;
  14. use mobile\server\IndexServer;
  15. use Yii;
  16. class JsonController extends BaseController
  17. {
  18. /**
  19. * @var bool
  20. */
  21. public $enableCsrfValidation = false;
  22. /**
  23. * 移动首页热销楼盘
  24. * @return mixed
  25. */
  26. public function actionGethousem()
  27. {
  28. // $hothouse = (new PushHothouse())->getHotHouse(2, 4);
  29. $hothouse = (new IndexServer())->getHotHouse(13,6);
  30. if (!empty($hothouse)) {
  31. return Help::JsonCode(Help::SUCCESS, '成功', $hothouse);
  32. }
  33. return Help::JsonCode(Help::ERROR, '暂无数据');
  34. }
  35. /**
  36. * 楼盘列表
  37. * @return mixed
  38. */
  39. public function actionSearchdata()
  40. {
  41. $model = new HouseServer();
  42. $input = Yii::$app->request->get();
  43. $rows = $model->SearchForm($input);
  44. if (!empty($rows['data'])) {
  45. return Help::JsonData(Help::SUCCESS, '成功', $rows['count'], $rows['data']);
  46. }
  47. return Help::JsonCode(Help::ERROR, '暂无相关楼盘数据');
  48. }
  49. /**
  50. * 获取区域子类信息
  51. * @return mixed
  52. */
  53. public function actionSoncity()
  54. {
  55. $CityModel = new CategoryCity();
  56. $r = $CityModel->GetAllSon(Yii::$app->request->post('pid'), ['city_name', 'id', 'pinyin', 'pid'], 2);
  57. return Help::JsonCode(Help::SUCCESS, '成功', $r);
  58. }
  59. /**
  60. * @return mixed
  61. * 获取楼盘ID,返回楼盘预售证书信息
  62. */
  63. public function actionLicence()
  64. {
  65. $input = Yii::$app->request->post();
  66. if (!empty($input['hid'])) {
  67. $model = new HousePermit();
  68. $rows = $model->getList($input);
  69. if ($rows != null) {
  70. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  71. }
  72. }
  73. return Help::JsonCode(Help::ERROR, '失败');
  74. }
  75. /**
  76. * 楼盘所有相册
  77. * @return mixed
  78. */
  79. public function actionAlbumlist()
  80. {
  81. $model = new HouseServer();
  82. $rows = $model->HouseAlbumAll();
  83. if (!empty($rows)) {
  84. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  85. }
  86. return Help::JsonCode(Help::ERROR, '暂无楼盘相册信息');
  87. }
  88. /**
  89. * 楼盘户型分组后的数据
  90. * @return mixed
  91. */
  92. public function actionHousetype()
  93. {
  94. $model = new HouseServer();
  95. $rows = $model->HouseTypeGroupAll(Yii::$app->request->post());
  96. if ($rows != null) {
  97. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  98. }
  99. return Help::JsonCode(Help::ERROR, '暂无楼盘户型图数据');
  100. }
  101. /**
  102. * 首页-底部 拨打电话图标
  103. * @return mixed
  104. */
  105. public function actionTelrand()
  106. {
  107. $input = Yii::$app->request->post();
  108. //没有选择区域的情况下
  109. if (empty($input['city']) || $input['city'] == 0) {
  110. //调取广东的电话
  111. $tel = new CategoryTelCity();
  112. $tel->cid = 68;
  113. $resultTel = $tel->CityTelOne();
  114. if (!empty($resultTel)) {
  115. $telArr = explode(',', $resultTel['tel']);
  116. $index = array_rand($telArr, 1);
  117. if (!empty($telArr[$index])) {
  118. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  119. }
  120. }
  121. }
  122. //有选择区域的情况下
  123. if (!empty($input['city']) && $input['city'] != 0) {
  124. $city = CategoryCity::findOne($input['city']);
  125. $tel = new CategoryTelCity();
  126. $tel->cid = $input['city'];
  127. //选择的是省
  128. if ($city['pid'] == 0) {
  129. $resultTel = $tel->CityTelOne();
  130. if (!empty($resultTel)) {
  131. $telArr = explode(',', $resultTel['tel']);
  132. $index = array_rand($telArr, 1);
  133. if (!empty($telArr[$index])) {
  134. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  135. }
  136. }
  137. }
  138. //选择的是市县
  139. if ($city['pid'] != 0) {
  140. $resultTel = $tel->CityTelOne();
  141. if (!empty($resultTel)) {
  142. $telArr = explode(',', $resultTel['tel']);
  143. $index = array_rand($telArr, 1);
  144. if (!empty($telArr[$index])) {
  145. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  146. }
  147. } else { //如果为空,返回省的电话
  148. $telmodel = new CategoryTelCity();
  149. $telmodel->cid = $city['pid'];
  150. $result = $telmodel->CityTelOne();
  151. if (!empty($result)) {
  152. $telArr = explode(',', $result['tel']);
  153. $index = array_rand($telArr, 1);
  154. if (!empty($telArr[$index])) {
  155. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  156. }
  157. }
  158. }
  159. }
  160. }
  161. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => Yii::$app->params['default_dialtel']]);
  162. }
  163. /**
  164. * 楼盘名称搜索
  165. * @return mixed
  166. */
  167. public function actionSearchname()
  168. {
  169. $model = new HouseServer();
  170. $row = $model->SearchHouseName(Yii::$app->request->get());
  171. if (!empty($row)) {
  172. return Help::JsonCode(Help::SUCCESS, '成功', $row);
  173. }
  174. return Help::JsonCode(Help::ERROR, '暂无搜索数据');
  175. }
  176. /**
  177. * 楼盘首页底部-推荐楼盘 同价位楼盘 周边楼盘
  178. * @return mixed
  179. */
  180. public function actionTall()
  181. {
  182. $model = new House();
  183. $input = Yii::$app->request->post();
  184. if (!empty($input['city'])) {
  185. $model->city = $input['city'];
  186. }
  187. if ($input['price'] == 0) {
  188. $input['price'] = "";
  189. }
  190. $rows = $model->randList(3, $input);
  191. if (count($rows) < 3) { // start 20181019 当同地区同价格楼盘小于3
  192. $cityModel = new CategoryCity();
  193. $parentCity = $cityModel->CityIdentical($input['city']);
  194. $cityId = array_column($parentCity, 'id');
  195. $key = array_search($input['city'], $cityId);
  196. unset($cityId[$key]);
  197. $model->city = $cityId;
  198. $row = $model->randList(2, $input);
  199. $rows = array_merge($rows, $row);
  200. }
  201. if (!empty($rows)) {
  202. foreach ($rows as &$val) {
  203. $val['characteristic'] = HouseHandle::Subject(json_decode($val['characteristic']), 3);
  204. $val['tel'] = HouseHandle::RandTel($val['city']);
  205. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  206. $val['state'] = Yii::$app->params['HouseSalesStatus'][$val['state']];
  207. }
  208. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  209. }
  210. }
  211. /**
  212. * 传入父ID获取子城市
  213. * @return mixed
  214. */
  215. public function actionGetcity()
  216. {
  217. $model = new CategoryCity();
  218. $input = Yii::$app->request->post();
  219. $model->pid = $input['city'];
  220. $rows = $model->getList([], ['id', 'city_name', 'll']); //获取所有子类
  221. $rows = $this->houseCount($rows);
  222. if (!empty($rows)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'get_success'), $rows);
  223. }
  224. /**
  225. * 地图找房
  226. * @param $city
  227. * @return bool
  228. */
  229. private function houseCount($city)
  230. {
  231. if (!is_array($city)) return false;
  232. $rows = [];
  233. $input = [];
  234. $cityId = array_column($city, 'id');
  235. $query = House::find();
  236. $query->select(["count('city') as num", 'city']);
  237. $query->andWhere(['city' => $cityId]);
  238. $query->andWhere(['del' => 1]);
  239. $query->andWhere(['is_view' => 1]);
  240. $query->groupBy('city');
  241. $cityCount = $query->asArray()->all();
  242. if ($cityCount) {
  243. $cityRows = array_column($cityCount, 'num', 'city');
  244. foreach ($city as &$val) {
  245. $val['number'] = isset($cityRows[$val['id']]) ? $cityRows[$val['id']] : 0;
  246. $val['point'] = $val['ll'];
  247. $val['name'] = $val['city_name'];
  248. }
  249. return $city;
  250. }
  251. return false;
  252. }
  253. /**
  254. * 地图找房加载楼盘
  255. * @return mixed
  256. */
  257. public function actionHouselist()
  258. {
  259. $model = new House();
  260. $input = Yii::$app->request->post();
  261. $input['limit'] = 20;
  262. if (isset($input['city']) && !empty($input['city'])) {
  263. $city = (new CategoryCity())->getCityNameTurnId($input);
  264. if ($city) {
  265. $model->city = $city['id'];
  266. }
  267. }
  268. $data = $model->PcHouseList($input, ['pfg_cn_category_city.city_name', 'pfg_cn_category_city.ll', 'pfg_cn_house.id', 'pfg_cn_house.city', 'pfg_cn_house.price', 'pfg_cn_house.name', 'pfg_cn_house_detail.address', 'pfg_cn_house_detail.main_units', 'pfg_cn_house_detail.price_unit', 'pfg_cn_house_detail.longitude_latitude', 'pfg_cn_house.thumb', 'pfg_cn_house.sale_price', 'pfg_cn_house.characteristic']);
  269. if ($data != null) {
  270. $characteristic = new Characteristic();
  271. $charList = $characteristic->getList([]);
  272. $characteristicId = array_column($charList, 'name', 'id');
  273. $chara = array_column($data, 'characteristic', 'id');
  274. $charaArrs = [];
  275. //处理特色主题
  276. foreach ($chara as $key => $val) {
  277. $arr = json_decode($val, true);
  278. if (is_array($arr) && !empty($arr)) {
  279. foreach ($arr as $k => $v) {
  280. if (isset($characteristicId[$v])) {
  281. $charaArrs[$key][$k] = $characteristicId[$v];
  282. }
  283. }
  284. }
  285. }
  286. $Tel = new CategoryTelCity();
  287. $telRow = $Tel->QgetAll();
  288. $cityTel = [];
  289. foreach ($telRow as &$v) {
  290. $cityTel[$v['cid']] = explode(',', $v['tel']);
  291. }
  292. $randArr = [];
  293. foreach ($data as &$val) {
  294. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'];
  295. if (isset($charaArrs[$val['id']])) {
  296. //随机选择3个特色主题
  297. if (count($charaArrs[$val['id']]) > 3) {
  298. $ranChar = array_rand($charaArrs[$val['id']], 3);
  299. $randArr[] = $charaArrs[$val['id']][$ranChar[0]];
  300. $randArr[] = $charaArrs[$val['id']][$ranChar[1]];
  301. $randArr[] = $charaArrs[$val['id']][$ranChar[2]];
  302. $val['characteristic'] = $randArr;
  303. $randArr = [];
  304. } else {
  305. $val['characteristic'] = $charaArrs[$val['id']];
  306. }
  307. }
  308. if (isset($cityTel[$val['city']])) {
  309. $rand = array_rand($cityTel[$val['city']], 1);
  310. $val['citytel'] = $cityTel[$val['city']][$rand];
  311. } else {
  312. $val['citytel'] = Yii::$app->params['default_dialtel'];
  313. }
  314. }
  315. $rows = ['data' => $data];
  316. }
  317. if (!empty($rows)) {
  318. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  319. }
  320. return Help::JsonCode(Help::ERROR, '暂无数据');
  321. }
  322. /**
  323. * 地图找房楼盘详情
  324. * @return mixed
  325. */
  326. public function actionDetails()
  327. {
  328. $model = new HouseServer();
  329. $row = $model->Details();
  330. $arr = [];
  331. if (!empty($row)) {
  332. $arr['id'] = $row['house']['id'];
  333. $arr['name'] = $row['house']['name'];
  334. $arr['state'] = $row['house']['state'];
  335. $arr['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $row['house']['thumb'] . '/pfgwatermark';
  336. $arr['sale_price'] = $row['house']['sale_price'];
  337. $arr['price_unit'] = $row['house']['price_unit'];
  338. $arr['main_units'] = $row['house']['main_units'];
  339. $arr['city_name'] = $row['house']['city_name'];
  340. $arr['characteristic'] = $row['characteristic'];
  341. return Help::JsonCode(Help::SUCCESS, '成功', $arr);
  342. }
  343. return Help::JsonCode(Help::ERROR, '暂无相关楼盘数据');
  344. }
  345. /**
  346. * 资讯列表
  347. * @return mixed
  348. */
  349. public function actionHomeform()
  350. {
  351. $model = new News();
  352. if (is_numeric(Yii::$app->request->get('cid'))) {
  353. $model->category = Yii::$app->request->get('cid');
  354. if ($model->category == 0) $model->category = null;
  355. }
  356. $newsList = $model->Mhomelist(Yii::$app->request->get());
  357. if (!empty($newsList)) {
  358. foreach ($newsList as &$val) {
  359. if (!empty($val['thumb'])) {
  360. $val['thumb'] = json_decode($val['thumb']);
  361. }
  362. }
  363. $arr['url'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['newsthumb'];
  364. $arr['data'] = $newsList;
  365. return Help::JsonCode(Help::SUCCESS, '成功', $arr);
  366. }
  367. return Help::JsonCode(Help::ERROR, '失败');
  368. }
  369. }