ShopDataManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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> RemoveNotSaleCfg(List<ShopCfg> shop,List<int> idList)
  109. {
  110. List<ShopCfg> shopCfgs = new List<ShopCfg>();
  111. for (int i = 0; i < idList.Count; i++)
  112. {
  113. ShopCfg shopcfg = ShopCfgArray.Instance.GetCfg(idList[i]);
  114. shopCfgs.Add(shopcfg);
  115. }
  116. return shopCfgs;
  117. }
  118. //商品排序
  119. public List<ShopCfg> SortShopGoodsCfgs(List<ShopCfg> shopCfgs)
  120. {
  121. shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  122. {
  123. //未售罄的>已售罄的
  124. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  125. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  126. if (buyTypeA > buyTypeB) return -1;
  127. if (buyTypeA < buyTypeB) return 1;
  128. int sortTypeA = a.sort == 0 ? 999 : a.sort;
  129. int sortTypeB = b.sort == 0 ? 999 : b.sort;
  130. if (sortTypeA > sortTypeB) return 1;
  131. if (sortTypeA < sortTypeB) return -1;
  132. return a.id - b.id;
  133. });
  134. return shopCfgs;
  135. }
  136. //获取商店所有消耗品id列表
  137. public List<int> GetShopCostIds(List<ShopCfg> shopCfgs)
  138. {
  139. List<int> costIds = new List<int>();
  140. for (int i = 0; i < shopCfgs.Count; i++)
  141. {
  142. if (shopCfgs[i].CostIdReal == 0) continue;
  143. if (costIds.IndexOf(shopCfgs[i].CostIdReal) < 0)
  144. {
  145. costIds.Add(shopCfgs[i].CostIdReal);
  146. }
  147. }
  148. return costIds;
  149. }
  150. /// <summary>
  151. /// 根据商品Id获取商品是否已解锁
  152. /// /// </summary>
  153. /// <param name="goodsId"></param>
  154. /// <returns></returns>
  155. public bool GetShopGoodsStateById(int goodsId)
  156. {
  157. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  158. if (shopCfg.lockType == LockType.NONE)
  159. {
  160. return true;
  161. }
  162. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE && shopCfg.menu2 == 2)
  163. {
  164. return RoleDataManager.CheckIsMonthCardOpenByType(MonthCardType.Gold) || RoleDataManager.CheckIsMonthCardOpenByType(MonthCardType.BlackGold);
  165. }
  166. else if (shopCfg.lockType == LockType.STORY_LV)
  167. {
  168. return InstanceZonesDataManager.CheckLevelPass(shopCfg.lockValue);
  169. }
  170. else if (shopCfg.lockType == LockType.ROLE_LV)
  171. {
  172. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= shopCfg.lockValue;
  173. }
  174. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE)
  175. {
  176. return RoleDataManager.CheckIsMonthCardOpenByType(shopCfg.lockValue);
  177. }
  178. else if (shopCfg.lockType == LockType.AREND_GRADE)
  179. {
  180. int lockValue = shopCfg.lockValue;
  181. if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM && shopCfg.menu2 < ArenaDataManager.Instance.SeasonId)
  182. {
  183. bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce > 0;
  184. lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue;
  185. }
  186. return ArenaDataManager.Instance.HighestGrade >= lockValue;
  187. }
  188. return true;
  189. }
  190. /// <summary>
  191. /// 根据商品Id获取商品解锁提示
  192. /// /// </summary>
  193. /// <param name="goodsId"></param>
  194. /// <returns></returns>
  195. public string GetShopGoodsStateTips(int goodsId)
  196. {
  197. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  198. if (shopCfg.lockType == LockType.STORY_LV)
  199. {
  200. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(shopCfg.lockValue);
  201. return string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order);
  202. }
  203. else if (shopCfg.lockType == LockType.ROLE_LV)
  204. {
  205. return string.Format("角色达到{0}级解锁", shopCfg.lockValue);
  206. }
  207. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE)
  208. {
  209. return string.Format("开通{0}解锁", shopCfg.lockValue == MonthCardType.Gold ? "红包卡" : "福气卡");
  210. }
  211. else if (shopCfg.lockType == LockType.AREND_GRADE)
  212. {
  213. int lockValue = shopCfg.lockValue;
  214. if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM && shopCfg.menu2 < ArenaDataManager.Instance.SeasonId)
  215. {
  216. bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce > 0;
  217. lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue;
  218. }
  219. ArenaRankCfg arenaRankCfg = ArenaRankCfgArray.Instance.GetCfg(lockValue);
  220. return string.Format("飞花令段位达到{0}解锁", arenaRankCfg.gradeName);
  221. }
  222. return "";
  223. }
  224. /// <summary>
  225. /// 根据商品id获取下架时间
  226. /// </summary>
  227. /// <param name="goodsId"></param>
  228. /// <returns></returns>
  229. public string GetEndTime(int goodsId)
  230. {
  231. long endTime = 0;
  232. ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId);
  233. if (cfg.endTime == "") return "";
  234. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  235. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  236. }
  237. //获取商品折扣百分比
  238. public int GetShopGoodsDiscount(int goodsId)
  239. {
  240. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  241. if (shopCfg.Price == 0) return 0;
  242. return (int)(((double)shopCfg.originalPrice / (double)shopCfg.Price) * 100);
  243. }
  244. // public List<ShopCfg> SortGiftBagCfgs(List<ShopCfg> shopCfgs)
  245. // {
  246. // shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  247. // {
  248. // //未售罄的>未解锁>已售罄的
  249. // int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  250. // int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  251. // if (buyTypeA > buyTypeB) return -1;
  252. // if (buyTypeA < buyTypeB) return 1;
  253. // //解锁状态
  254. // int lockA = GetShopGoodsStateById(a.id) ? 1 : -1;
  255. // int lockB = GetShopGoodsStateById(b.id) ? 1 : -1;
  256. // if (lockA > lockB) return -1;
  257. // if (lockA < lockB) return 1;
  258. // //免费>钻石>现金>道具
  259. // if (a.costType < b.costType) return -1;
  260. // if (a.costType > b.costType) return 1;
  261. // //有下架时间的 > 没有下架时间的
  262. // int endTimeA = a.endTime != "" ? 1 : -1;
  263. // int endTimeB = b.endTime != "" ? 1 : -1;
  264. // if (endTimeA > endTimeB) return -1;
  265. // if (endTimeA < endTimeB) return 1;
  266. // //折扣打的>折扣小的
  267. // int disCountA = GetShopGoodsDiscount(a.id);
  268. // int disCountB = GetShopGoodsDiscount(b.id);
  269. // if (disCountA > disCountB) return -1;
  270. // if (disCountA < disCountB) return 1;
  271. // //价格低的>价格高的
  272. // if (a.price != b.price) return a.price - b.price;
  273. // return 0;
  274. // });
  275. // return shopCfgs;
  276. // }
  277. // private List<GiftBagCfg> GetNoneGiftCfg()
  278. // {
  279. // List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  280. // return giftBagCfgs;
  281. // }
  282. // private GiftBagCfg GetStoryLvGiftCfg()
  283. // {
  284. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  285. // if (giftBagCfgs.Count == 0) return null;
  286. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  287. // {
  288. // if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  289. // {
  290. // return a.storyLevelId.CompareTo(b.storyLevelId);
  291. // }
  292. // return -1;
  293. // });
  294. // for (int i = 0; i < giftBagCfgs.Count; i++)
  295. // {
  296. // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  297. // }
  298. // return giftBagCfgs[0];
  299. // }
  300. // private GiftBagCfg GetRoleLvGiftCfg()
  301. // {
  302. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  303. // if (giftBagCfgs.Count == 0) return null;
  304. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  305. // {
  306. // if (a.lv.CompareTo(b.lv) != 0)
  307. // {
  308. // return a.lv.CompareTo(b.lv);
  309. // }
  310. // return -1;
  311. // });
  312. // for (int i = 0; i < giftBagCfgs.Count; i++)
  313. // {
  314. // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  315. // }
  316. // return giftBagCfgs[0];
  317. // }
  318. // public List<ShopExchangeCfg> GetExchangeCfgs()
  319. // {
  320. // List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  321. // shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  322. // {
  323. // //未售罄的>已售罄的
  324. // int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  325. // int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  326. // if (buyTypeA > buyTypeB) return -1;
  327. // if (buyTypeA < buyTypeB) return 1;
  328. // return 0;
  329. // });
  330. // return shopExchangeCfgs;
  331. // }
  332. /// <summary>
  333. /// 返回活动商城是否显示
  334. /// /// </summary>
  335. public bool GetShopActivityIsShow(int shopType,int menuType)
  336. {
  337. List<ShopCfg> shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(shopType, menuType);
  338. if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0)
  339. return false;
  340. else
  341. return true;
  342. }
  343. public bool GetShopIdCanBuyInShop(int menuType,List<int> shopListId)
  344. {
  345. List<ShopCfg> shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_GIFT_BAG, menuType);
  346. if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0)
  347. return false;
  348. foreach (var shopId in shopListId)
  349. {
  350. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopId);
  351. foreach (var cfg in shopCfgs)
  352. {
  353. if (cfg.id == shopId && buyNum < cfg.maxBuyNum)
  354. return true;
  355. }
  356. }
  357. return false;
  358. }
  359. }
  360. }