ShopDataManager.cs 16 KB

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