IndexController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/19
  6. * Time: 下午2:52
  7. */
  8. namespace mobile\controllers;
  9. use common\models\CategoryCity;
  10. use common\models\CategoryTelCity;
  11. use common\models\PushmCity;
  12. use common\models\PushmColumn;
  13. use mobile\base\CommonController;
  14. use mobile\server\IndexServer;
  15. use Yii;
  16. use mobile\base\Help;
  17. class IndexController extends CommonController
  18. {
  19. public $enableCsrfValidation = false;
  20. public function actionIndex()
  21. {
  22. // //区域
  23. // $cityM = new \mobile\server\CityServer();
  24. // $Abroad_a = $cityM->CityAbroad_a();
  25. // $Abroad_b = $cityM->CityAbroad_b();
  26. // $city_a = getTree($Abroad_a,0);
  27. // $city_b = getTree($Abroad_b,0);
  28. $model = new IndexServer();
  29. $lunbo = $model->Lunbo();
  30. $tuijian = $model->tuijian(); //易购头条
  31. $news = $model->newslist();
  32. $newsc = $model->NewsColumn();
  33. //分站后 区域id
  34. $gCity = Yii::$app->request->get('city');
  35. if (empty($gCity)) {
  36. $gCity = Yii::$app->hostserver->hostId;
  37. }
  38. //精选楼盘
  39. $hot = $model->Hothouse(['city' => !empty($gCity) ? $gCity : 0, 'type' => 4, 'rand' => null]);
  40. if (!empty($hot)) {
  41. foreach ($hot as &$val) {
  42. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . Yii::$app->params['pfgwatermark'];
  43. }
  44. }
  45. //品牌商
  46. $PushmColumn = new PushmColumn();
  47. $PushmColumn->type = 1;
  48. $pinpai = $PushmColumn->getList(['page' => 1, 'limit' => 5])['data'];
  49. if ($pinpai) {
  50. $m = new \common\models\PushmHouse();
  51. $m->developers_id = array_column($pinpai, 'did');
  52. $result = $m->getListGroup();
  53. if ($result) {
  54. $resultArr = array_column($result, 'total', 'developers_id');
  55. }
  56. foreach ($pinpai as &$val) {
  57. $val['house_count'] = 0;
  58. if (isset($resultArr[$val['did']])) {
  59. $val['house_count'] = $resultArr[$val['did']];
  60. }
  61. $val['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['push_lb'] . $val['img'];
  62. }
  63. }
  64. if (empty($gCity)) {
  65. $gCity = Yii::$app->hostserver->hostId;
  66. if ($gCity != 0) {
  67. $cityName = \common\models\CategoryCity::findOne($gCity)['city_name'];
  68. } else {
  69. $cityName = '全国';
  70. }
  71. } else {
  72. $gCity = Yii::$app->hostserver->hostId;
  73. $cityName = \common\models\CategoryCity::findOne($gCity)['city_name'];
  74. }
  75. //导航
  76. $sysmenu = new \common\models\Frontend();
  77. $sysmenu->pid = 5;
  78. $SysRows = $sysmenu->SonList(8, ['name', 'url', 'icon', 'function', 'width']);
  79. //专题入口
  80. $entrance = new \common\models\MiniRotation();
  81. $entrance->del = 1;
  82. $zt = $entrance->getAll(5, 2);
  83. // //热门区域
  84. // $CityModel = new PushmCity();
  85. // $CityModel->type = 1;
  86. // $CityModel->abroad = 1;
  87. // $HotCity = $CityModel->Homelist(7);
  88. //
  89. // $CityModel->abroad = 2;
  90. // $HotCityb = $CityModel->Homelist(8);
  91. return $this->render('index', [
  92. 'lunbo' => $lunbo,
  93. // 'tese'=>$tese,
  94. 'tuijian' => $tuijian,
  95. 'news' => $news,
  96. 'newsc' => $newsc,
  97. 'gcity' => $gCity,
  98. 'cityname' => $cityName,
  99. 'sysmenu' => $SysRows,
  100. 'hot_house' => $hot,
  101. 'pinpai' => $pinpai,
  102. 'zt' => $zt
  103. ]);
  104. }
  105. public function actionHothouses()
  106. {
  107. // $model = new IndexServer();
  108. // $hot = $model->Hothouse(Yii::$app->request->post());
  109. // if(!empty($hot))
  110. // {
  111. // foreach ($hot as &$val)
  112. // {
  113. // $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'];
  114. // }
  115. // return Help::JsonCode(Help::SUCCESS,'成功',$hot);
  116. // }
  117. return Help::JsonCode(Help::SUCCESS, '成功', []);
  118. }
  119. public function actionSearchalert()
  120. {
  121. $model = new IndexServer();
  122. $shaixuan = $model->shaixuan();
  123. $price = $model->PriceList();
  124. //热门区域
  125. $CityModel = new PushmCity();
  126. $CityModel->type = 1;
  127. $CityModel->abroad = 1;
  128. $HotCity = $CityModel->Homelist(7);
  129. $Housetype = \common\models\CategoryHousetype::find()->andWhere(['del' => 1])->andWhere(['state' => 1])->orderBy(['sort' => SORT_ASC])->limit(4)->asArray()->all();
  130. return $this->renderPartial('searchalert', ['shaixuan' => $Housetype, 'hot_city' => $HotCity]);
  131. }
  132. /**
  133. * 首页-底部 拨打电话图标
  134. * @return mixed
  135. */
  136. public function actionTelrand()
  137. {
  138. //二级域名,mhainan.xxx.com
  139. if (Yii::$app->hostserver->hostId != 0) {
  140. $input = Yii::$app->request->post();
  141. //没有选择区域的情况下
  142. if (empty($input['city']) || $input['city'] == 0) {
  143. $tel = new CategoryTelCity();
  144. //调取二级域名hostId的电话
  145. $hostid = Yii::$app->hostserver->hostId;
  146. $tel->cid = $hostid;
  147. if ($hostid == 37) {
  148. $tel->cid = 40; //防城港
  149. }
  150. if ($hostid == 48) {
  151. $tel->cid = 49; //昆明
  152. }
  153. if ($hostid == 28) {
  154. $tel->cid = 62; //珠海
  155. }
  156. $resultTel = $tel->CityTelOne();
  157. if (!empty($resultTel)) {
  158. $telArr = explode(',', $resultTel['tel']);
  159. $index = array_rand($telArr, 1);
  160. if (!empty($telArr[$index])) {
  161. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  162. }
  163. }
  164. }
  165. //有选择区域的情况下
  166. if (!empty($input['city']) && $input['city'] != 0) {
  167. $tel = new CategoryTelCity();
  168. //调取二级域名hostId的电话
  169. $tel->cid = $input['city'];
  170. $resultTel = $tel->CityTelOne();
  171. if (!empty($resultTel)) {
  172. $telArr = explode(',', $resultTel['tel']);
  173. $index = array_rand($telArr, 1);
  174. if (!empty($telArr[$index])) {
  175. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  176. }
  177. } else { //如果区域市县没有电话,返回域名的电话
  178. $tel = new CategoryTelCity();
  179. $tel->cid = Yii::$app->hostserver->hostId;
  180. $resultTel = $tel->CityTelOne();
  181. if (!empty($resultTel)) {
  182. $telArr = explode(',', $resultTel['tel']);
  183. $index = array_rand($telArr, 1);
  184. if (!empty($telArr[$index])) {
  185. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  186. }
  187. }
  188. }
  189. }
  190. } else if (Yii::$app->hostserver->hostId == 0) {
  191. //m.shuofangw.com//全国,一级域名
  192. $input = Yii::$app->request->post();
  193. //没有选择区域的情况下
  194. if (empty($input['city']) || $input['city'] == 0) {
  195. //调取三亚的电话
  196. $tel = new CategoryTelCity();
  197. $tel->cid = 6;
  198. $resultTel = $tel->CityTelOne();
  199. if (!empty($resultTel)) {
  200. $telArr = explode(',', $resultTel['tel']);
  201. $index = array_rand($telArr, 1);
  202. if (!empty($telArr[$index])) {
  203. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  204. }
  205. }
  206. }
  207. //有选择区域的情况下
  208. if (!empty($input['city']) && $input['city'] != 0) {
  209. $city = CategoryCity::findOne($input['city']);
  210. $tel = new CategoryTelCity();
  211. $tel->cid = $input['city'];
  212. if ($input['city'] == 37) {
  213. $tel->cid = 40; //防城港
  214. }
  215. if ($input['city'] == 48) {
  216. $tel->cid = 49; //昆明
  217. }
  218. if ($input['city'] == 28) {
  219. $tel->cid = 62; //珠海
  220. }
  221. //选择的是省
  222. if ($city['pid'] == 0) {
  223. $resultTel = $tel->CityTelOne();
  224. if (!empty($resultTel)) {
  225. $telArr = explode(',', $resultTel['tel']);
  226. $index = array_rand($telArr, 1);
  227. if (!empty($telArr[$index])) {
  228. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  229. }
  230. }
  231. }
  232. //选择的是市县
  233. if ($city['pid'] != 0) {
  234. $resultTel = $tel->CityTelOne();
  235. if (!empty($resultTel)) {
  236. $telArr = explode(',', $resultTel['tel']);
  237. $index = array_rand($telArr, 1);
  238. if (!empty($telArr[$index])) {
  239. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  240. }
  241. } else { //如果为空,返回省的电话
  242. $telmodel = new CategoryTelCity();
  243. $telmodel->cid = $city['pid'];
  244. $result = $telmodel->CityTelOne();
  245. if (!empty($result)) {
  246. $telArr = explode(',', $result['tel']);
  247. $index = array_rand($telArr, 1);
  248. if (!empty($telArr[$index])) {
  249. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => Yii::$app->params['default_dialtel']]);
  257. }
  258. // /**
  259. // * 需求定制 价格-户型-区域
  260. // */
  261. // public function actionCustomized()
  262. // {
  263. // $arr['price'] = [10,20,30,40,50,60,70,80,90];
  264. // $typeModel = new \common\models\CategoryHousetype();
  265. // $typeModel->state = 1;
  266. // $arr['type'] = $typeModel->getList([],['id','huxing_name']);
  267. // $city = new \common\models\CategoryCity();
  268. // $city->pid = 0;
  269. // $arr['province'] = $city->getList([],['id','city_name']);
  270. // p($arr);
  271. // }
  272. /**
  273. * 传递父类区域ID
  274. * 返回子类区域信息
  275. */
  276. public function actionCityson()
  277. {
  278. $input = Yii::$app->request->post();
  279. if (!empty($input['pid'])) {
  280. $city = new \common\models\CategoryCity();
  281. $city->pid = $input['pid'];
  282. $rows = $city->getList([], ['id', 'city_name']);
  283. if (!empty($rows)) {
  284. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  285. }
  286. }
  287. return Help::JsonCode(Help::ERROR, '暂无区域信息');
  288. }
  289. /**
  290. * 区域价格走势
  291. */
  292. public function actionCityprice()
  293. {
  294. $model = new \common\models\PushCityprice();
  295. $model->city_id = Yii::$app->request->post('id');
  296. $rows = $model->FindCityRecordPrice();
  297. if (!empty($rows)) {
  298. $timestrap = strtotime($rows['price_at']);
  299. $rows['price_at'] = trim(date('m', $timestrap) . '月', '0');
  300. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  301. }
  302. }
  303. //需求数据
  304. // public function actionCustomizedform()
  305. // {
  306. //
  307. // }
  308. /**
  309. * 楼盘价格走势
  310. */
  311. public function actionHouseprice()
  312. {
  313. $input = Yii::$app->request->post();
  314. if (is_numeric($input['id'])) {
  315. $model = new \common\models\HousePriceRecord();
  316. $model->hid = $input['id'];
  317. $rows = $model->getList([]);
  318. if (!empty($rows)) {
  319. $arr = [];
  320. foreach ($rows as $val) {
  321. $arr['categories'][] = $val['create_time'];
  322. $arr['data'][] = $val['price'];
  323. $arr['unit'][] = $val['price_unit'];
  324. }
  325. return Help::JsonCode(Help::SUCCESS, '成功', $arr);
  326. }
  327. }
  328. return Help::JsonCode(Help::ERROR, '失败');
  329. }
  330. }