HouseHandle.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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\CategoryTelCity;
  11. use common\models\Characteristic;
  12. use common\models\HousePriceRecord;
  13. use Yii;
  14. use yii\helpers\ArrayHelper;
  15. class HouseHandle
  16. {
  17. /**
  18. * 楼盘首页没有区域需要用到的跳转(商务通需要用到)
  19. */
  20. public function CityLocation()
  21. {
  22. $view = Yii::$app->view;
  23. $mainUrl = $view->params['main_city_url'];
  24. if (!is_numeric($_GET['hid'])) {
  25. $ex = explode('-', $_GET['hid']);
  26. if (!empty($ex[1]) && is_numeric($ex[1])) {
  27. $_GET['hid'] = $ex[1];
  28. } else {
  29. header('Location:/');
  30. exit;
  31. }
  32. } else {
  33. $inp = Yii::$app->request->get();
  34. $m = new \common\models\House();
  35. $r = $m->FindById($inp['hid']);
  36. if ($r) {
  37. $city = \common\models\CategoryCity::findOne($r->city);
  38. if ($city['pid'] != 0) {
  39. $father_city = \common\models\CategoryCity::findOne($city['pid']);
  40. if (!empty($father_city['a'])) {
  41. $httpUrl = 'http://' . $father_city['a'] . '.' . $mainUrl;
  42. }
  43. }
  44. header('Location:' . $httpUrl . '/house/' . $city['pinyin'] . '-' . $inp['hid'] . '/');
  45. exit;
  46. }
  47. // $url = Yii::$app->request->getHostInfo();
  48. header('Location:http://www.' . $mainUrl . '/house/default-' . $inp['hid'] . '/');
  49. exit;
  50. }
  51. }
  52. /**
  53. * 楼盘首页没有区域需要用到的跳转(商务通需要用到)
  54. */
  55. public function MobileCityLocation()
  56. {
  57. $view = Yii::$app->view;
  58. $mainUrl = $view->params['main_city_url'];
  59. if (!is_numeric($_GET['hid'])) {
  60. $ex = explode('-', $_GET['hid']);
  61. if (!empty($ex[1]) && is_numeric($ex[1])) {
  62. $_GET['hid'] = $ex[1];
  63. } else {
  64. header('Location:/');
  65. exit;
  66. }
  67. } else {
  68. $inp = Yii::$app->request->get();
  69. $m = new \common\models\House();
  70. $r = $m->FindById($inp['hid']);
  71. if ($r) {
  72. $city = \common\models\CategoryCity::findOne($r->city);
  73. if ($city['pid'] != 0) {
  74. $father_city = \common\models\CategoryCity::findOne($city['pid']);
  75. if (!empty($father_city['a'])) {
  76. $httpUrl = 'http://m' . $father_city['a'] . '.' . $mainUrl;
  77. }
  78. }
  79. header('Location:' . $httpUrl . '/house/' . $city['pinyin'] . '-' . $inp['hid'] . '/');
  80. exit;
  81. }
  82. // $url = Yii::$app->request->getHostInfo();
  83. header('Location:http://m.' . $mainUrl . '/house/default-' . $inp['hid'] . '/');
  84. exit;
  85. }
  86. }
  87. //转换特色主题
  88. public static function ChangeCharacteristic($Characteristic)
  89. {
  90. if (empty($Characteristic)) return [];
  91. $cacheName = 'params:characteristic';
  92. $cache = Yii::$app->redis;
  93. $cacheContent = $cache->get($cacheName);
  94. $arr = [];
  95. if ($cacheContent) {
  96. $cid = json_decode($cacheContent, true);
  97. } else {
  98. $characteristic = new \common\models\Characteristic();
  99. $row = $characteristic->getListAll();
  100. $cid = array_column($row, 'name', 'id');
  101. $cache->set($cacheName, json_encode($cid));
  102. }
  103. if ($cid) {
  104. if (!empty($Characteristic) && is_string($Characteristic)) {
  105. $cha = json_decode($Characteristic, true);
  106. if (count($cha) > 3) {
  107. $rand_keys = array_rand($cha, 3);
  108. isset($cid[$cha[$rand_keys[0]]]) ? $arr[] = $cid[$cha[$rand_keys[0]]] : '';
  109. isset($cid[$cha[$rand_keys[1]]]) ? $arr[] = $cid[$cha[$rand_keys[1]]] : '';
  110. isset($cid[$cha[$rand_keys[2]]]) ? $arr[] = $cid[$cha[$rand_keys[2]]] : '';
  111. } else {
  112. foreach ($cha as $v) {
  113. isset($cid[$v]) ? $arr[] = $cid[$v] : '';
  114. }
  115. }
  116. }
  117. }
  118. return $arr;
  119. }
  120. //随机电话
  121. public static function ChangeCityTel($city)
  122. {
  123. $cacheName = 'params:citytel';
  124. $cache = Yii::$app->redis;
  125. $cacheContent = $cache->get($cacheName);
  126. if ($cacheContent) {
  127. $cityTel = json_decode($cacheContent, true);
  128. } else {
  129. $Tel = new \common\models\CategoryTelCity();
  130. $telRow = $Tel->QgetAll();
  131. if ($telRow) {
  132. $cityTel = [];
  133. foreach ($telRow as &$v) {
  134. $cityTel[$v['cid']] = explode(',', $v['tel']);
  135. }
  136. $cache->set($cacheName, json_encode($cityTel));
  137. }
  138. }
  139. if (isset($cityTel[$city]) && !empty($cityTel[$city])) {
  140. $rand = array_rand($cityTel[$city], 1);
  141. return $cityTel[$city][$rand];
  142. }
  143. return Yii::$app->params['default_dialtel'];
  144. }
  145. //楼盘价格走势
  146. public static function HousePrice($Id)
  147. {
  148. $list = (new HousePriceRecord())->GetPrice($Id);
  149. if ($list != null) {
  150. $arr = [];
  151. foreach ($list as $val) {
  152. $arr['categories'][] = $val['create_time'];
  153. $arr['data'][] = $val['price'];
  154. $arr['unit'][] = $val['price_unit'];
  155. }
  156. return $arr;
  157. }
  158. }
  159. /**
  160. * 根据价格单位返回是均价还是总价
  161. * @param $priceunit
  162. * @return string
  163. */
  164. public static function priceUnit($priceunit)
  165. {
  166. if (strpos($priceunit, '㎡') !== false) {
  167. return '均';
  168. }
  169. if (strpos($priceunit, '套') !== false) {
  170. return '总';
  171. }
  172. }
  173. //楼盘随机电话
  174. public static function RandTel($city)
  175. {
  176. $tel = new CategoryTelCity();
  177. $tel->cid = $city;
  178. $telModel = $tel->CityTelOne();
  179. if ($telModel != null) {
  180. $telArr = explode(',', $telModel['tel']);
  181. $randNum = array_rand($telArr, 1);
  182. return $telArr[$randNum];
  183. }
  184. }
  185. //特色主题 超过3个随机返回3个元素
  186. public static function Subject($id, $num = 3)
  187. {
  188. $char = new Characteristic();
  189. if (is_array($id) && !empty($id)) {
  190. $char->id = $id;
  191. $charMode = array_column($char->getList([], ['id', 'name']), 'name', 'id');
  192. if ($charMode != null) {
  193. $count = count($charMode);
  194. $arr = [];
  195. if ($count >= 3) {
  196. $rand = array_rand($charMode, $num);
  197. foreach ($rand as $key => $val) {
  198. $arr[$key] = $charMode[$val];
  199. }
  200. } else {
  201. $arr = $charMode;
  202. }
  203. return $arr;
  204. }
  205. }
  206. }
  207. }