添加有货币页面总部的banner数据
Code Review By Rock Zhang
Showing
3 changed files
with
45 additions
and
0 deletions
@@ -58,4 +58,6 @@ class CacheConfig | @@ -58,4 +58,6 @@ class CacheConfig | ||
58 | 58 | ||
59 | const KEY_INDEX_BRANDS_LIST_DATA = 'key_index_brands_list_data';//频道brands数据 | 59 | const KEY_INDEX_BRANDS_LIST_DATA = 'key_index_brands_list_data';//频道brands数据 |
60 | 60 | ||
61 | + const KEY_CODE_YOHOCOIN_BANNER = 'key_code_yohocoin_banner';// 有货币banner数据 | ||
62 | + | ||
61 | } | 63 | } |
@@ -261,6 +261,8 @@ class HomeController extends AbstractAction | @@ -261,6 +261,8 @@ class HomeController extends AbstractAction | ||
261 | $this->setNavHeader('YOHO币', true, false); | 261 | $this->setNavHeader('YOHO币', true, false); |
262 | 262 | ||
263 | $currency = UserModel::getYohoCoinData($this->_uid); | 263 | $currency = UserModel::getYohoCoinData($this->_uid); |
264 | + // banenr数据 | ||
265 | + $currency['banner'] = UserModel::getYohoCoinBanner(); | ||
264 | $currency['pageFooter'] = true; | 266 | $currency['pageFooter'] = true; |
265 | 267 | ||
266 | $this->_view->display('currency', $currency); | 268 | $this->_view->display('currency', $currency); |
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | namespace Index; | 3 | namespace Index; |
4 | 4 | ||
5 | use Configs\CacheConfig; | 5 | use Configs\CacheConfig; |
6 | +use LibModels\Wap\Home\IndexData; | ||
6 | use LibModels\Wap\Home\UserData; | 7 | use LibModels\Wap\Home\UserData; |
7 | use Plugin\Cache; | 8 | use Plugin\Cache; |
8 | use Plugin\Helpers; | 9 | use Plugin\Helpers; |
@@ -18,6 +19,7 @@ use Plugin\Images; | @@ -18,6 +19,7 @@ use Plugin\Images; | ||
18 | */ | 19 | */ |
19 | class UserModel | 20 | class UserModel |
20 | { | 21 | { |
22 | + const CODE_YOHOCOIN_BANNER = 'a2ec977c027d0cd9cdccb356ddf16b08'; | ||
21 | 23 | ||
22 | /** | 24 | /** |
23 | * 处理用户个人详情数据 | 25 | * 处理用户个人详情数据 |
@@ -372,6 +374,45 @@ class UserModel | @@ -372,6 +374,45 @@ class UserModel | ||
372 | return $result; | 374 | return $result; |
373 | } | 375 | } |
374 | 376 | ||
377 | + public static function getYohoCoinBanner() | ||
378 | + { | ||
379 | + $result = false; | ||
380 | + | ||
381 | + if (USE_CACHE) { | ||
382 | + // 先尝试获取一级缓存(master), 有数据则直接返回. | ||
383 | + $result = Cache::get(CacheConfig::KEY_CODE_YOHOCOIN_BANNER, 'master'); | ||
384 | + if (!empty($result)) { | ||
385 | + return $result; | ||
386 | + } | ||
387 | + } | ||
388 | + | ||
389 | + // 调用接口获取数据 | ||
390 | + $banner = IndexData::getBannerStart(self::CODE_YOHOCOIN_BANNER); | ||
391 | + if (isset($banner['code']) && $banner['code'] == 200 && !empty($banner['data'])) { | ||
392 | + $result = array(); | ||
393 | + // 处理数据 | ||
394 | + foreach ($banner['data'] as $val) { | ||
395 | + foreach ($val['data'] as $single) { | ||
396 | + $result['url'] = ''; | ||
397 | + $result['img'] = Helpers::getImageUrl($single['src'], 640, 200); | ||
398 | + } | ||
399 | + } | ||
400 | + } | ||
401 | + | ||
402 | + if (USE_CACHE) { | ||
403 | + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. | ||
404 | + if (empty($result)) { | ||
405 | + $result = Cache::get(CacheConfig::KEY_CODE_YOHOCOIN_BANNER, 'slave'); | ||
406 | + } | ||
407 | + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 | ||
408 | + else { | ||
409 | + Cache::set(CacheConfig::KEY_CODE_YOHOCOIN_BANNER, $result); | ||
410 | + } | ||
411 | + } | ||
412 | + | ||
413 | + return $result; | ||
414 | + } | ||
415 | + | ||
375 | /** | 416 | /** |
376 | * 处理YOHO币变化履历数据 | 417 | * 处理YOHO币变化履历数据 |
377 | * | 418 | * |
-
Please register or login to post a comment