public function handle_request() { $this->_apf = APF::get_instance(); $this->_request = $this->_apf->get_request(); $this->_params = $this->_request->get_parameters(); $request_body = file_get_contents('php://input'); if ($request_body) { $res = json_decode($request_body, true); if (is_array($res)) { foreach ($res as $k => $v) { $_REQUEST[$k] = $v; } } } $this->_params = array_merge($this->_params, $_REQUEST); $router_matches = $this->_request->get_router_matches(); try { // 验证参数 if (isset($this->paramRules)) { $validator = new Util_Validator($this->_params, $this->paramRules); if ($validator->fails()) { throw new Exception_General_InvalidParameters(json_encode($validator->messages())); } } // 通过缓存去获取数据 if (self::$_totalCacheOnOff && $this->_isCache && $this->setCacheKey()) { // 获取数据 $mem = APF_Cache_Factory::get_instance()->get_memcache(); if ($this->_params['rmCache']) { // 是否清除缓存 $mem->delete($this->_cacheKey); // 删除缓存 } $ret = $mem->get($this->_cacheKey); if (!$ret) { $ret = $this->handle_request_internal(); if ($ret['status'] == Const_APIStatus::RETURN_CODE_OK) { $mem->set($this->_cacheKey, $ret, $this->_isCacheZip, $this->_cacheTime); } } } else { $ret = $this->handle_request_internal(); } // 生成用户友好的错误消息 if ($ret['status'] == Const_APIStatus::RETURN_CODE_ERROR) { $apiError = new Api_Error($ret['message'], $ret['errcode']); if ($this->isDebugMode()) { $apiError->enableDebugMode(); } $ret = $apiError->toArray(); } } catch (Exception $e) { $apiError = new Api_Error($e); if ($this->isDebugMode()) { $apiError->enableDebugMode(); } $ret = $apiError->toArray(); } $this->output($ret); }
/** * 获取周边板块公共委托房源列表 * @param int $areaTypeId,$dateLine,$currentPage * @return array * */ public static function getAreaPublicCommissionList($areaTypeId, $dateLine) { //获取对当天有效的memcache $time = Util_MemCacheTime::getPublicCommissionByAreacode(); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $key = Util_MemCacheKey::getPublicCommissionByAreacode($areaTypeId, $dateLine); $value = $memcache->get($key); if (!$value) { $parentId = ltrim($areaTypeId, 0); //获取区域下符合条件的委托房源(发布于前天以前,当前被抢0、1次,列表显示逻辑与主营板块列表同) $arrParamCodes = self::getAreaCodesByParentId($parentId); $inparams = implode(',', array_fill(0, count($arrParamCodes), '?')); /* * jasonqian 2011-08-26 * propertystatus!=4 系统删除的房源不显示 */ if (!$inparams) { return array(); } $Conditions = " areacode in({$inparams}) and openStatus = ? and createtime > ? and createtime < ? and propertystatus in (1,3) and openBrokerCnt in(4,5) order by openBrokerCnt desc,createtime desc limit 60"; $Params = $arrParamCodes; $Params[] = 2; $Params[] = time() - 86400 * 30; $Params[] = $dateLine; //得到符合条件的委托房源(前天以前,目前被抢0、1次,在区域大范围内) $CommissionList = parent::getPublicCommissionList($Conditions, $Params, true); $value = $CommissionList; $memcache->set($key, $value, 0, $time); } return $value; }
/** * 获取业务逻辑缓存的内容 * @param string $p_strFunctionName * @param array $p_arrKeyValue * @return mix */ function getCache($p_strFunctionName = '', $p_arrKeyValue = array()) { if (get_class(APF::get_instance()->get_request()) !== 'AJKRequest') { return false; } if ('cc' == APF::get_instance()->get_request()->get_parameter('cc')) { $bolNeedCache = false; } else { $bolNeedCache = true; } $strCacheKey = self::_mkCacheKey($p_strFunctionName, $p_arrKeyValue); apf_require_class('APF_Cache_Factory'); $objMem = APF_Cache_Factory::get_instance()->get_memcache(); $arrCacheData = false; if ($bolNeedCache) { $arrCacheData = $objMem->get($strCacheKey); } else { $objMem->delete($strCacheKey); } $mixValue = false; if (false === $arrCacheData or null === $arrCacheData) { } else { $mixValue = $arrCacheData['DATA']; } if ($this->_bolDebug) { APF::get_instance()->debug($this->_strClassName . '[Memcache]->Get: ' . $strCacheKey . '|' . var_export($mixValue, true)); if (false !== $mixValue) { APF::get_instance()->debug($this->_strClassName . '[Memcache]->Info: Key=>' . $strCacheKey . ' Create=>' . date('Y-m-d H:i:s', $arrCacheData['CREATETIME']) . ' Expire=>' . (0 == $arrCacheData['LIFETIME'] ? 'unlimit' : date('Y-m-d H:i:s', $arrCacheData['CREATETIME'] + $arrCacheData['LIFETIME']))); } } return $mixValue; }
/** * @return APF_Cache_Factory */ public static function &get_instance() { if (!self::$instance) { self::$instance = new APF_Cache_Factory(); } return self::$instance; }
public function handle_request_internal() { // 关闭录入房源 $tmpTime = APF::get_instance()->get_config('fyk_onoff_time', 'fyk_common'); if (time() >= strtotime($tmpTime)) { return array('status' => 'error', 'message' => "现在无法录入房源"); } $userId = intval($this->_params['userId']); $data = $this->_params; //$commInfo = Bll_Community_CommunityGardener::getCommunityInfoByCommunityId($data['commId']); $commInfo = Bll_Community_APIComm::getInstance()->getInfoById($data['commId']); //判断用户是否有使用房源库的资格 $hasAccess = Bll_Fyk_Prop_Action::getInstance()->hasFykAccess($userId); if ($hasAccess === false) { $ary = array("status" => "error", "errcode" => Const_APIStatus::E_FYK_USER_NO_ACCESS, "message" => '该用户没有权限'); return $ary; } //验证用户是否达到发房上限 if (Const_Fyk::LIMIT_OF_PUBLISH > 0) { $isReach = $this->isReachTheLimitOfPublish($userId, Const_Fyk::LIMIT_OF_PUBLISH); if (!empty($isReach)) { return $isReach; } } //验证房源库是否达到每日发房总数上限 if (Const_Fyk::LIMIT_OF_TOTAL_PUBLISH > 0) { $isReachTotal = Bll_Fyk_Prop_Action::getInstance()->isReachTheLimitOfTotalPublish($commInfo['city_id'], Const_Fyk::LIMIT_OF_TOTAL_PUBLISH); if ($isReachTotal === true) { $ary = array('status' => 'error', 'errcode' => Const_APIStatus::E_FYK_PROP_PUBLISH_REACH_TOTAL_PUBLISH_NUM, 'message' => '该城市房源库达到每日发房数量上限'); return $ary; } } //验证发布的房源是否已被此经纪人发布过 $isInVerification = Bll_Fyk_Prop_Action::getInstance()->isPublishPropInVerification($userId, intval($data['commId']), $data['houseNum'], $data['buildNum']); if ($isInVerification === true) { $ary = array('status' => 'error', 'errcode' => Const_APIStatus::E_FYK_PROP_PUBLISH_IN_VERIFICATION, 'message' => '该房源已被此经纪人发布过'); return $ary; } $data['isOnly'] = $data['isOnly'] ? 1 : 0; $data['certificate'] = $data['certificate'] ? 1 : 0; $data['houseImages'] = $data['houseImages'] ? $data['houseImages'] : ''; $houseImages = array(); if (!empty($data['houseImages'])) { $houseImages = json_decode($data['houseImages'], true); } $acreage = round($data['acreage']); $base = array('userId' => $data['userId'], 'commId' => $data['commId'], 'buildNum' => trim($data['buildNum']), 'roomNum' => trim($data['houseNum']), 'ownerName' => $data['ownerName'], 'mobile' => $data['ownerPhone'], 'totalPrices' => $data['prices'], 'acreage' => $acreage, 'cell' => $data['cell'], 'hall' => $data['hall'], 'toilet' => $data['toilet'], 'totalFloor' => $data['totalFloor'], 'floor' => $data['floor'], 'orientation' => $data['orientation'], 'isOnly' => $data['isOnly'], 'certificate' => $data['certificate'], 'houseImages' => $houseImages); $body = json_encode(array('base' => $base, 'edit' => array())); $publishInfo = array('cityId' => $commInfo['city_id'], 'userId' => $data['userId'], 'operatorId' => '', 'operatorName' => '', 'status' => 0, 'source' => $data['fromType'], 'type' => 1, 'body' => $body, 'checkMsg' => '', 'createTime' => time()); $result = Model_Fyk_UserPropAction::getInstance()->insertData($publishInfo); if ($result) { //设置缓存 $publishCacheKey = Bll_Fyk_Prop_Action::getInstance()->getPublishCacheKey($userId, $data['commId'], $data['houseNum'], $data['buildNum']); $cache = APF_Cache_Factory::get_instance()->get_memcache(); $cache->set($publishCacheKey, 'fykPublish', 0, 300); return array("status" => "ok", "message" => "发布成功"); } else { return array("status" => "error", "errcode" => Const_APIStatus::E_FYK_PROP_PUBLISH_FAILURE, "message" => ""); } }
public function handle_request_internal() { $lng = $this->_params['lng']; $lat = $this->_params['lat']; $radius = isset($this->_params['radius']) ? $this->_params['radius'] : 3000; // 搜索半径,默认3000米 $total = isset($this->_params['total']) ? $this->_params['total'] : 500; // 最大总数,默认500 $days = isset($this->_params['days']) ? $this->_params['days'] : 3; // 查询天数,默认3天 $cache = APF_Cache_Factory::get_instance()->get_memcache(); $key = $this->generateCacheKey($lat, $lng, $days); $result = $cache->get($key); if ($result === false || $this->isDebugMode()) { // 获取近几日附近签到过的经纪人坐标 $brokerLocations = Bll_Broker_Location::getRoundBrokerLocationsInThePastFewDays($lng, $lat, $radius, $total, $days); $brokerIds = array_keys($brokerLocations); // 获取经纪人的等级 $brokerLevels = Model_Broker_AjkBrokerExtend::getMultiBrokerLevels($brokerIds); // 获取经纪人微聊状态(根据活动是否进行中,决定是否查询) if (Bll_Broker_CallAnalysis::isTalentEventOngoing()) { $brokerChatStats = Model_Chat_TalentStat::findMultiByBrokerIds($brokerIds); } // 获取经纪人明星中介状态(未判断城市是否开启等,已 BI 每日生成的最终数据为准) $brokerStarBrokerStats = Model_Broker_StarIntermediaryScore::findMultiByBrokerIds($brokerIds, date('Y-m-d')); // 拼装返回数据 $result = array(); foreach ($brokerLocations as $brokerLocation) { $row = array(); $row['id'] = $brokerLocation['id']; $row['brokerId'] = $brokerLocation['brokerId']; $row['lat'] = $brokerLocation['lat']; $row['lng'] = $brokerLocation['lng']; $row['updateTime'] = $brokerLocation['updateTime']; // 获取经纪人状态:活跃 or 非活跃(ajk_brokerextend.BrokerLevel = 'K' 为 活跃经纪人) $row['isActive'] = intval(isset($brokerLevels[$row['brokerId']]) && $brokerLevels[$row['brokerId']] == 'K'); // 微聊达人 $isChatTalent = -1; // 默认,微聊达人活动未开始或已结束 if (Bll_Broker_CallAnalysis::isTalentEventOngoing()) { $isChatTalent = 0; // 活动中,默认不是微聊达人 if (isset($brokerChatStats[$row['brokerId']])) { $isChatTalent = $brokerChatStats[$row['brokerId']]['isTalent']; } } $row['isChatTalent'] = $isChatTalent; // 明星中介 $isStarBroker = 0; if (isset($brokerStarBrokerStats[$row['brokerId']])) { $isStarBroker = $brokerStarBrokerStats[$row['brokerId']]['isMingxing']; } $row['isStarBroker'] = $isStarBroker; $result[] = $row; } $cache->set($key, $result, 0, 900); } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $result); }
public function __construct() { $this->apf = APF::get_instance(); $this->request = $this->apf->get_request(); $this->response = $this->apf->get_response(); $this->cache = APF_Cache_Factory::get_instance()->get_memcache(); $this->config = $this->apf->get_config(null, 'weiliao'); }
/** * 从缓存获取激活公司数 * @return array|int|string */ public static function getCompanyNumWithCache() { $key = __CLASS__ . __METHOD__; $objMem = APF_Cache_Factory::get_instance()->get_memcache(); if (!($result = $objMem->get($key))) { $result = self::getCompanyNum(); $objMem->set($key, $result, 0, self::$cacheExpire); } return $result; }
public static function getCityDistricts($cityId) { $key = Util_MemCacheKey::getCityDistrictsKey($cityId); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $info = $memcache->get($key); if ($info === false) { $info = self::data_access()->filter(self::CITY_ID, $cityId)->filter(self::IS_ACTIVED, 1)->sort(self::DISPLAY_ORDER, 'asc')->get_all(); $memcache->set($key, $info, 0, 86400); } return $info; }
public function ajk_community_info($commid) { $key = "Dao_Comm_AjkCommunity_ajk_community_info_infos{$commid}"; $functionName = 'ajk_community_info'; APF::get_instance()->benchmark_begin(__CLASS__ . $functionName); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $info = $memcache->get($key); if (!$info) { $commmap = array(); $info = array(); // 小区开展信息 $info['commextend'] = $this->get_commextinfo_by_commid($commid); $i = 0; while ($info['commextend']['ismerge'] == 1) { // 是否合并小区 $commid = self::get_from_commid($commid); if (empty($commid)) { return array(); } // 小区开展信息 $info['commextend'] = $this->get_commextinfo_by_commid($commid); if ($i > 2) { break; } $i++; } // 小区基本信息 $info['community'] = $this->get_community_info_byid($commid); if (!$info['community']) { return array(); } // 小区地图信息,先从map_communities_baidu,没有的话从ajk_communitys取 $commmap = $this->get_comm_latlng_by_commid($commid); if ($commmap) { if ($commmap['lat'] && $commmap['lng'] && $commmap['zoom']) { $info['community']['mapx'] = $commmap['lng']; $info['community']['mapy'] = $commmap['lat']; $info['community']['mapzoom'] = $commmap['zoom']; } } // 区域、板块 $daoArea = new Dao_Area_HzArea(); $areaList = $daoArea->get_areaname_bycode(substr(@$info['community']['AREACODE'], 0, 8)); $blockList = $daoArea->get_areaname_bycode(@$info['community']['AREACODE']); $info['community']['areainfo'] = $areaList; $info['community']['blockinfo'] = $blockList; $info['commid'] = $info['community']['commid']; $memcache->add($key, $info, 0, 28800); //8h } APF::get_instance()->benchmark_end(__CLASS__ . $functionName); return $info; }
/** * 获取经纪人返现记录 * * @param int $cityId * @param int $brokerId * @return array */ public static function getBrokerChoiceConsumeCashBackLog($cityId, $brokerId) { $cacheKey = sprintf('ajk_broker_choice_consume_cash_back_log_%d_%d', $cityId, $brokerId); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $brokerConsumeCashBackLog = $memcache->get($cacheKey); if (is_array($brokerConsumeCashBackLog) && !empty($brokerConsumeCashBackLog)) { return $brokerConsumeCashBackLog; } $brokerConsumeCashBackLog = Model_Choice_AjkBrokerChoiceConsumeCashBackLog::getBrokerChoiceConsumeCashBackLog($cityId, $brokerId); $memcache->set($cacheKey, $brokerConsumeCashBackLog, 0, 1800); return $brokerConsumeCashBackLog; }
public function handle_request() { $memCache = APF_Cache_Factory::get_instance()->get_memcache(); $key = self::KEY_PRICE_INTERVAL; $cache = $memCache->get($key); if (empty($cache)) { echo "缓存不存在"; exit; } if ($memCache->delete($key)) { echo "删除缓存成功"; } else { echo "删除缓存失败,或者已经删除,请手动删除缓存,地址为/tools/memcache/,KEY为 price_interval"; } }
public function handle_request() { $memCache = APF_Cache_Factory::get_instance()->get_memcache(); $key = 'anjuke_ppc_coin_city_v2_11'; $cache = $memCache->get($key); if (empty($cache)) { echo "缓存不存在"; exit; } if ($memCache->delete($key)) { echo "删除缓存成功"; } else { echo "删除缓存失败,或者已经删除,请手动删除缓存,地址为/tools/memcache/,KEY为 anjuke_ppc_coin_city_v2_11"; } }
/** * 查询账户关系表(支持缓存) * @param $accountId * @param string $site */ public static function getAccountMapping($accountId, $site = '', $isCache = true) { $data = array(); if ($isCache) { $strCacheKey = 'ballance_log_job_accountid_new_' . $accountId . '_site_' . $site; $objMem = APF_Cache_Factory::get_instance()->get_memcache(); $data = $objMem->get($strCacheKey); } if (!$data) { $data = Model_Payment_AccountMapping::getAccountMapping($accountId, $site); if ($isCache && $data) { $objMem->set($strCacheKey, $data, 0, 86400); } } return $data; }
public function handle_request_internal() { $userId = $this->_params['userId']; $brokerId = $this->_params['brokerId']; $cityId = $this->_params['cityId']; //查询用户是否存在fyk_users表 $userInfo = Bll_Fyk_User_User::getInstance()->getUsersByUserId($userId); if (empty($userInfo)) { //不存在则报错 return array('status' => 'error', 'errcode' => Const_APIStatus::E_FYK_USER_NO_ACCESS, 'message' => '该用户无房源库使用资格'); } else { //判断用户是否未激活 $isInIt = $this->_isUserInIt($userInfo); if ($isInIt === false) { //该用户已激活,返回错误信息 return array('status' => 'error', 'errcode' => Const_APIStatus::E_FYK_USER_ALREADY_ACTIVATE, 'message' => '该用户已报名'); } } //查询缓存获得每日报名上限 $today = intval(date('Ymd', time())); $dayNumCacheKey = $this->_getDayNumCacheKey($cityId, $today); $cache = APF_Cache_Factory::get_instance()->get_memcache(); $dayNum = intval($cache->get($dayNumCacheKey)); if (empty($dayNum) || !is_numeric($dayNum)) { //如果查不到缓存,则查数据库并设置缓存 //获取当先正在进行的活动配置信息 $onActivateConfig = Bll_Fyk_User_User::getInstance()->getOnActivateConfig($cityId); if (empty($onActivateConfig)) { //查询不到活动信息,则报错 return array('status' => 'error', 'errcode' => Const_APIStatus::E_FYK_USER_NO_ACTIVITY, 'message' => '当前无有效活动'); } //缓存每日报名上限 $dayNum = intval($onActivateConfig['dayNum']); $cache->set($dayNumCacheKey, $dayNum, 0, 86400); } $activate = Bll_Fyk_User_User::getInstance()->updateActivateNum($cityId, $today, $dayNum); if ($activate) { //报名成功,激活此用户 $userInfo->status = Model_Fyk_Users::INVITATION; $userInfo->activeTime = date('Y-m-d h:i:s', time()); $userInfo->save(); return array('status' => 'ok', 'message' => '报名成功'); } else { //报名失败 return array('status' => 'error', 'errcode' => Const_APIStatus::E_FYK_USER_ACTIVATE_FAILURE, 'message' => '报名失败'); } }
public function get_inline_styles() { $url = $this->get_boundable_styles_url(); $key = "css-" . md5($url); apf_require_class('APF_Cache_Factory'); $mem = APF_Cache_Factory::get_instance()->get_memcache(); $css = $mem->get($key); if ($css) { return $css; } apf_require_class('APF_Http_Client_Factory'); $c = APF_Http_Client_Factory::get_instance()->get_curl(); $c->set_url($url); $c->execute(); $css = $c->get_response_text(); $mem->set($key, $css, 0, 0); return $css; }
public function getWtfWords() { if (isset(self::$arrWtfWords)) { return self::$arrWtfWords; } $objMem = APF_Cache_Factory::get_instance()->get_memcache(); $arrWtfWordsFinal = $objMem->get(self::KEY_WTF_WORDS); if (!$arrWtfWordsFinal) { $objDa = Model_Bbs_BanWords::data_access(); $arrWtfWords = $objDa->load_field(Model_Bbs_BanWords::WORD)->find(); $arrWtfWordsFinal = array(); foreach ($arrWtfWords as $keyAWWord => $valAWWord) { $arrWtfWordsFinal[] = '/' . str_replace('/', '\\/', $valAWWord->word) . '/i'; } $objMem->set(self::KEY_WTF_WORDS, $arrWtfWordsFinal, false, self::TIME_WTF_WORDS); } self::$arrWtfWords = $arrWtfWordsFinal; return $arrWtfWordsFinal; }
/** * 查询经纪人新封顶模式可用套餐列表 * @param $brokerId * @param $bizType * @param $isCache * @return bool|mixed */ public static function getPpcBrokerLimitTempList($brokerId, $bizType = self::PPC_BROKER_LIMIT_ESF_SITE, $isCache = false) { $params = array('brokerId' => $brokerId, 'bizType' => $bizType); $cache = APF_Cache_Factory::get_instance()->get_memcache(); $key = __CLASS__ . __FUNCTION__ . $brokerId . '_' . $bizType; if ($result = $cache->get($key)) { if ($result['expireTime'] > time() && $isCache) { return $result; } } $apiInfo = Uri_BrokerApi::getPpcBrokerLimitTempList($params); if (isset($apiInfo['status']) && $apiInfo['status'] == 'ok') { $result = $apiInfo['data']; $result['expireTime'] = strtotime(date('Y-m-d 00:00:00', strtotime('+1 day'))); $cache->set($key, $result); return $result; } return false; }
/** * 查询经纪人新封顶模式信息 * @param $brokerId * @param $bizType * @return bool|mixed */ public static function getPpcBrokerLimitInfo($brokerId, $bizType = self::PPC_BROKER_LIMIT_HZ_SITE) { $cache = APF_Cache_Factory::get_instance()->get_memcache(); $key = __CLASS__ . __FUNCTION__ . $brokerId . '_' . $bizType; if ($result = $cache->get($key)) { if ($result['expireTime'] > time()) { return $result; } } $host = APF::get_instance()->get_config("JavaAPIHost"); $url = $host . "service-internal/rest/broker/showBrokerLimitConfig?json&brokerId={$brokerId}&bizType={$bizType}"; $apiInfo = Util_Curl::service_curl($url); if (isset($apiInfo['status']) && $apiInfo['status'] == 'ok') { $result = $apiInfo['data']; $result['expireTime'] = strtotime(date('Y-m-d 00:00:00', strtotime('+1 day'))); $cache->set($key, $result); return $result; } return false; }
/** * 获取价格区间的定价价格 * * @param int $cityId * @param float $totalMoney * @param int $areaId * @param int $communityId * @return array */ public static function getPriceInterval($cityId, $totalMoney, $areaId = 0, $communityId = 0) { $cityId = intval($cityId); if (empty($cityId) || !isset($totalMoney)) { return array(); } static $priceInterval = array(); if (empty($priceInterval)) { $cache = APF_Cache_Factory::get_instance()->get_memcache(); //实例缓存 $time = Util_MemCacheTime::getPriceInterval(); //缓存有效时间 $key = Util_MemCacheKey::getPriceInterval(); //缓存key $priceIntervalCache = $cache->get($key); if (false === $priceIntervalCache) { $tmpResult = Model_House_EsfPrice::getAllPriceIntervalEx(Model_House_EsfPrice::TRADE_TYPE_SALE); foreach ($tmpResult as $list) { $index = $list['cityId'] . '_' . $list['areaCode'] . '_' . $list['commId']; $priceInterval[$index][] = $list; } $cache->set($key, $priceInterval, 0, $time); } else { $priceInterval = $priceIntervalCache; } } $indexList = array(sprintf('%d_%d_%d', $cityId, $areaId, $communityId), sprintf('%d_%d_%d', $cityId, $areaId, 0), sprintf('%d_%d_%d', $cityId, 0, 0)); foreach ($indexList as $index) { if (!isset($priceInterval[$index])) { continue; } foreach ($priceInterval[$index] as $list) { if ($totalMoney > $list['minPrice'] && $totalMoney <= $list['maxPrice']) { return $list; } } } $errorMsg = sprintf('[%s] %d_%d_%d %d' . PHP_EOL, date('Y-m-d H:i:s'), $cityId, $areaId, $communityId, $totalMoney); file_put_contents('/data1/logs/PriceIntervalErr.log', $errorMsg, FILE_APPEND); return array(); }
public function __construct() { $strKey = 'Util_FilterWords_v2'; $objMemcache = APF_Cache_Factory::get_instance()->get_memcache(); $this->classArr = $objMemcache->get($strKey); if (empty($this->classArr)) { // 获取词库 $this->wordsArr = $this->get_keywords(); // 分别对每个关键词进行首字符分析分类 foreach ($this->wordsArr as $v) { $v = trim($v['WORD']); $oneStr = mb_substr($v, 0, 1, 'UTF-8'); if (!isset($this->classArr[$oneStr])) { $this->classArr[$oneStr] = array(); } if (!in_array($v, $this->classArr[$oneStr])) { $this->classArr[$oneStr][] = $v; } } $objMemcache->set($strKey, $this->classArr, 0, 86400 * 30); } }
function url2hash($type, $file, $ext, $redisurl, $onlyhash = false) { $apf = APF::get_instance(); $request = $apf->get_request(); $response = $apf->get_response(); $type_single = self::DEFAULT_RESOURCE_TYPE_SINGLE; $type_boundable = self::DEFAULT_RESOURCE_TYPE_BOUNDABLE; if ($this->is_use_redis()) { apf_require_class('APF_Cache_Factory'); $objRedis = APF_Cache_Factory::get_instance()->get_redis('redis'); $strContentHash = ''; if ($type == $type_boundable) { $res = $this->fetch_boundable_resources($file, $ext, TRUE); if (!$res) { $new_file = $this->try_new_file($file); if ($new_file) { //301 $url = "{$new_file}.{$ext}"; $response->redirect($url, true); } else { //404 $response->set_header("HTTP/1.1", "404 Not Found", "404"); return; } } //if(true===ANJUKE_PHP_IN_GA){ ob_start(); $response->add_header('ori_url', $redisurl . '|' . date('Y-m-d H:i:s')); $hashversion = $apf->get_config('hash_url_version', 'resource'); echo '/*' . $hashversion . '*/'; $this->passthru_boundable_resources(); $res = ob_get_contents(); ob_clean(); $strContentHash = md5($res); $objRedis->setex('url_' . $redisurl, 233280000, $strContentHash); $objRedis->setex('hash_' . $strContentHash, 233280000, $redisurl); if (!$onlyhash) { echo $res; } /*}else{ $this->passthru_boundable_resources(); }*/ } elseif ($type == $type_single) { ob_start(); $response->add_header('ori_url', $redisurl . '|' . date('Y-m-d H:i:s')); $hashversion = $apf->get_config('hash_url_version', 'resource'); echo '/*' . $hashversion . '*/'; if (!$this->include_resource_file("{$file}.{$ext}")) { trigger_error("Unable to include resource \"{$file}.{$ext}\"", E_USER_WARNING); } $res = ob_get_contents(); ob_clean(); $strContentHash = md5($res); $objRedis->setex('url_' . $redisurl, 233280000, $strContentHash); $objRedis->setex('hash_' . $strContentHash, 233280000, $redisurl); if (!$onlyhash) { echo $res; } } return $strContentHash; } else { if ($type == $type_boundable) { $res = $this->fetch_boundable_resources($file, $ext, TRUE); if (!$res) { $new_file = $this->try_new_file($file); if ($new_file) { //301 $url = "{$new_file}.{$ext}"; $response->redirect($url, true); } else { //404 $response->set_header("HTTP/1.1", "404 Not Found", "404"); return; } } $this->passthru_boundable_resources(); } elseif ($type == $type_single) { if (!$this->include_resource_file("{$file}.{$ext}")) { trigger_error("Unable to include resource \"{$file}.{$ext}\"", E_USER_WARNING); } } } }
public function get_friendinviteview($cityid, $html_id) { APF::get_instance()->benchmark_begin(__CLASS__ . " get_friendinviteview "); $key = Util_MemCacheKey::get_myanjuke_friendinviteview($cityid); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $list = $memcache->get($key); // $memcache->delete($key); if (!$list) { $list = parent::get_html_content($cityid, $html_id, $key); $memcache->add($key, $list, 0, Util_MemCacheTime::get_myanjuke_friendinviteview()); } APF::get_instance()->benchmark_end(__CLASS__ . " get_friendinviteview "); return $list; }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $maxId = isset($this->_params['maxId']) ? $this->_params['maxId'] : null; $sinceId = isset($this->_params['sinceId']) ? $this->_params['sinceId'] : null; $per = isset($this->_params['per']) ? $this->_params['per'] : 20; $per = $per + 1; //判断是否有下一页 $moreFlag = 1; $allData = array(); $cacheCursorKey = md5($brokerId . 'commission'); //游标key $cacheCommissionKey = md5($cacheCursorKey . $brokerId); //commissionInfo key $cache = APF_Cache_Factory::get_instance()->get_memcache(); $cacheCursor = $cache->get($cacheCursorKey); $maxCommissionInfo = Model_House_Commission::data_access()->filter('brokerId', $brokerId)->filter('isDelete', Model_House_Commission::DELETE_NO)->sort('id', 'desc')->limit(1)->find_only(); if ($maxCommissionInfo['id'] == $cacheCursor) { //没新数据则读缓存 $allData = $cache->get($cacheCommissionKey); } elseif (!empty($maxCommissionInfo)) { //如果有新数据 // 获取经纪人的所有委托 $daCommissions = Model_House_Commission::data_access()->filter('brokerId', $brokerId)->filter('isDelete', Model_House_Commission::DELETE_NO)->sort('id', 'desc'); $commissions = $daCommissions->find_all(); // 获取委托关联的房源 $houses = array(); if (!empty($commissions)) { $houseIds = array(); foreach ($commissions as $commission) { $houseIds[] = $commission->houseId; $brokerHouseIds[] = $commission->brokerHouseId; } // 获取房源信息 $houses = Model_House_CommissionHouse::data_access()->filter('id', $houseIds)->sort('id', 'asc')->find_all(); // 索引 $indexedHouses = array(); foreach ($houses as $house) { $indexedHouses[$house['id']] = $house; } $houses = $indexedHouses; // 是否存在实拍图片 $imagesInfos = Model_Image_SaleEntrustImage::getImagesByProIds($houseIds); $isImages = array(); foreach ($imagesInfos as $imagesInfo) { $isImages[$imagesInfo->proId] = 1; } $BrokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($brokerId); //房源推广状态(定价&套餐) $isOnLine = Bll_House_EsfHouse::getHouseOnLineInfo($BrokerInfo['BaseInfo']['CITYID'], $brokerId, $brokerHouseIds); } $houseAction = array(); //可操作房源 $houseUnAction = array(); //不可操作房源 foreach ($commissions as $commission) { if (!isset($houses[$commission['houseId']])) { continue; } $house = $houses[$commission['houseId']]; $row = array(); $row['id'] = $commission['id']; $row['propertyId'] = $house['id']; $row['commName'] = $house['commName']; $row['type'] = $house['commissionType']; $row['room'] = $house['roomNum']; $row['hall'] = $house['hallNum']; $row['toilet'] = $house['toiletNum']; $row['area'] = $house['areaNum']; $row['price'] = $house['proPrice']; switch ($house['commissionType']) { case Model_House_CommissionHouse::COMMISSION_TYPE_RENT: $row['priceUnit'] = '元/月'; break; case Model_House_CommissionHouse::COMMISSION_TYPE_SALE: $row['priceUnit'] = '万元'; break; } $row['publishTime'] = date('Y-m-d H:i:s', $house['created']); $row['status'] = $house['proStatus']; $row['statusInfo'] = $this->statusMapping[$house['proStatus']]; $row['ownerName'] = $house['userName']; $row['ownerPhone'] = $house->getPhone(); $row['callable'] = intval($house['proStatus'] == Model_House_CommissionHouse::STATUS_ONGOING); $row['isRealityPats'] = $isImages[$house['id']] ? 1 : 0; $row['timestate'] = Bll_Common_Format::formatTime($house['created']); list($isExtension, $isExtensionInfo) = $this->isExtension($commission, $isOnLine, $house); if ($isExtension == 5 || $isExtension == 6) { $row['isExtension'] = 7; } else { $row['isExtension'] = $isExtension; } $row['isExtensionInfo'] = $isExtensionInfo; //1-违规已删除 2-已过期 5-待发布 6-待推广 7-已推广 8-房东删除 if (in_array($isExtension, array(1, 2, 8))) { //不可操作房源 $houseUnAction[] = $row; } else { $houseAction[] = $row; } } $cacheCursorValue = $houseAction[0]['id'] > $houseUnAction[0]['id'] ? $houseAction[0]['id'] : $houseUnAction[0]['id']; $cache->set($cacheCursorKey, $cacheCursorValue, 0, 10); $allData = array_merge($houseAction, $houseUnAction); $cache->set($cacheCommissionKey, $allData, 0, 10); } $data = array(); if ($allData) { $countAllCommissions = count($allData); $segmentation = array(); //供分页用 foreach ($allData as $value) { $segmentation[] = $value['id']; } /** * 以下是分页处理代码 略坑,勿踩 * add by xiongjianxu */ if (isset($maxId)) { $max = array(); $max = array_keys($segmentation, $maxId); if (!empty($max)) { $offset = $countAllCommissions - $max[0]; krsort($allData); $data = array_slice($allData, $offset, $per, false); } } elseif (isset($sinceId)) { $since = array(); $since = array_keys($segmentation, $sinceId); if (!empty($since)) { $offset = $since[0] + 1; $data = array_slice($allData, $offset, $per, false); } } else { // maxId和sinceId均不存在时,返回当前最新的记录 $data = array_slice($allData, 0, $per, false); } //判断有无下一页 $countCommissions = count($data); if ($countCommissions < $per) { $moreFlag = 0; } else { unset($data[$countCommissions - 1]); } } else { $moreFlag = 0; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data, 'nextPage' => $moreFlag); }
/** * * @return APF_Cache_Memcache */ protected function get_cache() { return APF_Cache_Factory::get_instance()->get_memcache(); }
/** * 更新房源小区缓存 * * @param array $list 房源信息 * @param int $tradetype * @param int $prop_type 待上架/普通/推荐 * @param int $brokerid */ private function update_cached_prop_communitys($list, $tradetype, $prop_type, $brokerid) { if ($tradetype == 1 && $prop_type == 0) { //出售待上架 $index = Const_My::KEY_UnSale_Comm; } elseif ($tradetype == 1 && $prop_type == 1) { //出售普通房源 $index = Const_My::KEY_OnSale_Normal_Comm; } elseif ($tradetype == 1 && $prop_type == 2) { //出售推荐房源 $index = Const_My::KEY_OnSale_Recommend_Comm; } elseif ($tradetype == 2 && $prop_type == 0) { //出租待上架 $index = Const_My::KEY_UnRent_Comm; } elseif ($tradetype == 2 && $prop_type == 1) { //出租普通房源 $index = Const_My::KEY_OnRent_Normal_Comm; } elseif ($tradetype == 2 && $prop_type == 2) { //出租推荐房源 $index = Const_My::KEY_onRent_Recommend_Comm; } //获取memcache $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $key = Util_MemCacheKey::get_propmanagement_commids($brokerid); $time = Util_MemCacheTime::get_propmanagement_commids(); $communitys_list = $memcache->get($key); if (is_array($communitys_list[$index])) { foreach ($list as $prop) { if (!array_key_exists($prop["CommId"], $communitys_list[$index])) { $communitys_list[$index][$prop["CommId"]]++; } } } //更新cache $memcache->set($key, $communitys_list, 0, $time); }
/** * 使用 Memcache 来过滤经纪人短时间内的重复提交设计精选 * 根据经纪人ID和房源ID 到memcache里获取key是否存在,存在即 该次请求无效,程序可以不处理该次请求 返回值为 false * key 不存则 add 一个值为1 过期时间为2秒的缓存到 memcache ,add 失败则返回 false 成功 返回 true. * * @param $siteType * @param $brokerId * @param $houseId * @return bool */ public static function rejectSameRequest($siteType, $brokerId, $houseId) { $key = Util_MemCacheKey::getChoiceRequestKey($siteType, $brokerId, $houseId); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); if (!$memcache) { return true; } $keyExists = $memcache->get($key); if ($keyExists === false) { $memcache->add($key, 1, false, Bll_Plan_Bid_Choice::REJECT_SAME_REQUEST_TIME_OUT); return true; } return false; }
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; }
/** * Redis连接 * * @param string $configName * @return APF_Cache_Redis */ private function initRedis($configName) { $this->redis = APF_Cache_Factory::get_instance()->get_redis($configName); }
protected function cache_delete() { APF::get_instance()->debug("delete row cache"); $cache = APF_Cache_Factory::get_instance()->get_memcache(); $cache->delete($cache->get_obj_key(get_called_class(), $this->get_primary_key())); }