diff --git a/webapp/mt/ShopGoods.php b/webapp/mt/ShopGoods.php index 0679f6f3..df61c50a 100644 --- a/webapp/mt/ShopGoods.php +++ b/webapp/mt/ShopGoods.php @@ -48,6 +48,26 @@ class ShopGoods return getXVal($shopData['goodsHash'], $goodsId, null); } + public static function getRandDailyHeroGoodsIds($shopId, $num) + { + $goodsMetaList = self::getGoodsList($shopId); + $goodsIds = array(); + foreach ($goodsMetaList as $goodsMeta) { + if ($goodsMeta['is_close']) { + continue; + } + array_push($goodsIds, $goodsMeta['goods_id']); + } + shuffle($goodsIds); + $result = array(); + for ($i = 0; $i < $num; ++$i) { + if ($i < count($goodIds)) { + array_push($result, $goodsIds[$i]); + } + } + return $result; + } + protected static function mustBeShopGoodsHash() { if (!self::$shopGoodsHash) { diff --git a/webapp/services/ShopService.php b/webapp/services/ShopService.php index cbe0ac0d..8a299f8a 100644 --- a/webapp/services/ShopService.php +++ b/webapp/services/ShopService.php @@ -165,9 +165,12 @@ class ShopService { return self::$dailyHeroHash[myself()->_getAccountId()]; } $r = myself()->_getSelfRedis(); - $data = $r->get('shop.daily.shop:' . myself()->_getAccountId()); + $key = 'shop.daily.shop:' . myself()->_getAccountId(); + $data = $r->get($key); if (empty($data)) { - + $num = myself()->_callMtStatic('Parameter', 'getByName', 'SHOP_TYPE2_SLOT'); + $data = mt\ShopGoods::getRandDailyHeroGoodsIds(mt\Shop::DAILY_HERO_SHOP, min(50, $num)); + $r->setPx($key, json_encode($data), 1000 * 3600 * 24); } else { $data = json_decode($data, true); }