HouseHandle.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/8/18
  6. * Time: 上午10:46
  7. * 手机端和PC端楼盘相关共用部分
  8. */
  9. namespace common\fm;
  10. use common\models\HousePriceRecord;
  11. use Yii;
  12. use yii\helpers\ArrayHelper;
  13. class HouseHandle
  14. {
  15. /**
  16. * 楼盘首页没有区域需要用到的跳转(商务通需要用到)
  17. */
  18. public function CityLocation()
  19. {
  20. $view = Yii::$app->view;
  21. $mainUrl = $view->params['main_city_url'];
  22. if (!is_numeric($_GET['hid'])) {
  23. $ex = explode('-', $_GET['hid']);
  24. if (!empty($ex[1]) && is_numeric($ex[1])) {
  25. $_GET['hid'] = $ex[1];
  26. } else {
  27. header('Location:/');
  28. exit;
  29. }
  30. } else {
  31. $inp = Yii::$app->request->get();
  32. $m = new \common\models\House();
  33. $r = $m->FindById($inp['hid']);
  34. if ($r) {
  35. $city = \common\models\CategoryCity::findOne($r->city);
  36. if ($city['pid'] != 0) {
  37. $father_city = \common\models\CategoryCity::findOne($city['pid']);
  38. if (!empty($father_city['a'])) {
  39. $httpUrl = 'http://' . $father_city['a'] . '.' . $mainUrl;
  40. }
  41. }
  42. header('Location:' . $httpUrl . '/house/' . $city['pinyin'] . '-' . $inp['hid'] . '/');
  43. exit;
  44. }
  45. // $url = Yii::$app->request->getHostInfo();
  46. header('Location:http://www.' . $mainUrl . '/house/default-' . $inp['hid'] . '/');
  47. exit;
  48. }
  49. }
  50. /**
  51. * 楼盘首页没有区域需要用到的跳转(商务通需要用到)
  52. */
  53. public function MobileCityLocation()
  54. {
  55. $view = Yii::$app->view;
  56. $mainUrl = $view->params['main_city_url'];
  57. if (!is_numeric($_GET['hid'])) {
  58. $ex = explode('-', $_GET['hid']);
  59. if (!empty($ex[1]) && is_numeric($ex[1])) {
  60. $_GET['hid'] = $ex[1];
  61. } else {
  62. header('Location:/');
  63. exit;
  64. }
  65. } else {
  66. $inp = Yii::$app->request->get();
  67. $m = new \common\models\House();
  68. $r = $m->FindById($inp['hid']);
  69. if ($r) {
  70. $city = \common\models\CategoryCity::findOne($r->city);
  71. if ($city['pid'] != 0) {
  72. $father_city = \common\models\CategoryCity::findOne($city['pid']);
  73. if (!empty($father_city['a'])) {
  74. $httpUrl = 'http://m' . $father_city['a'] . '.' . $mainUrl;
  75. }
  76. }
  77. header('Location:' . $httpUrl . '/house/' . $city['pinyin'] . '-' . $inp['hid'] . '/');
  78. exit;
  79. }
  80. // $url = Yii::$app->request->getHostInfo();
  81. header('Location:http://m.' . $mainUrl . '/house/default-' . $inp['hid'] . '/');
  82. exit;
  83. }
  84. }
  85. //转换特色主题
  86. public static function ChangeCharacteristic($Characteristic)
  87. {
  88. if (empty($Characteristic)) return [];
  89. $cacheName = 'params:characteristic';
  90. $cache = Yii::$app->redis;
  91. $cacheContent = $cache->get($cacheName);
  92. $arr = [];
  93. if ($cacheContent) {
  94. $cid = json_decode($cacheContent, true);
  95. } else {
  96. $characteristic = new \common\models\Characteristic();
  97. $row = $characteristic->getListAll();
  98. $cid = array_column($row, 'name', 'id');
  99. $cache->set($cacheName, json_encode($cid));
  100. }
  101. if ($cid) {
  102. if (!empty($Characteristic) && is_string($Characteristic)) {
  103. $cha = json_decode($Characteristic, true);
  104. if (count($cha) > 3) {
  105. $rand_keys = array_rand($cha, 3);
  106. isset($cid[$cha[$rand_keys[0]]]) ? $arr[] = $cid[$cha[$rand_keys[0]]] : '';
  107. isset($cid[$cha[$rand_keys[1]]]) ? $arr[] = $cid[$cha[$rand_keys[1]]] : '';
  108. isset($cid[$cha[$rand_keys[2]]]) ? $arr[] = $cid[$cha[$rand_keys[2]]] : '';
  109. } else {
  110. foreach ($cha as $v) {
  111. isset($cid[$v]) ? $arr[] = $cid[$v] : '';
  112. }
  113. }
  114. }
  115. }
  116. return $arr;
  117. }
  118. //随机电话
  119. public static function ChangeCityTel($city)
  120. {
  121. $cacheName = 'params:citytel';
  122. $cache = Yii::$app->redis;
  123. $cacheContent = $cache->get($cacheName);
  124. if ($cacheContent) {
  125. $cityTel = json_decode($cacheContent, true);
  126. } else {
  127. $Tel = new \common\models\CategoryTelCity();
  128. $telRow = $Tel->QgetAll();
  129. if ($telRow) {
  130. $cityTel = [];
  131. foreach ($telRow as &$v) {
  132. $cityTel[$v['cid']] = explode(',', $v['tel']);
  133. }
  134. $cache->set($cacheName, json_encode($cityTel));
  135. }
  136. }
  137. if (isset($cityTel[$city]) && !empty($cityTel[$city])) {
  138. $rand = array_rand($cityTel[$city], 1);
  139. return $cityTel[$city][$rand];
  140. }
  141. return Yii::$app->params['default_dialtel'];
  142. }
  143. //楼盘价格走势
  144. public static function HousePrice($Id)
  145. {
  146. $list = (new HousePriceRecord())->GetPrice($Id);
  147. if ($list != null) {
  148. $arr = [];
  149. foreach ($list as $val) {
  150. $arr['categories'][] = $val['create_time'];
  151. $arr['data'][] = $val['price'];
  152. $arr['unit'][] = $val['price_unit'];
  153. }
  154. return $arr;
  155. }
  156. }
  157. /**
  158. * 根据价格单位返回是均价还是总价
  159. * @param $priceunit
  160. * @return string
  161. */
  162. public static function priceUnit($priceunit)
  163. {
  164. if (strpos($priceunit, '㎡') !== false) {
  165. return '均';
  166. }
  167. if (strpos($priceunit, '套') !== false) {
  168. return '总';
  169. }
  170. }
  171. }