JsonController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace frontend\controllers;
  3. use common\models\House;
  4. use common\models\HousePriceRecord;
  5. use common\models\News;
  6. use common\models\Pricetrends;
  7. use frontend\base\Help;
  8. use frontend\base\BaseController;
  9. use frontend\server\HouseServer;
  10. use Yii;
  11. class JsonController extends BaseController
  12. {
  13. /**
  14. * @var boolpushnewslist
  15. */
  16. public $enableCsrfValidation = false;
  17. /**
  18. * 区域价格走势
  19. * @return mixed
  20. */
  21. public function actionCityprice()
  22. {
  23. $model = new Pricetrends();
  24. $model->city_id = Yii::$app->request->get('id');
  25. $rows = $model->CityRecordPrice();
  26. if (!empty($rows)) {
  27. $arr = [];
  28. foreach ($rows as &$val) {
  29. $val['price_at'] = trim(date('m', $val['price_at']) . '月', '0');
  30. $arr['categories'][] = $val['price_at'];
  31. $arr['data'][] = $val['price'];
  32. $arr['region'][] = $val['city_name'];
  33. }
  34. return Help::JsonCode(Help::SUCCESS, '成功', $arr);
  35. }
  36. return Help::JsonCode(Help::ERROR, '暂无数据');
  37. }
  38. /**
  39. * 楼盘价格走势
  40. * @return mixed
  41. */
  42. public function actionHouseprice()
  43. {
  44. $input = Yii::$app->request->post();
  45. if (is_numeric($input['id'])) {
  46. $model = new HousePriceRecord();
  47. $model->hid = $input['id'];
  48. $rows = $model->getList([]);
  49. if (!empty($rows)) {
  50. $arr = [];
  51. foreach ($rows as $val) {
  52. $arr['categories'][] = $val['create_time'];
  53. $arr['data'][] = $val['price'];
  54. }
  55. return Help::JsonCode(Help::SUCCESS, '成功', $arr);
  56. }
  57. }
  58. return Help::JsonCode(Help::ERROR, '失败');
  59. }
  60. /**
  61. * 底部推荐楼盘
  62. * @param $input
  63. * @return mixed
  64. */
  65. public function actionall()
  66. {
  67. $input = Yii::$app->request->post();
  68. switch ($input['type']) {
  69. case 'price':
  70. $model = new House();
  71. $model->sale_price = $input['content'];
  72. $a['sale_price'] = $input['content'];
  73. $result = $model->HomegetList(4, $a);
  74. break;
  75. case 'quyu':
  76. $model = new House();
  77. $model->city = $input['content'];
  78. $result = $model->HomegetList(4);
  79. break;
  80. }
  81. if (!empty($result)) {
  82. foreach ($result as &$val) {
  83. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  84. }
  85. return Help::JsonCode(Help::SUCCESS, '成功', $result);
  86. }
  87. return Help::JsonCode(Help::ERROR, '暂无数据');
  88. }
  89. /**
  90. * 楼盘所有相册
  91. * @return mixed
  92. */
  93. public function actionAlbumlist()
  94. {
  95. $model = new HouseServer();
  96. $album = $model->AlbumAll();
  97. if ($album != null) {
  98. return Help::JsonCode(Help::SUCCESS, '成功', $album);
  99. }
  100. return Help::JsonCode(Help::ERROR, '暂无数据');
  101. }
  102. /**
  103. * 楼盘户型数据
  104. * @return mixed
  105. */
  106. public function actionHousetypeall()
  107. {
  108. $model = new HouseServer();
  109. $rows = $model->TypeAll(Yii::$app->request->post(), false);
  110. if ($rows != null) {
  111. return Help::JsonCode(Help::SUCCESS, '成功', $rows);
  112. }
  113. }
  114. /**
  115. * 弹窗搜索结果
  116. * @return mixed
  117. */
  118. public function actionSearchresult()
  119. {
  120. $model = new HouseServer();
  121. $res = $model->SearchHouseName(Yii::$app->request->get());
  122. if (!empty($res)) {
  123. return Help::JsonCode(Help::SUCCESS, '成功', $res);
  124. }
  125. return Help::JsonCode(Help::ERROR, '暂无数据');
  126. }
  127. /**
  128. * 首页-大家都在关注
  129. * @return mixed
  130. */
  131. public function actionHousefollow()
  132. {
  133. $input = Yii::$app->request->get();
  134. $query = House::find();
  135. $query->select(['id', 'name'])->where(['is_push' => 2, 'del' => 1, 'province' => 68]);
  136. $query->limit = $input['limit'];
  137. $data = $query->orderBy('RAND()')->asArray()->all();
  138. if ($data) {
  139. return Help::JsonCode(Help::SUCCESS, '成功', $data);
  140. }
  141. return Help::JsonCode(Help::ERROR, '失败', $data);
  142. }
  143. //2020.10.22 vr改版获取推送区域的楼盘数据
  144. public function actionPushcityhouselist()
  145. {
  146. $input = Yii::$app->request->post();
  147. $model = new HouseServer();
  148. $data = $model->getHouseListByCity($input['city'], 6);
  149. return Help::JsonCode(Help::SUCCESS, '成功', $data);
  150. }
  151. //2020.10.25 v2改版首页推送资讯数据获取
  152. public function actionPushnewslist()
  153. {
  154. $input = Yii::$app->request->post();
  155. $data = (new News())->getNewsByCategory($input['news'],14);
  156. foreach ($data as &$val){
  157. $val['thumb'] = Yii::$app->params['httpImg']['host']. Yii::$app->params['httpImg']['newsthumb']. json_decode($val['thumb'],true)[0];
  158. }
  159. return Help::JsonCode(Help::SUCCESS, '成功', $data);
  160. }
  161. /**
  162. * 底部推荐楼盘
  163. * @param $input
  164. * @return mixed
  165. */
  166. public function actionTall()
  167. {
  168. $input = Yii::$app->request->post();
  169. switch ($input['type']) {
  170. case 'price':
  171. $model = new House();
  172. $model->sale_price = $input['content'];
  173. $a['sale_price'] = $input['content'];
  174. $result = $model->HomegetList(4, $a);
  175. break;
  176. case 'quyu':
  177. $model = new House();
  178. $model->city = $input['content'];
  179. $result = $model->HomegetList(4);
  180. break;
  181. }
  182. if (!empty($result)) {
  183. foreach ($result as &$val) {
  184. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  185. }
  186. return Help::JsonCode(Help::SUCCESS, '成功', $result);
  187. }
  188. return Help::JsonCode(Help::ERROR, '暂无数据');
  189. }
  190. }