IndexController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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\PushRotation;
  12. use common\models\PushmCity;
  13. use common\models\PushmColumn;
  14. use mobile\base\CommonController;
  15. use mobile\server\IndexServer;
  16. use Yii;
  17. use mobile\base\Help;
  18. class IndexController extends CommonController
  19. {
  20. public $enableCsrfValidation = false;
  21. public function actionIndex()
  22. {
  23. //获取当前模块
  24. $module = Yii::$app->hostserver->module;
  25. //导航
  26. $sysmenu = new \common\models\Frontend();
  27. $sysmenu->pid = 208;
  28. $sysrows = $sysmenu->SonList(8, ['name', 'url', 'icon', 'id', 'function']);
  29. $lunbo = (new PushRotation())->getRoationChart(5, 5); //轮播图
  30. $IndexModel = new IndexServer();
  31. $news = $IndexModel->newslist(); //咨询列表
  32. $housetou = $IndexModel->getHouseTouTiao(1,3); //获取房产头条推送
  33. $hothouse = $IndexModel->getHotHouse(12,3); //获取首页热榜楼盘
  34. $PCIndexModel = new \frontend\server\IndexServer();
  35. $vrhouse = $PCIndexModel->getVrHouse(4); //获取VR看房
  36. $pushaerial = $PCIndexModel->getPushAerial(4); //获取航拍实景
  37. //区域
  38. $gCity = Yii::$app->request->get('city');
  39. if (empty($gCity)) {
  40. $gCity = 60;
  41. if ($gCity != 0) {
  42. $cityName = CategoryCity::findOne($gCity)['city_name'];
  43. } else {
  44. $cityName = '海南';
  45. }
  46. } else {
  47. $cityName = CategoryCity::findOne($gCity)['city_name'];
  48. }
  49. return $this->render($this->action->id, [
  50. 'module' => $module['module'],
  51. 'sysmenu' => $sysrows,
  52. 'cityname' => $cityName,
  53. 'news' => $news,
  54. 'lunbo'=>$lunbo,
  55. 'housetou'=>$housetou,
  56. 'hothouse'=>$hothouse,
  57. 'vrhouse'=>$vrhouse,
  58. 'pushaerial'=>$pushaerial
  59. ]);
  60. }
  61. public function actionHothouses()
  62. {
  63. // $model = new IndexServer();
  64. // $hot = $model->Hothouse(Yii::$app->request->post());
  65. // if(!empty($hot))
  66. // {
  67. // foreach ($hot as &$val)
  68. // {
  69. // $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'];
  70. // }
  71. // return Help::JsonCode(Help::SUCCESS,'成功',$hot);
  72. // }
  73. return Help::JsonCode(Help::SUCCESS, '成功', []);
  74. }
  75. public function actionSearchalert()
  76. {
  77. $model = new IndexServer();
  78. $shaixuan = $model->shaixuan();
  79. $price = $model->PriceList();
  80. //热门区域
  81. $CityModel = new PushmCity();
  82. $CityModel->type = 1;
  83. $CityModel->abroad = 1;
  84. $HotCity = $CityModel->Homelist(7);
  85. $Housetype = \common\models\CategoryHousetype::find()->andWhere(['del' => 1])->andWhere(['state' => 1])->orderBy(['sort' => SORT_ASC])->limit(4)->asArray()->all();
  86. return $this->renderPartial('searchalert', ['shaixuan' => $Housetype, 'hot_city' => $HotCity]);
  87. }
  88. /**
  89. * 首页-底部 拨打电话图标
  90. * @return mixed
  91. */
  92. public function actionTelrand()
  93. {
  94. //二级域名,mhainan.xxx.com
  95. if (Yii::$app->hostserver->hostId != 0) {
  96. $input = Yii::$app->request->post();
  97. //没有选择区域的情况下
  98. if (empty($input['city']) || $input['city'] == 0) {
  99. $tel = new CategoryTelCity();
  100. //调取二级域名hostId的电话
  101. $hostid = Yii::$app->hostserver->hostId;
  102. $tel->cid = $hostid;
  103. if ($hostid == 37) {
  104. $tel->cid = 40; //防城港
  105. }
  106. if ($hostid == 48) {
  107. $tel->cid = 49; //昆明
  108. }
  109. if ($hostid == 28) {
  110. $tel->cid = 62; //珠海
  111. }
  112. $resultTel = $tel->CityTelOne();
  113. if (!empty($resultTel)) {
  114. $telArr = explode(',', $resultTel['tel']);
  115. $index = array_rand($telArr, 1);
  116. if (!empty($telArr[$index])) {
  117. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  118. }
  119. }
  120. }
  121. //有选择区域的情况下
  122. if (!empty($input['city']) && $input['city'] != 0) {
  123. $tel = new CategoryTelCity();
  124. //调取二级域名hostId的电话
  125. $tel->cid = $input['city'];
  126. $resultTel = $tel->CityTelOne();
  127. if (!empty($resultTel)) {
  128. $telArr = explode(',', $resultTel['tel']);
  129. $index = array_rand($telArr, 1);
  130. if (!empty($telArr[$index])) {
  131. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  132. }
  133. } else { //如果区域市县没有电话,返回域名的电话
  134. $tel = new CategoryTelCity();
  135. $tel->cid = Yii::$app->hostserver->hostId;
  136. $resultTel = $tel->CityTelOne();
  137. if (!empty($resultTel)) {
  138. $telArr = explode(',', $resultTel['tel']);
  139. $index = array_rand($telArr, 1);
  140. if (!empty($telArr[$index])) {
  141. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  142. }
  143. }
  144. }
  145. }
  146. } else if (Yii::$app->hostserver->hostId == 0) {
  147. //m.shuofangw.com//全国,一级域名
  148. $input = Yii::$app->request->post();
  149. //没有选择区域的情况下
  150. if (empty($input['city']) || $input['city'] == 0) {
  151. //调取三亚的电话
  152. $tel = new CategoryTelCity();
  153. $tel->cid = 6;
  154. $resultTel = $tel->CityTelOne();
  155. if (!empty($resultTel)) {
  156. $telArr = explode(',', $resultTel['tel']);
  157. $index = array_rand($telArr, 1);
  158. if (!empty($telArr[$index])) {
  159. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  160. }
  161. }
  162. }
  163. //有选择区域的情况下
  164. if (!empty($input['city']) && $input['city'] != 0) {
  165. $city = CategoryCity::findOne($input['city']);
  166. $tel = new CategoryTelCity();
  167. $tel->cid = $input['city'];
  168. if ($input['city'] == 37) {
  169. $tel->cid = 40; //防城港
  170. }
  171. if ($input['city'] == 48) {
  172. $tel->cid = 49; //昆明
  173. }
  174. if ($input['city'] == 28) {
  175. $tel->cid = 62; //珠海
  176. }
  177. //选择的是省
  178. if ($city['pid'] == 0) {
  179. $resultTel = $tel->CityTelOne();
  180. if (!empty($resultTel)) {
  181. $telArr = explode(',', $resultTel['tel']);
  182. $index = array_rand($telArr, 1);
  183. if (!empty($telArr[$index])) {
  184. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  185. }
  186. }
  187. }
  188. //选择的是市县
  189. if ($city['pid'] != 0) {
  190. $resultTel = $tel->CityTelOne();
  191. if (!empty($resultTel)) {
  192. $telArr = explode(',', $resultTel['tel']);
  193. $index = array_rand($telArr, 1);
  194. if (!empty($telArr[$index])) {
  195. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  196. }
  197. } else { //如果为空,返回省的电话
  198. $telmodel = new CategoryTelCity();
  199. $telmodel->cid = $city['pid'];
  200. $result = $telmodel->CityTelOne();
  201. if (!empty($result)) {
  202. $telArr = explode(',', $result['tel']);
  203. $index = array_rand($telArr, 1);
  204. if (!empty($telArr[$index])) {
  205. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => $telArr[$index]]);
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. return Help::JsonCode(Help::SUCCESS, '成功', ['tel' => Yii::$app->params['default_dialtel']]);
  213. }
  214. // /**
  215. // * 需求定制 价格-户型-区域
  216. // */
  217. // public function actionCustomized()
  218. // {
  219. // $arr['price'] = [10,20,30,40,50,60,70,80,90];
  220. // $typeModel = new \common\models\CategoryHousetype();
  221. // $typeModel->state = 1;
  222. // $arr['type'] = $typeModel->getList([],['id','huxing_name']);
  223. // $city = new \common\models\CategoryCity();
  224. // $city->pid = 0;
  225. // $arr['province'] = $city->getList([],['id','city_name']);
  226. // p($arr);
  227. // }
  228. /**
  229. * 传递父类区域ID
  230. * 返回子类区域信息
  231. */
  232. public function actionCityson()
  233. {
  234. $input = Yii::$app->request->post();
  235. if (!empty($input['pid'])) {
  236. $city = new \common\models\CategoryCity();
  237. $city->pid = $input['pid'];
  238. $rows = $city->getList([], ['id', 'city_name']);
  239. if (!empty($rows)) {
  240. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  241. }
  242. }
  243. return Help::JsonCode(Help::ERROR, '暂无区域信息');
  244. }
  245. /**
  246. * 区域价格走势
  247. */
  248. public function actionCityprice()
  249. {
  250. $model = new \common\models\PushCityprice();
  251. $model->city_id = Yii::$app->request->post('id');
  252. $rows = $model->FindCityRecordPrice();
  253. if (!empty($rows)) {
  254. $timestrap = strtotime($rows['price_at']);
  255. $rows['price_at'] = trim(date('m', $timestrap) . '月', '0');
  256. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  257. }
  258. }
  259. //需求数据
  260. // public function actionCustomizedform()
  261. // {
  262. //
  263. // }
  264. /**
  265. * 楼盘价格走势
  266. */
  267. public function actionHouseprice()
  268. {
  269. $input = Yii::$app->request->post();
  270. if (is_numeric($input['id'])) {
  271. $model = new \common\models\HousePriceRecord();
  272. $model->hid = $input['id'];
  273. $rows = $model->getList([]);
  274. if (!empty($rows)) {
  275. $arr = [];
  276. foreach ($rows as $val) {
  277. $arr['categories'][] = $val['create_time'];
  278. $arr['data'][] = $val['price'];
  279. $arr['unit'][] = $val['price_unit'];
  280. }
  281. return Help::JsonCode(Help::SUCCESS, '成功', $arr);
  282. }
  283. }
  284. return Help::JsonCode(Help::ERROR, '失败');
  285. }
  286. }