using System; using System.Collections.Generic; using System.Linq; using cfg.GfgCfg; using ET; namespace GFGGame { public class ShopDataManager : SingletonBase { public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" }; private Dictionary _goodsDic = new Dictionary(); public List GrowthFundRewardList = new List(); public void Clear() { _goodsDic.Clear(); } public void UpdateGoodsData(int giftId, int num) { if (!_goodsDic.ContainsKey(giftId)) { _goodsDic.Add(giftId, num); } else { _goodsDic[giftId] = num; } } /************************************************************************************************************/ public List GetList(int storeId, int typeIndex, int scoreType) { List shopCfgs = null; switch (storeId) { case ConstStoreId.CLOTHING_STORE_ID: shopCfgs = ShopConfigManager.Instance.GetConfigs(ConstStoreTabId.FU_ZHUANG_DIAN, ConstStoreSubId.FU_ZHUANG_DIAN, typeIndex.ToString()); break; case ConstStoreId.GALLERY_STORE_ID: shopCfgs = ShopConfigManager.Instance.GetConfigs(ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_EXCHANGE_GALLERY, typeIndex.ToString()); break; } SortItemListByScore(shopCfgs, scoreType); return shopCfgs; } public void GetMoneyIdAndNum(int buyId, int count, int shopType, out int costId, out int costNum, out int buyNum) { ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(buyId); costId = shopCfg.CostIdReal; costNum = shopCfg.Price * count; buyNum = count; } private List SortItemListByScore(List arrayList, int scoreType) { arrayList.Sort((ShopCfg a, ShopCfg b) => { long numA = ItemDataManager.GetItemNum(a.ItemId); long numB = ItemDataManager.GetItemNum(b.ItemId); bool hasA = numA > 0; bool hasB = numB > 0; if (hasA && !hasB) { return 1; } else if (!hasA && hasB) { return -1; } else if (scoreType > 0 && !hasA && !hasB) { int scoreA = ItemDataManager.GetItemAdditionScore(a.ItemId, scoreType); int scoreB = ItemDataManager.GetItemAdditionScore(b.ItemId, scoreType); if (scoreB > scoreA) { return 1; } else if (scoreB < scoreA) { return -1; } } return a.ItemId.CompareTo(b.ItemId); }); return arrayList; } /**************************************************************************************************************************/ /// /// 根据商品id获取购买次数 /// /// /// public int GetGoodsBuyNumById(int goodsId) { return !_goodsDic.ContainsKey(goodsId) ? 0 : _goodsDic[goodsId]; } //移除未上架商品 public List RemoveNotOpenCfg(List shop) { List shopCfgs = new List(); for (int i = shop.Count - 1; i >= 0; i--) { if (!string.IsNullOrEmpty(shop[i].StartTime) && !TimeUtil.IsBeforeCurTime(shop[i].StartTime) || !string.IsNullOrEmpty(shop[i].EndTime) && !TimeUtil.IsLaterCurTime(shop[i].EndTime)) { continue; } shopCfgs.Add(shop[i]); } return shopCfgs; } //移除原价商品 public List RemoveNotSaleCfg(List shop, List idList) { List shopCfgs = new List(); for (int i = 0; i < idList.Count; i++) { ShopCfg shopcfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(idList[i]); shopCfgs.Add(shopcfg); } return shopCfgs; } //商品排序 public List SortShopGoodsCfgs(List shopCfgs) { shopCfgs.Sort((ShopCfg a, ShopCfg b) => { //未售罄的>已售罄的 int buyTypeA = (a.MaxBuyNum == 0 || a.MaxBuyNum - GetGoodsBuyNumById(a.Id) > 0) ? 1 : -1; int buyTypeB = (b.MaxBuyNum == 0 || b.MaxBuyNum - GetGoodsBuyNumById(b.Id) > 0) ? 1 : -1; if (buyTypeA > buyTypeB) return -1; if (buyTypeA < buyTypeB) return 1; int sortTypeA = a.Sort == 0 ? 999 : a.Sort; int sortTypeB = b.Sort == 0 ? 999 : b.Sort; if (sortTypeA > sortTypeB) return 1; if (sortTypeA < sortTypeB) return -1; return a.Id - b.Id; }); return shopCfgs; } //获取商店所有消耗品id列表 public List GetShopCostIds(List shopCfgs) { List costIds = new List(); for (int i = 0; i < shopCfgs.Count; i++) { if (shopCfgs[i].CostIdReal == 0) continue; if (costIds.IndexOf(shopCfgs[i].CostIdReal) < 0) { costIds.Add(shopCfgs[i].CostIdReal); } } return costIds; } /// /// 根据商品Id获取商品是否已解锁 /// /// /// /// public bool GetShopGoodsStateById(int goodsId) { ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId); if (shopCfg.LockType == LockType.NONE) { return true; } else if (shopCfg.LockType == LockType.STORY_LV) { return InstanceZonesDataManager.CheckLevelPass(shopCfg.LockValue); } else if (shopCfg.LockType == LockType.ROLE_LV) { return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= shopCfg.LockValue; } else if (shopCfg.LockType == LockType.MONTH_CARD_TYPE) { return RoleDataManager.CheckIsMonthCardOpenByType(shopCfg.LockValue); } else if (shopCfg.LockType == LockType.AREND_GRADE) { int lockValue = shopCfg.LockValue; if (shopCfg.Menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.Menu2 != ConstStoreSubId.STORE_ARENA_ITEM && shopCfg.Menu2 < ArenaDataManager.Instance.SeasonId) { bool isDown = ArenaDataManager.Instance.SeasonId - CommonDataManager.Tables.TblGlobalCfg.SeasonReduce > 0; lockValue = isDown ? Math.Max(1, shopCfg.LockValue - CommonDataManager.Tables.TblGlobalCfg.RankReduce) : shopCfg.LockValue; } return ArenaDataManager.Instance.HighestGrade >= lockValue; } return true; } /// /// 根据商品Id获取商品解锁提示 /// /// /// /// public string GetShopGoodsStateTips(int goodsId) { ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId); if (shopCfg.LockType == LockType.STORY_LV) { StoryLevelCfg storyLevelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(shopCfg.LockValue); return string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.ChapterId), storyLevelCfg.Order); } else if (shopCfg.LockType == LockType.ROLE_LV) { return string.Format("角色达到{0}级解锁", shopCfg.LockValue); } else if (shopCfg.LockType == LockType.MONTH_CARD_TYPE) { return string.Format("开通{0}解锁", shopCfg.LockValue == MonthCardType.Gold ? "红包卡" : "福气卡"); } else if (shopCfg.LockType == LockType.AREND_GRADE) { int lockValue = shopCfg.LockValue; if (shopCfg.Menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.Menu2 != ConstStoreSubId.STORE_ARENA_ITEM && shopCfg.Menu2 < ArenaDataManager.Instance.SeasonId) { bool isDown = ArenaDataManager.Instance.SeasonId - CommonDataManager.Tables.TblGlobalCfg.SeasonReduce > 0; lockValue = isDown ? Math.Max(1, shopCfg.LockValue - CommonDataManager.Tables.TblGlobalCfg.RankReduce) : shopCfg.LockValue; } ArenaRankCfg arenaRankCfg = CommonDataManager.Tables.TblArenaRankCfg.GetOrDefault(lockValue); return string.Format("飞花令段位达到{0}解锁", arenaRankCfg.GradeName); } return ""; } /// /// 根据商品id获取下架时间 /// /// /// public string GetEndTime(int goodsId) { long endTime = 0; ShopCfg cfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId); if (cfg.EndTime == "") return ""; endTime = TimeUtil.DateTimeToTimestamp(cfg.EndTime); return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime); } //获取商品折扣百分比 public int GetShopGoodsDiscount(int goodsId) { ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId); if (shopCfg.Price == 0) return 0; return (int)(((double)shopCfg.OriginalPrice / (double)shopCfg.Price) * 100); } // public List SortGiftBagCfgs(List shopCfgs) // { // shopCfgs.Sort((ShopCfg a, ShopCfg b) => // { // //未售罄的>未解锁>已售罄的 // int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1; // int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1; // if (buyTypeA > buyTypeB) return -1; // if (buyTypeA < buyTypeB) return 1; // //解锁状态 // int lockA = GetShopGoodsStateById(a.id) ? 1 : -1; // int lockB = GetShopGoodsStateById(b.id) ? 1 : -1; // if (lockA > lockB) return -1; // if (lockA < lockB) return 1; // //免费>钻石>现金>道具 // if (a.costType < b.costType) return -1; // if (a.costType > b.costType) return 1; // //有下架时间的 > 没有下架时间的 // int endTimeA = a.endTime != "" ? 1 : -1; // int endTimeB = b.endTime != "" ? 1 : -1; // if (endTimeA > endTimeB) return -1; // if (endTimeA < endTimeB) return 1; // //折扣打的>折扣小的 // int disCountA = GetShopGoodsDiscount(a.id); // int disCountB = GetShopGoodsDiscount(b.id); // if (disCountA > disCountB) return -1; // if (disCountA < disCountB) return 1; // //价格低的>价格高的 // if (a.price != b.price) return a.price - b.price; // return 0; // }); // return shopCfgs; // } // private List GetNoneGiftCfg() // { // List giftBagCfgs = new List(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE)); // return giftBagCfgs; // } // private GiftBagCfg GetStoryLvGiftCfg() // { // List giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV); // if (giftBagCfgs.Count == 0) return null; // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) => // { // if (a.storyLevelId.CompareTo(b.storyLevelId) != 0) // { // return a.storyLevelId.CompareTo(b.storyLevelId); // } // return -1; // }); // for (int i = 0; i < giftBagCfgs.Count; i++) // { // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i]; // } // return giftBagCfgs[0]; // } // private GiftBagCfg GetRoleLvGiftCfg() // { // List giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV); // if (giftBagCfgs.Count == 0) return null; // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) => // { // if (a.lv.CompareTo(b.lv) != 0) // { // return a.lv.CompareTo(b.lv); // } // return -1; // }); // for (int i = 0; i < giftBagCfgs.Count; i++) // { // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i]; // } // return giftBagCfgs[0]; // } // public List GetExchangeCfgs() // { // List shopExchangeCfgs = new List(ShopExchangeCfgArray.Instance.dataArray); // shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) => // { // //未售罄的>已售罄的 // int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1; // int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1; // if (buyTypeA > buyTypeB) return -1; // if (buyTypeA < buyTypeB) return 1; // return 0; // }); // return shopExchangeCfgs; // } /// /// 返回活动商城是否显示 /// /// public bool GetShopActivityIsShow(int shopType, int menuType) { List shopCfgs = CommonDataManager.Tables.TblShopCfg.DataList .Where(a => a.Menu1 == shopType && a.Menu2 == menuType).ToList(); if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0) return false; else return true; } public bool GetShopIdCanBuyInShop(int menuType, List shopListId) { List shopCfgs = CommonDataManager.Tables.TblShopCfg.DataList .Where(a => a.Menu1 == ConstStoreTabId.STORE_GIFT_BAG && a.Menu2 == menuType).ToList(); if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0) return false; foreach (var shopId in shopListId) { int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopId); foreach (var cfg in shopCfgs) { if (cfg.Id == shopId && buyNum < cfg.MaxBuyNum) return true; } } return false; } } }