|
@@ -20,6 +20,7 @@ use LibModels\Wap\Product\SearchData; |
|
@@ -20,6 +20,7 @@ use LibModels\Wap\Product\SearchData; |
20
|
*/
|
20
|
*/
|
21
|
class PlusstarData
|
21
|
class PlusstarData
|
22
|
{
|
22
|
{
|
|
|
23
|
+
|
23
|
const URI_BRANDLIST = 'guang/api/v1/plustar/getlist';
|
24
|
const URI_BRANDLIST = 'guang/api/v1/plustar/getlist';
|
24
|
const URI_BRANDINFO_PLUSSTAR = 'guang/service/v1/plustar/';
|
25
|
const URI_BRANDINFO_PLUSSTAR = 'guang/service/v1/plustar/';
|
25
|
const URI_BRANDINFO_FAVORITE = 'shops/service/v1/favorite/';
|
26
|
const URI_BRANDINFO_FAVORITE = 'shops/service/v1/favorite/';
|
|
@@ -126,30 +127,34 @@ class PlusstarData |
|
@@ -126,30 +127,34 @@ class PlusstarData |
126
|
$result['getUidProductFav'] = array();
|
127
|
$result['getUidProductFav'] = array();
|
127
|
$result['getArticleByBrand'] = array();
|
128
|
$result['getArticleByBrand'] = array();
|
128
|
|
129
|
|
129
|
- $key = CacheConfig::KEY_ACTION_GUANG_PLUSTAR_DATA . strval($id);
|
130
|
+ // 客户端类型
|
|
|
131
|
+ $clientType = $isApp ? 'iphone' : 'h5';
|
|
|
132
|
+ $key = CacheConfig::KEY_ACTION_GUANG_PLUSTAR_DATA . strval($id) . $clientType;
|
|
|
133
|
+
|
|
|
134
|
+ if (USE_CACHE) {
|
|
|
135
|
+ // 先尝试获取二级缓存(slave), 有数据则直接返回.
|
|
|
136
|
+ $cached = Cache::get($key, 'master');
|
|
|
137
|
+ if (!empty($cached)) {
|
|
|
138
|
+ return $cached;
|
|
|
139
|
+ }
|
|
|
140
|
+ }
|
|
|
141
|
+ return $result;
|
130
|
|
142
|
|
131
|
// 品牌详情信息
|
143
|
// 品牌详情信息
|
132
|
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)), 3600); // 缓存1小时
|
144
|
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)), 3600); // 缓存1小时
|
133
|
if (!isset($brandInfo['data']['brand_id'])) {
|
145
|
if (!isset($brandInfo['data']['brand_id'])) {
|
134
|
- if (USE_CACHE) {
|
|
|
135
|
- // 先尝试获取二级缓存(slave), 有数据则直接返回.
|
|
|
136
|
- $result = Cache::get($key, 'slave');
|
|
|
137
|
- if (!empty($result)) {
|
|
|
138
|
- return $result;
|
|
|
139
|
- }
|
|
|
140
|
- }
|
|
|
141
|
return $result;
|
146
|
return $result;
|
142
|
} else {
|
147
|
} else {
|
143
|
$result['getBrandInfo'] = $brandInfo;
|
148
|
$result['getBrandInfo'] = $brandInfo;
|
144
|
}
|
149
|
}
|
145
|
|
150
|
|
146
|
- // 是否收藏店铺
|
|
|
147
|
- $isUidOk = $uid && is_numeric($uid);
|
|
|
148
|
- if ($isUidOk) {
|
|
|
149
|
- Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidBrandFav', array($uid, $brandInfo['data']['brand_id']), function($retval) use(&$result) {
|
|
|
150
|
- $result['getUidBrandFav'] = (isset($retval['message']) && $retval['message'] == 'favorite') ? true : false;
|
|
|
151
|
- });
|
|
|
152
|
- }
|
151
|
+// // 是否收藏店铺
|
|
|
152
|
+// $isUidOk = $uid && is_numeric($uid);
|
|
|
153
|
+// if ($isUidOk) {
|
|
|
154
|
+// Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidBrandFav', array($uid, $brandInfo['data']['brand_id']), function($retval) use(&$result) {
|
|
|
155
|
+// $result['getUidBrandFav'] = (isset($retval['message']) && $retval['message'] == 'favorite') ? true : false;
|
|
|
156
|
+// });
|
|
|
157
|
+// }
|
153
|
|
158
|
|
154
|
// 相关资讯列表 (3篇)
|
159
|
// 相关资讯列表 (3篇)
|
155
|
$result['getArticleByBrand'] = array();
|
160
|
$result['getArticleByBrand'] = array();
|
|
@@ -179,7 +184,7 @@ class PlusstarData |
|
@@ -179,7 +184,7 @@ class PlusstarData |
179
|
$condition['limit'] = 6;
|
184
|
$condition['limit'] = 6;
|
180
|
$condition['order'] = 's_t_desc';
|
185
|
$condition['order'] = 's_t_desc';
|
181
|
$newProduct = SearchData::searchElasticByCondition($condition, 1800); // 有缓存30分钟
|
186
|
$newProduct = SearchData::searchElasticByCondition($condition, 1800); // 有缓存30分钟
|
182
|
-
|
187
|
+
|
183
|
if (empty($newProduct['data']['product_list'])) {
|
188
|
if (empty($newProduct['data']['product_list'])) {
|
184
|
break;
|
189
|
break;
|
185
|
}
|
190
|
}
|
|
@@ -202,11 +207,11 @@ class PlusstarData |
|
@@ -202,11 +207,11 @@ class PlusstarData |
202
|
// 用户是否收藏该商品
|
207
|
// 用户是否收藏该商品
|
203
|
$skn = $value['product_skn'];
|
208
|
$skn = $value['product_skn'];
|
204
|
$result['getUidProductFav'][$skn] = false;
|
209
|
$result['getUidProductFav'][$skn] = false;
|
205
|
- if ($isUidOk) {
|
|
|
206
|
- Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidProductFav', array($uid, $value['product_skn']), function($retval) use(&$result, &$skn) {
|
|
|
207
|
- $result['getUidProductFav'][$skn] = empty($retval['data']) ? false : $retval['data'];
|
|
|
208
|
- });
|
|
|
209
|
- }
|
210
|
+// if ($isUidOk) {
|
|
|
211
|
+// Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidProductFav', array($uid, $value['product_skn']), function($retval) use(&$result, &$skn) {
|
|
|
212
|
+// $result['getUidProductFav'][$skn] = empty($retval['data']) ? false : $retval['data'];
|
|
|
213
|
+// });
|
|
|
214
|
+// }
|
210
|
|
215
|
|
211
|
$i ++;
|
216
|
$i ++;
|
212
|
}
|
217
|
}
|
|
@@ -215,11 +220,16 @@ class PlusstarData |
|
@@ -215,11 +220,16 @@ class PlusstarData |
215
|
// 调用发起请求
|
220
|
// 调用发起请求
|
216
|
Yohobuy::yarConcurrentLoop();
|
221
|
Yohobuy::yarConcurrentLoop();
|
217
|
|
222
|
|
218
|
- if (USE_CACHE && !empty($result['getBrandInfo'])) {
|
223
|
+ if (USE_CACHE) {
|
|
|
224
|
+ // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
|
|
|
225
|
+ if (empty($result)) {
|
|
|
226
|
+ $result = Cache::get($key, 'slave');
|
|
|
227
|
+ }
|
219
|
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
|
228
|
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
|
220
|
- Cache::set($key, $result);
|
229
|
+ elseif (!empty($result['getBrandInfo'])) {
|
|
|
230
|
+ Cache::set($key, $result);
|
|
|
231
|
+ }
|
221
|
}
|
232
|
}
|
222
|
-
|
|
|
223
|
return $result;
|
233
|
return $result;
|
224
|
}
|
234
|
}
|
225
|
|
235
|
|