IndexController.php 11 KB

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