JsonController.php 14 KB

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