ShopDataManager.cs 15 KB

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