IndexServer.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/6/9
  6. * Time: 上午11:12
  7. */
  8. namespace mobile\server;
  9. use common\models\CategoryCity;
  10. use common\models\HouseNumber;
  11. use common\models\PushmRotation;
  12. use common\models\PushmCharacteristic;
  13. use common\models\PushmHouse;
  14. use common\models\PushmRecommend;
  15. use common\models\Characteristic;
  16. use common\models\HousesPrice;
  17. use Yii;
  18. class IndexServer
  19. {
  20. /*
  21. * 轮播图
  22. * */
  23. public function Lunbo()
  24. {
  25. $model = new PushmRotation();
  26. if(Yii::$app->hostserver->hostId != 0)
  27. {
  28. $model->city = Yii::$app->hostserver->hostId;
  29. $result=$model->HomeGetList();
  30. if(empty($result)){
  31. return $model->GetAllList();
  32. }else{
  33. return $model->HomeGetList();
  34. }
  35. }
  36. return $model->GetAllList();
  37. }
  38. /*
  39. * 搜索框-热门筛选
  40. * */
  41. public function shaixuan()
  42. {
  43. $model = new PushmHouse();
  44. $model->type = 2;
  45. $rows = $model->Homegetlist(10);
  46. if(!empty($rows))
  47. {
  48. return $rows;
  49. }
  50. }
  51. /*
  52. * 搜索框 - 价格
  53. * */
  54. public function PriceList()
  55. {
  56. $PriceModel = new HousesPrice();
  57. $PriceList = $PriceModel->getList([],['price','id']);
  58. if($PriceList != null)
  59. {
  60. return $PriceList;
  61. }
  62. }
  63. /*
  64. * 特色推荐
  65. * */
  66. public function tese()
  67. {
  68. $model = new PushmCharacteristic();
  69. return $model->Homegetlist(3);
  70. }
  71. /*
  72. * 热销楼盘
  73. * */
  74. public function Hothouse($input)
  75. {
  76. $row = [];
  77. if(empty($input['city']))
  78. {
  79. $model = new PushmHouse();
  80. $model->type = $input['type'];
  81. $rows = $model->Homegetlist(6,$input['rand']);
  82. }
  83. else
  84. {
  85. $id = CategoryCity::find()->select(['id'])->andWhere(['pid'=>$input['city']])->asArray()->all();
  86. $city = array_column($id,'id');
  87. $h = new PushmHouse();
  88. $h->type = $input['type'];
  89. $rows = $h->CityGetHome($city);
  90. }
  91. // if(isset($input['city']) && $input['city'] == 0)
  92. // {
  93. // $model = new PushmHouse();
  94. // $model->type = $input['type'];
  95. // $rows = $model->Homegetlist(6,$input['rand']);
  96. // }
  97. // else if ( $input['city'] != 0)
  98. // {
  99. // $id = CategoryCity::find()->select(['id'])->andWhere(['pid'=>$input['city']])->asArray()->all();
  100. // $city = array_column($id,'id');
  101. // $h = new PushmHouse();
  102. // $h->type = $input['type'];
  103. // $rows = $h->CityGetHome($city);
  104. // }
  105. if(!empty($rows))
  106. {
  107. foreach ($rows as &$val)
  108. {
  109. if(!empty($val['characteristic']))
  110. {
  111. // $val['characteristic'] = $this->Subject(json_decode($val['characteristic']),3);
  112. $val['characteristic'] = \common\fm\HouseHandle::ChangeCharacteristic($val['characteristic']);
  113. }
  114. // $val['tel'] = $this->RandTel($val['cid']);
  115. $val['tel'] = \common\fm\HouseHandle::ChangeCityTel($val['cid']);
  116. //查询是否单独设置楼盘号码
  117. if (!empty(HouseNumber::SearchNumber($val['id']))) {
  118. $val['tel'] = HouseNumber::SearchNumber($val['id']);
  119. }
  120. //楼盘状态
  121. $val['state'] = Yii::$app->params['HouseSalesStatus'][$val['state']];
  122. }
  123. }
  124. return $rows;
  125. }
  126. /*
  127. * 品房推荐
  128. * */
  129. public function tuijian()
  130. {
  131. $model = new PushmRecommend();
  132. return $model->Homegetlist(10);
  133. }
  134. /*
  135. * 热门地区
  136. * */
  137. public function hotCity()
  138. {
  139. $model = new \common\models\PushmCity();
  140. $model->type = 1;
  141. $rows = $model->Homegetlist(6);
  142. return $rows;
  143. }
  144. //资讯
  145. public function newslist()
  146. {
  147. $model = new \common\models\PushmNews();
  148. $model->type = 1;
  149. return $model->Homegetlist(4);
  150. }
  151. //资讯栏目
  152. public function NewsColumn()
  153. {
  154. $model = new \common\models\PushmNewscolumn();
  155. return $model->Homegetlist(4);
  156. }
  157. //特色主题 超过3个随机返回3个元素
  158. public function Subject($id,$num = 3)
  159. {
  160. $char = new Characteristic();
  161. if(is_array($id) && !empty($id))
  162. {
  163. $char->id = $id;
  164. $charMode = array_column($char->getList([],['id','name']),'name','id');
  165. if($charMode != null)
  166. {
  167. $count = count($charMode);
  168. $arr = [];
  169. if($count >= 3)
  170. {
  171. $rand = array_rand($charMode,$num);
  172. foreach ($rand as $key=>$val)
  173. {
  174. $arr[$key] = $charMode[$val];
  175. }
  176. }
  177. else
  178. {
  179. $arr = $charMode;
  180. }
  181. return $arr;
  182. }
  183. }
  184. }
  185. //楼盘随机电话
  186. public function RandTel($city)
  187. {
  188. $tel = new \common\models\CategoryTelCity();
  189. $tel->cid = $city;
  190. $telModel = $tel->CityTelOne();
  191. if($telModel != null)
  192. {
  193. $telArr = explode(',',$telModel['tel']);
  194. $randNum = array_rand($telArr,1);
  195. return $telArr[$randNum];
  196. }
  197. }
  198. public function getProvinceName($province)
  199. {
  200. $model = new \common\models\CategoryCity();
  201. $data = $model::find()->select(['city_name'])->andWhere(['id'=>$province])->asArray()->one();
  202. if(!empty($data)){
  203. return $data;
  204. }
  205. }
  206. }