123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/8/18
- * Time: 上午10:46
- * 手机端和PC端楼盘相关共用部分
- */
- namespace common\fm;
- use common\models\CategoryTelCity;
- use common\models\Characteristic;
- use common\models\HousePriceRecord;
- use Yii;
- use yii\helpers\ArrayHelper;
- class HouseHandle
- {
- /**
- * 楼盘首页没有区域需要用到的跳转(商务通需要用到)
- */
- public function CityLocation()
- {
- $view = Yii::$app->view;
- $mainUrl = $view->params['main_city_url'];
- if (!is_numeric($_GET['hid'])) {
- $ex = explode('-', $_GET['hid']);
- if (!empty($ex[1]) && is_numeric($ex[1])) {
- $_GET['hid'] = $ex[1];
- } else {
- header('Location:/');
- exit;
- }
- } else {
- $inp = Yii::$app->request->get();
- $m = new \common\models\House();
- $r = $m->FindById($inp['hid']);
- if ($r) {
- $city = \common\models\CategoryCity::findOne($r->city);
- if ($city['pid'] != 0) {
- $father_city = \common\models\CategoryCity::findOne($city['pid']);
- if (!empty($father_city['a'])) {
- $httpUrl = 'http://' . $father_city['a'] . '.' . $mainUrl;
- }
- }
- header('Location:' . $httpUrl . '/house/' . $city['pinyin'] . '-' . $inp['hid'] . '/');
- exit;
- }
- // $url = Yii::$app->request->getHostInfo();
- header('Location:http://www.' . $mainUrl . '/house/default-' . $inp['hid'] . '/');
- exit;
- }
- }
- /**
- * 楼盘首页没有区域需要用到的跳转(商务通需要用到)
- */
- public function MobileCityLocation()
- {
- $view = Yii::$app->view;
- $mainUrl = $view->params['main_city_url'];
- if (!is_numeric($_GET['hid'])) {
- $ex = explode('-', $_GET['hid']);
- if (!empty($ex[1]) && is_numeric($ex[1])) {
- $_GET['hid'] = $ex[1];
- } else {
- header('Location:/');
- exit;
- }
- } else {
- $inp = Yii::$app->request->get();
- $m = new \common\models\House();
- $r = $m->FindById($inp['hid']);
- if ($r) {
- $city = \common\models\CategoryCity::findOne($r->city);
- if ($city['pid'] != 0) {
- $father_city = \common\models\CategoryCity::findOne($city['pid']);
- if (!empty($father_city['a'])) {
- $httpUrl = 'http://m' . $father_city['a'] . '.' . $mainUrl;
- }
- }
- header('Location:' . $httpUrl . '/house/' . $city['pinyin'] . '-' . $inp['hid'] . '/');
- exit;
- }
- // $url = Yii::$app->request->getHostInfo();
- header('Location:http://m.' . $mainUrl . '/house/default-' . $inp['hid'] . '/');
- exit;
- }
- }
- //转换特色主题
- public static function ChangeCharacteristic($Characteristic)
- {
- if (empty($Characteristic)) return [];
- $cacheName = 'params:characteristic';
- $cache = Yii::$app->redis;
- $cacheContent = $cache->get($cacheName);
- $arr = [];
- if ($cacheContent) {
- $cid = json_decode($cacheContent, true);
- } else {
- $characteristic = new \common\models\Characteristic();
- $row = $characteristic->getListAll();
- $cid = array_column($row, 'name', 'id');
- $cache->set($cacheName, json_encode($cid));
- }
- if ($cid) {
- if (!empty($Characteristic) && is_string($Characteristic)) {
- $cha = json_decode($Characteristic, true);
- if (count($cha) > 3) {
- $rand_keys = array_rand($cha, 3);
- isset($cid[$cha[$rand_keys[0]]]) ? $arr[] = $cid[$cha[$rand_keys[0]]] : '';
- isset($cid[$cha[$rand_keys[1]]]) ? $arr[] = $cid[$cha[$rand_keys[1]]] : '';
- isset($cid[$cha[$rand_keys[2]]]) ? $arr[] = $cid[$cha[$rand_keys[2]]] : '';
- } else {
- foreach ($cha as $v) {
- isset($cid[$v]) ? $arr[] = $cid[$v] : '';
- }
- }
- }
- }
- return $arr;
- }
- //随机电话
- public static function ChangeCityTel($city)
- {
- $cacheName = 'params:citytel';
- $cache = Yii::$app->redis;
- $cacheContent = $cache->get($cacheName);
- if ($cacheContent) {
- $cityTel = json_decode($cacheContent, true);
- } else {
- $Tel = new \common\models\CategoryTelCity();
- $telRow = $Tel->QgetAll();
- if ($telRow) {
- $cityTel = [];
- foreach ($telRow as &$v) {
- $cityTel[$v['cid']] = explode(',', $v['tel']);
- }
- $cache->set($cacheName, json_encode($cityTel));
- }
- }
- if (isset($cityTel[$city]) && !empty($cityTel[$city])) {
- $rand = array_rand($cityTel[$city], 1);
- return $cityTel[$city][$rand];
- }
- return Yii::$app->params['default_dialtel'];
- }
- //楼盘价格走势
- public static function HousePrice($Id)
- {
- $list = (new HousePriceRecord())->GetPrice($Id);
- if ($list != null) {
- $arr = [];
- foreach ($list as $val) {
- $arr['categories'][] = $val['create_time'];
- $arr['data'][] = $val['price'];
- $arr['unit'][] = $val['price_unit'];
- }
- return $arr;
- }
- }
- /**
- * 根据价格单位返回是均价还是总价
- * @param $priceunit
- * @return string
- */
- public static function priceUnit($priceunit)
- {
- if (strpos($priceunit, '㎡') !== false) {
- return '均';
- }
- if (strpos($priceunit, '套') !== false) {
- return '总';
- }
- }
-
- //楼盘随机电话
- public static function RandTel($city)
- {
- $tel = new CategoryTelCity();
- $tel->cid = $city;
- $telModel = $tel->CityTelOne();
- if ($telModel != null) {
- $telArr = explode(',', $telModel['tel']);
- $randNum = array_rand($telArr, 1);
- return $telArr[$randNum];
- }
- }
-
- //特色主题 超过3个随机返回3个元素
- public static function Subject($id, $num = 3)
- {
- $char = new Characteristic();
- if (is_array($id) && !empty($id)) {
- $char->id = $id;
- $charMode = array_column($char->getList([], ['id', 'name']), 'name', 'id');
- if ($charMode != null) {
- $count = count($charMode);
- $arr = [];
- if ($count >= 3) {
- $rand = array_rand($charMode, $num);
- foreach ($rand as $key => $val) {
- $arr[$key] = $charMode[$val];
- }
- } else {
- $arr = $charMode;
- }
- return $arr;
- }
- }
- }
- }
|