ShopDataManager.cs 16 KB

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