/** * 获取周边板块公共委托房源列表 * @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; }
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; }
/** * 获取价格区间的定价价格 * * @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 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; }
/** * 更新房源小区缓存 * * @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 get_userinf_byusername($username) { if (!$username) { return false; } $key = Util_MemCacheKey::get_userinf_byusername($username); APF::get_instance()->benchmark_begin(__CLASS__ . " get_userinf_byusername "); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $list = $memcache->get($key); if (!$list) { $time = Util_MemCacheTime::get_userinf_byusername(); $list = parent::get_userinf_byusername($username); $memcache->add($key, $list, 0, $time); } APF::get_instance()->benchmark_end(__CLASS__ . " get_userinf_byusername "); return $list; }
/** * * 获取套餐点击量(人/天) * 备注: * 1.最多获取30天数据 * 2.当天数据为准实时 * 3.数据最早为半年前 * * @param $brokerId 二手房经纪人id * @param $starDate 2014-08-08 * @param $endDate 2014-08-18 * @param $siteType 网站类型 * @return array|string * [id] => 53 * [brokerId] => 147536 * [siteType] => 1 * [date] => 20140814 * [cnum] => 10 * [icnum] => 0 */ public static function getBrokerComboClick($brokerId, $startDate, $endDate, $siteType, $boolCache = true) { /**数据初始化,时间转时间戳处理*/ $startDate = strtotime($startDate); //开始时间 $endDate = strtotime($endDate); //结束时间 $nowDate = time(); //当前时间 /**参数判断*/ //开始时间不能大于当前时间 if ($startDate > $nowDate) { return false; } //只提供半年后的数据 if ($startDate < $nowDate - 180 * 86400) { return false; } //结束时间大于当前时间,自动赋值为当前时间 if ($endDate > $nowDate) { $endDate = $nowDate; } //只提供30天区间段内的数据 if ($endDate - $startDate > 30 * 86400) { return false; } /** 查询参数生成 */ //cache的key值计算(昨天之前的数据做cache) $keyDate = ''; if ($endDate <= $nowDate - 86400) { $keyDate = date('Y.m.d', $startDate) . "-" . date('Y.m.d', $endDate); } else { $keyDate = date('Y.m.d', $startDate) . "-" . date('Y.m.d', $endDate - 86400); } //根据时间段计算落入的分表(按月分的表) $nowDateArr = array(); //二位数组 $otherDateArr = array(); //三维数据 $tmpOtherDateArr = array(); //临时存储 $tmpCalDate = $endDate; do { //参数初始化 $formatDayTmpCalDate = date('Ymd', $tmpCalDate); $formatDayNowDate = date('Ymd', $nowDate); $formatMonthTmpCalDate = date('Ym', $tmpCalDate); $formatMonthNowDate = date('Ym', $nowDate); if ($formatDayTmpCalDate == $formatDayNowDate) { $nowDateArr['tableDate'] = $formatMonthTmpCalDate; $nowDateArr['date'][] = $formatDayTmpCalDate; } else { if (isset($tmpOtherDateArr['tableDate']) && $tmpOtherDateArr['tableDate'] == $formatMonthTmpCalDate) { $tmpOtherDateArr['date'][] = $formatDayTmpCalDate; } else { if (!empty($tmpOtherDateArr)) { //数据压入 $otherDateArr[] = $tmpOtherDateArr; $tmpOtherDateArr = array(); } $tmpOtherDateArr['date'][] = $formatDayTmpCalDate; $tmpOtherDateArr['tableDate'] = $formatMonthTmpCalDate; } } $tmpCalDate -= 86400; //时间到了,跳出循环 if ($tmpCalDate < $startDate) { //数据压入 $otherDateArr[] = $tmpOtherDateArr; break; } } while (true); /** 查询其他天的数据 */ //cache取数据 $otherDateValue = array(); if ($boolCache) { $key = Util_MemCacheKey::get_broker_combo_click($brokerId, $keyDate . "_" . $siteType); $time = Util_MemCacheTime::get_broker_combo_click(); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $tmpValue = $memcache->get($key); if (!empty($tmpValue)) { $otherDateValue = $tmpValue; } } if (empty($otherDateValue)) { //到数据库查询 foreach ($otherDateArr as $list) { //查询当天的数据 $tmpOtherDateValue = Model_Ppc_NewPackageStatsBrokerDay::getComboClickInfoBydates($brokerId, $list['date'], $siteType, $list['tableDate']); foreach ($tmpOtherDateValue as $value) { $otherDateValue[$value['date']] = $value; } } //压入cache if ($boolCache) { $memcache->set($key, $otherDateValue, 0, $time); } } //查询当天的数据 $nowDateValue = array(); if (!empty($nowDateArr['date'])) { $nowDateValue = Model_Ppc_NewPackageStatsBrokerDay::getComboClickInfoBydates($brokerId, $nowDateArr['date'], $siteType, $nowDateArr['tableDate']); foreach ($nowDateValue as $value) { $otherDateValue[$value['date']] = $value; } } //数据合并 return $otherDateValue; }
public function get_worker_info($worker_id) { $key = Util_MemCacheKey::get_worker_info($worker_id); APF::get_instance()->benchmark_begin(__CLASS__ . " get_worker_info-{$worker_id}"); $memcache = APF_Cache_Factory::get_instance()->get_memcache(); $value = $memcache->get($key); if (!$value) { $time = Util_MemCacheTime::get_worker_info(); $value = parent::get_worker_info($worker_id); $memcache->add($key, $value, 0, $time); } APF::get_instance()->benchmark_end(__CLASS__ . " get_worker_info-{$worker_id}"); return $value; }