ShopDataManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ET;
  5. namespace GFGGame
  6. {
  7. public class ShopDataManager : SingletonBase<ShopDataManager>
  8. {
  9. public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" };
  10. private Dictionary<int, int> _goodsDic = new Dictionary<int, int>();
  11. public List<int> GrowthFundRewardList = new List<int>();
  12. public void Clear()
  13. {
  14. _goodsDic.Clear();
  15. }
  16. public void UpdateGoodsData(int giftId, int num)
  17. {
  18. if (!_goodsDic.ContainsKey(giftId))
  19. {
  20. _goodsDic.Add(giftId, num);
  21. }
  22. else
  23. {
  24. _goodsDic[giftId] = num;
  25. }
  26. }
  27. /************************************************************************************************************/
  28. public List<ShopCfg> GetList(int storeId, int typeIndex, int scoreType)
  29. {
  30. List<ShopCfg> shopCfgs = null;
  31. switch (storeId)
  32. {
  33. case ConstStoreId.CLOTHING_STORE_ID:
  34. shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.FU_ZHUANG_DIAN, ConstStoreSubId.FU_ZHUANG_DIAN, typeIndex.ToString());
  35. break;
  36. case ConstStoreId.GALLERY_STORE_ID:
  37. shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_EXCHANGE_GALLERY, typeIndex.ToString());
  38. break;
  39. }
  40. SortItemListByScore(shopCfgs, scoreType);
  41. return shopCfgs;
  42. }
  43. public void GetMoneyIdAndNum(int buyId, int count, int shopType, out int costId, out int costNum, out int buyNum)
  44. {
  45. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(buyId);
  46. costId = shopCfg.CostIdReal;
  47. costNum = shopCfg.Price * count;
  48. buyNum = count;
  49. }
  50. private List<ShopCfg> SortItemListByScore(List<ShopCfg> arrayList, int scoreType)
  51. {
  52. arrayList.Sort((ShopCfg a, ShopCfg b) =>
  53. {
  54. long numA = ItemDataManager.GetItemNum(a.itemId);
  55. long numB = ItemDataManager.GetItemNum(b.itemId);
  56. bool hasA = numA > 0;
  57. bool hasB = numB > 0;
  58. if (hasA && !hasB)
  59. {
  60. return 1;
  61. }
  62. else if (!hasA && hasB)
  63. {
  64. return -1;
  65. }
  66. else if (scoreType > 0 && !hasA && !hasB)
  67. {
  68. int scoreA = ItemDataManager.GetItemAdditionScore(a.itemId, scoreType);
  69. int scoreB = ItemDataManager.GetItemAdditionScore(b.itemId, scoreType);
  70. if (scoreB > scoreA)
  71. {
  72. return 1;
  73. }
  74. else if (scoreB < scoreA)
  75. {
  76. return -1;
  77. }
  78. }
  79. return a.itemId.CompareTo(b.itemId);
  80. });
  81. return arrayList;
  82. }
  83. /**************************************************************************************************************************/
  84. /// <summary>
  85. /// 根据商品id获取购买次数
  86. /// </summary>
  87. /// <param name="goodsId"></param>
  88. /// <returns></returns>
  89. public int GetGoodsBuyNumById(int goodsId)
  90. {
  91. return !_goodsDic.ContainsKey(goodsId) ? 0 : _goodsDic[goodsId];
  92. }
  93. //移除未上架商品
  94. public List<ShopCfg> RemoveNotOpenCfg(List<ShopCfg> shop)
  95. {
  96. List<ShopCfg> shopCfgs = new List<ShopCfg>();
  97. for (int i = shop.Count - 1; i >= 0; i--)
  98. {
  99. if (!string.IsNullOrEmpty(shop[i].startTime) && !TimeUtil.IsBeforeCurTime(shop[i].startTime) || !string.IsNullOrEmpty(shop[i].endTime) && !TimeUtil.IsLaterCurTime(shop[i].endTime))
  100. {
  101. continue;
  102. }
  103. shopCfgs.Add(shop[i]);
  104. }
  105. return shopCfgs;
  106. }
  107. //商品排序
  108. public List<ShopCfg> SortShopGoodsCfgs(List<ShopCfg> shopCfgs)
  109. {
  110. shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  111. {
  112. //未售罄的>已售罄的
  113. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  114. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  115. if (buyTypeA > buyTypeB) return -1;
  116. if (buyTypeA < buyTypeB) return 1;
  117. return a.id - b.id;
  118. });
  119. return shopCfgs;
  120. }
  121. //获取商店所有消耗品id列表
  122. public List<int> GetShopCostIds(List<ShopCfg> shopCfgs)
  123. {
  124. List<int> costIds = new List<int>();
  125. for (int i = 0; i < shopCfgs.Count; i++)
  126. {
  127. if (shopCfgs[i].CostIdReal == 0) continue;
  128. if (costIds.IndexOf(shopCfgs[i].CostIdReal) < 0)
  129. {
  130. costIds.Add(shopCfgs[i].CostIdReal);
  131. }
  132. }
  133. return costIds;
  134. }
  135. /// <summary>
  136. /// 根据商品Id获取商品是否已解锁
  137. /// /// </summary>
  138. /// <param name="goodsId"></param>
  139. /// <returns></returns>
  140. public bool GetShopGoodsStateById(int goodsId)
  141. {
  142. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  143. if (shopCfg.lockType == LockType.NONE)
  144. {
  145. return true;
  146. }
  147. else if (shopCfg.lockType == LockType.STORY_LV)
  148. {
  149. return InstanceZonesDataManager.CheckLevelPass(shopCfg.lockValue);
  150. }
  151. else if (shopCfg.lockType == LockType.ROLE_LV)
  152. {
  153. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= shopCfg.lockValue;
  154. }
  155. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE)
  156. {
  157. return RoleDataManager.CheckIsMonthCardOpenByType(shopCfg.lockValue);
  158. }
  159. else if (shopCfg.lockType == LockType.AREND_GRADE)
  160. {
  161. int lockValue = shopCfg.lockValue;
  162. if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM)
  163. {
  164. bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce > 0;
  165. lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue;
  166. }
  167. return ArenaDataManager.Instance.Grade >= lockValue;
  168. }
  169. return true;
  170. }
  171. /// <summary>
  172. /// 根据商品Id获取商品解锁提示
  173. /// /// </summary>
  174. /// <param name="goodsId"></param>
  175. /// <returns></returns>
  176. public string GetShopGoodsStateTips(int goodsId)
  177. {
  178. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  179. if (shopCfg.lockType == LockType.STORY_LV)
  180. {
  181. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(shopCfg.lockValue);
  182. return string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order);
  183. }
  184. else if (shopCfg.lockType == LockType.ROLE_LV)
  185. {
  186. return string.Format("角色达到{0}级解锁", shopCfg.lockValue);
  187. }
  188. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE)
  189. {
  190. return string.Format("开通{0}解锁", shopCfg.lockValue == MonthCardType.Gold ? "红包卡" : "福气卡");
  191. }
  192. else if (shopCfg.lockType == LockType.AREND_GRADE)
  193. {
  194. int lockValue = shopCfg.lockValue;
  195. if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM)
  196. {
  197. bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce > 0;
  198. lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue;
  199. }
  200. ArenaRankCfg arenaRankCfg = ArenaRankCfgArray.Instance.GetCfg(lockValue);
  201. return string.Format("飞花令段位达到{0}解锁", arenaRankCfg.gradeName);
  202. }
  203. return "";
  204. }
  205. /// <summary>
  206. /// 根据商品id获取下架时间
  207. /// </summary>
  208. /// <param name="goodsId"></param>
  209. /// <returns></returns>
  210. public string GetEndTime(int goodsId)
  211. {
  212. long endTime = 0;
  213. ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId);
  214. if (cfg.endTime == "") return "";
  215. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  216. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  217. }
  218. //获取商品折扣百分比
  219. public int GetShopGoodsDiscount(int goodsId)
  220. {
  221. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  222. if (shopCfg.Price == 0) return 0;
  223. return (int)(((double)shopCfg.originalPrice / (double)shopCfg.Price) * 100);
  224. }
  225. // public List<ShopCfg> SortGiftBagCfgs(List<ShopCfg> shopCfgs)
  226. // {
  227. // shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  228. // {
  229. // //未售罄的>未解锁>已售罄的
  230. // int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  231. // int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  232. // if (buyTypeA > buyTypeB) return -1;
  233. // if (buyTypeA < buyTypeB) return 1;
  234. // //解锁状态
  235. // int lockA = GetShopGoodsStateById(a.id) ? 1 : -1;
  236. // int lockB = GetShopGoodsStateById(b.id) ? 1 : -1;
  237. // if (lockA > lockB) return -1;
  238. // if (lockA < lockB) return 1;
  239. // //免费>钻石>现金>道具
  240. // if (a.costType < b.costType) return -1;
  241. // if (a.costType > b.costType) return 1;
  242. // //有下架时间的 > 没有下架时间的
  243. // int endTimeA = a.endTime != "" ? 1 : -1;
  244. // int endTimeB = b.endTime != "" ? 1 : -1;
  245. // if (endTimeA > endTimeB) return -1;
  246. // if (endTimeA < endTimeB) return 1;
  247. // //折扣打的>折扣小的
  248. // int disCountA = GetShopGoodsDiscount(a.id);
  249. // int disCountB = GetShopGoodsDiscount(b.id);
  250. // if (disCountA > disCountB) return -1;
  251. // if (disCountA < disCountB) return 1;
  252. // //价格低的>价格高的
  253. // if (a.price != b.price) return a.price - b.price;
  254. // return 0;
  255. // });
  256. // return shopCfgs;
  257. // }
  258. // private List<GiftBagCfg> GetNoneGiftCfg()
  259. // {
  260. // List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  261. // return giftBagCfgs;
  262. // }
  263. // private GiftBagCfg GetStoryLvGiftCfg()
  264. // {
  265. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  266. // if (giftBagCfgs.Count == 0) return null;
  267. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  268. // {
  269. // if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  270. // {
  271. // return a.storyLevelId.CompareTo(b.storyLevelId);
  272. // }
  273. // return -1;
  274. // });
  275. // for (int i = 0; i < giftBagCfgs.Count; i++)
  276. // {
  277. // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  278. // }
  279. // return giftBagCfgs[0];
  280. // }
  281. // private GiftBagCfg GetRoleLvGiftCfg()
  282. // {
  283. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  284. // if (giftBagCfgs.Count == 0) return null;
  285. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  286. // {
  287. // if (a.lv.CompareTo(b.lv) != 0)
  288. // {
  289. // return a.lv.CompareTo(b.lv);
  290. // }
  291. // return -1;
  292. // });
  293. // for (int i = 0; i < giftBagCfgs.Count; i++)
  294. // {
  295. // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  296. // }
  297. // return giftBagCfgs[0];
  298. // }
  299. // public List<ShopExchangeCfg> GetExchangeCfgs()
  300. // {
  301. // List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  302. // shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  303. // {
  304. // //未售罄的>已售罄的
  305. // int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  306. // int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  307. // if (buyTypeA > buyTypeB) return -1;
  308. // if (buyTypeA < buyTypeB) return 1;
  309. // return 0;
  310. // });
  311. // return shopExchangeCfgs;
  312. // }
  313. /// <summary>
  314. /// 返回活动商城是否显示
  315. /// /// </summary>
  316. public bool GetShopActivityIsShow(int shopType,int menuType)
  317. {
  318. List<ShopCfg> shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(shopType, menuType);
  319. if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0)
  320. return false;
  321. else
  322. return true;
  323. }
  324. public bool GetShopIdCanBuyInShop(int menuType,List<int> shopListId)
  325. {
  326. List<ShopCfg> shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_GIFT_BAG, menuType);
  327. if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0)
  328. return false;
  329. foreach (var shopId in shopListId)
  330. {
  331. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopId);
  332. foreach (var cfg in shopCfgs)
  333. {
  334. if (cfg.id == shopId && buyNum < cfg.maxBuyNum)
  335. return true;
  336. }
  337. }
  338. return false;
  339. }
  340. }
  341. }