Пример #1
0
 public static function getMostHotComms($cityId, $commIds, $fields = array())
 {
     // TYPE = 0 AND scoreRank IN (2,3) AND isY = 1";
     try {
         $allComm_today = Model_Mobile_HotComm::data_access()->filter('cityId', $cityId)->filter('type', 0)->filter_by_op('scoreRank', 'in', array(2, 3))->filter('isY', 1)->filter_by_op('commId', 'in', $commIds)->load_field($fields)->get_all();
         $yesterday = date("Ymd", time() - 86400);
         $allComm_yesterday = Model_Mobile_HotComm::data_access($yesterday)->filter('cityId', $cityId)->filter('type', 0)->filter_by_op('scoreRank', 'in', array(2, 3))->filter('isY', 1)->filter_by_op('commId', 'in', $commIds)->load_field($fields)->get_all();
     } catch (Exception $e) {
         $allComm = false;
     }
     return array_merge($allComm_today, $allComm_yesterday);
 }
Пример #2
0
 public function handle_request_internal()
 {
     $nearby_comm = new V1_Comm_GetNearbyController();
     $this->_params['pageSize'] = $this->_params['pageSize'] ? $this->_params['pageSize'] : self::NEARBY_COMM_NUM;
     //小区数目为40
     $key = self::MEMCACHE_KEY_FIND_NEARBY_COMMS . '_';
     foreach ($this->_params as $k => $v) {
         if (in_array($k, array('brokerId', 'cityId', 'mapType', 'lat', 'lng'))) {
             $key .= $k . '=' . $v;
         }
     }
     $key .= '_' . date("Ymd");
     $memcache = APF_Cache_Factory::get_instance()->get_memcache();
     $result = $memcache->get($key);
     $cityId = $this->_params['cityId'];
     if (empty($result)) {
         //初始化数组
         $commId = array();
         $topComms = array();
         $commonComms = array();
         $lanHaiComms = array();
         $hotComms = array();
         $nearby_comm = $nearby_comm->getNearbyComm($this->_params, 1, 0);
         if (!empty($nearby_comm) && $nearby_comm['count'] > 0) {
             //获取全部小区ID数组
             foreach ($nearby_comm['communities'] as $comm) {
                 $commIds[] = $comm['id'];
             }
             //从蓝海小区表获取相关数据
             //蓝海小区城市开关(产品表示暂不启用?)
             //$isOpenCity = Model_Mobile_TightCommCity::checkOpenCity($this->_params['cityId']);
             $allLanHaiComms = Model_Mobile_LanHaiComm::getAllLanHaiComms($commIds, array('commId', 'spreadNum', 'averageVPPV'));
             if (!empty($allLanHaiComms)) {
                 $maxVPPVComm = 0;
                 foreach ($allLanHaiComms as $lanHaiComm) {
                     $totalVPPV = ceil($lanHaiComm->averageVPPV * $lanHaiComm->spreadNum);
                     if ($totalVPPV > $maxVPPVComm) {
                         $maxVPPVComm = $totalVPPV;
                         $topCommIds[0] = $lanHaiComm->commId;
                     }
                     $lanHaiComms[$lanHaiComm->commId]['spreadNum'] = $lanHaiComm->spreadNum;
                     $lanHaiComms[$lanHaiComm->commId]['totalVPPV'] = $totalVPPV;
                 }
                 //从返还小区表里获取返还小区
                 $lanHaiCommIds = array_keys($lanHaiComms);
                 $allFanComms = Model_Mobile_FanComm::getAllFanComms($lanHaiCommIds, array('commId'));
             }
             //从热门小区表、竞争激烈表获取相关数据
             $allHotComms = Model_Mobile_HotComm::getMostHotComms($cityId, $commIds, array('commId', 'spreadPropNum', 'totalVPPV', 'type'));
             if (!empty($allHotComms)) {
                 $maxVPPVComm = 0;
                 $totalVPPV = array();
                 foreach ($allHotComms as $hotComm) {
                     $totalVPPV[$hotComm['commId']]['totalVPPV'] += $hotComm['totalVPPV'];
                     $spreadNum[$hotComm['commId']]['spreadNum'] += $hotComm['spreadPropNum'];
                     if ($totalVPPV[$hotComm['commId']]['totalVPPV'] > $maxVPPVComm) {
                         $maxVPPVComm = $totalVPPV[$hotComm['commId']]['totalVPPV'];
                         if (!in_array($hotComm['commId'], $lanHaiCommIds)) {
                             $topCommIds[1] = $hotComm['commId'];
                         }
                     }
                     $hotComms[$hotComm['commId']]['spreadNum'] = $spreadNum[$hotComm['commId']]['spreadNum'];
                     $hotComms[$hotComm['commId']]['totalVPPV'] = $totalVPPV[$hotComm['commId']]['totalVPPV'];
                 }
             }
             //循环小区数组,加上小区类型(蓝海、热门),房源数,vppv
             foreach ($nearby_comm['communities'] as $k => &$comm) {
                 $comm['commType'] = '';
                 $comm['isFanComm'] = 0;
                 $comm['spreadNum'] = 0;
                 $comm['totalVPPV'] = 0;
                 //打标签
                 if (isset($hotComms[$comm['id']])) {
                     $comm['commType'] = self::COMMTYPE_HOT;
                     $comm['spreadNum'] = $hotComms[$comm['id']]['spreadNum'];
                     $comm['totalVPPV'] = $hotComms[$comm['id']]['totalVPPV'];
                 }
                 if (isset($lanHaiComms[$comm['id']])) {
                     $comm['commType'] = self::COMMTYPE_LAN;
                     $comm['spreadNum'] = $lanHaiComms[$comm['id']]['spreadNum'];
                     $comm['totalVPPV'] = $lanHaiComms[$comm['id']]['totalVPPV'];
                     if (!empty($allFanComms)) {
                         foreach ($allFanComms as $fanComm) {
                             if ($fanComm->commId == $comm['id']) {
                                 $comm['isFanComm'] = 1;
                             }
                         }
                     }
                 } else {
                     //获取该小区的VPPV和推广房源数
                 }
                 if (!empty($topCommIds)) {
                     //从普通小区数组中去除top小区位的小区
                     if (in_array($comm['id'], $topCommIds)) {
                         foreach ($topCommIds as $k => $commId) {
                             if ($comm['id'] == $commId) {
                                 $topComms[] = $comm;
                             }
                         }
                     } else {
                         $common_comms[] = $comm;
                     }
                 } else {
                     $common_comms[] = $comm;
                 }
             }
             $commonComms = $common_comms;
             ksort($topComms);
         }
         $result['topComms'] = $topComms;
         $result['commonComms'] = $commonComms;
         if (!(empty($result['topComms']) && empty($result['commonComms']))) {
             $memcache->add($key, $result, 0, 86400);
             //24h
         }
     }
     $ret = array('status' => 'ok', 'data' => $result);
     return $ret;
 }