Authored by hf

modify guang page add data cache to fixes api down

... ... @@ -38,4 +38,7 @@ class CacheConfig
const KEY_ACTION_SEARCH_SEARCH = 'key_action_search_search'; // 搜索的数据
const KEY_ACTION_SEARCH_FILTER = 'key_action_search_filter'; // 搜索的过滤条件
const KEY_ACTION_GUANG_PLUSTAR_DATA = 'key_action_guang_plustar_data'; // 逛PLUSTAR
const KEY_ACTION_GUANG_DETAIL_DATA = 'key_action_guang_detail_data'; // 逛内容详情
}
... ...
... ... @@ -3,6 +3,7 @@
namespace LibModels\Wap\Guang;
use Api\Yohobuy;
use Configs\CacheConfig;
/**
* 逛资讯详情相关的数据模型
... ... @@ -37,10 +38,18 @@ class DetailData
// 客户端类型
$clientType = $isApp ? 'iphone' : 'h5';
$key = CacheConfig::KEY_ACTION_GUANG_DETAIL_DATA . strval($id);
// 获取资讯
$article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticle', array($id, $clientType));
if (!isset($article['author_id'])) {
if (USE_CACHE) {
// 先尝试获取二级缓存(slave), 有数据则直接返回.
$result = Cache::get($key, 'slave');
if (!empty($result)) {
return $result;
}
}
return $result;
}
$result['getArticle'] = $article;
... ... @@ -70,6 +79,10 @@ class DetailData
// 调用发起请求
Yohobuy::yarConcurrentLoop();
if (USE_CACHE && !empty($result['getArticle'])) {
Cache::set($key, $result);
}
return $result;
}
... ... @@ -115,5 +128,4 @@ class DetailData
return $result;
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace LibModels\Wap\Guang;
use Api\Sign;
use Api\Yohobuy;
use Plugin\Helpers;
use Configs\CacheConfig;
/**
* 明星品牌和原创品牌相关的数据模型
... ... @@ -124,9 +125,18 @@ class PlusstarData
$result['getUidProductFav'] = array();
$result['getArticleByBrand'] = array();
$key = CacheConfig::KEY_ACTION_GUANG_PLUSTAR_DATA . strval($id);
// 品牌详情信息
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)), 3600); // 缓存1小时
if (!isset($brandInfo['data']['brand_id'])) {
if (USE_CACHE) {
// 先尝试获取二级缓存(slave), 有数据则直接返回.
$result = Cache::get($key, 'slave');
if (!empty($result)) {
return $result;
}
}
return $result;
} else {
$result['getBrandInfo'] = $brandInfo;
... ... @@ -196,10 +206,12 @@ class PlusstarData
// 调用发起请求
Yohobuy::yarConcurrentLoop();
return $result;
if (USE_CACHE && !empty($result['getBrandInfo'])) {
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
Cache::set($key, $result);
}
// $goods_url = MakeUrl::h5ProductDetailUrl($baseUrl,$new_goods_info['product_id'],$new_goods_info['goods_list'][0]['goods_id'],$new_goods_info['cn_alphabet']);
// $url = MakeUrl::makeUrl('go.productDetail',$goods_url, array('product_skn'=>$new_goods_info['product_skn']),$client_type);
return $result;
}
}
... ...
... ... @@ -36,7 +36,7 @@ class RecomData
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
return Yohobuy::get(Yohobuy::API_URL, $param, 3600);
}
/**
... ... @@ -55,7 +55,7 @@ class RecomData
$param['yh_channel'] = '3';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
return Yohobuy::get(Yohobuy::API_URL, $param, 3600);
}
/**
... ...