ShopDataManager.cs 15 KB

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