ShopDataManager.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 UpdateGiftData(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.costId;
  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. for (int i = shop.Count - 1; i >= 0; i--)
  96. {
  97. if (!string.IsNullOrEmpty(shop[i].startTime) && !TimeUtil.IsBeforeCurTime(shop[i].startTime) || !string.IsNullOrEmpty(shop[i].endTime) && !TimeUtil.IsLaterCurTime(shop[i].endTime))
  98. {
  99. shop.RemoveAt(i);
  100. }
  101. }
  102. return shop;
  103. }
  104. //商品排序
  105. public List<ShopCfg> SortShopGoodsCfgs(List<ShopCfg> shopCfgs)
  106. {
  107. shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  108. {
  109. //未售罄的>已售罄的
  110. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  111. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  112. if (buyTypeA > buyTypeB) return -1;
  113. if (buyTypeA < buyTypeB) return 1;
  114. return a.id - b.id;
  115. });
  116. return shopCfgs;
  117. }
  118. //获取商店所有消耗品id列表
  119. public List<int> GetShopCostIds(List<ShopCfg> shopCfgs)
  120. {
  121. List<int> costIds = new List<int>();
  122. for (int i = 0; i < shopCfgs.Count; i++)
  123. {
  124. if (shopCfgs[i].costId == 0) continue;
  125. if (costIds.IndexOf(shopCfgs[i].costId) < 0)
  126. {
  127. costIds.Add(shopCfgs[i].costId);
  128. }
  129. }
  130. return costIds;
  131. }
  132. /// <summary>
  133. /// 根据商品Id获取商品是否已解锁
  134. /// /// </summary>
  135. /// <param name="goodsId"></param>
  136. /// <returns></returns>
  137. public bool GetShopGoodsStateById(int goodsId)
  138. {
  139. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  140. if (shopCfg.lockType == LockType.NONE)
  141. {
  142. return true;
  143. }
  144. else if (shopCfg.lockType == LockType.STORY_LV)
  145. {
  146. return InstanceZonesDataManager.CheckLevelPass(shopCfg.lockValue);
  147. }
  148. else if (shopCfg.lockType == LockType.ROLE_LV)
  149. {
  150. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= shopCfg.lockValue;
  151. }
  152. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE)
  153. {
  154. return RoleDataManager.CheckIsMonthCardOpenByType(shopCfg.lockValue);
  155. }
  156. else if (shopCfg.lockType == LockType.AREND_GRADE)
  157. {
  158. int lockValue = shopCfg.lockValue;
  159. if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM)
  160. {
  161. bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce >= 0;
  162. lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue;
  163. }
  164. return ArenaDataManager.Instance.Grade >= lockValue;
  165. }
  166. return true;
  167. }
  168. /// <summary>
  169. /// 根据商品Id获取商品解锁提示
  170. /// /// </summary>
  171. /// <param name="goodsId"></param>
  172. /// <returns></returns>
  173. public string GetShopGoodsStateTips(int goodsId)
  174. {
  175. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  176. if (shopCfg.lockType == LockType.STORY_LV)
  177. {
  178. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(shopCfg.lockValue);
  179. return string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order);
  180. }
  181. else if (shopCfg.lockType == LockType.ROLE_LV)
  182. {
  183. return string.Format("角色达到{0}级解锁", shopCfg.lockValue);
  184. }
  185. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE)
  186. {
  187. return string.Format("开通{0}解锁", shopCfg.lockValue == MonthCardType.Gold ? "金卡" : "黑金卡");
  188. }
  189. else if (shopCfg.lockType == LockType.AREND_GRADE)
  190. {
  191. int lockValue = shopCfg.lockValue;
  192. if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM)
  193. {
  194. bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce >= 0;
  195. lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue;
  196. }
  197. ArenaRankCfg arenaRankCfg = ArenaRankCfgArray.Instance.GetCfg(lockValue);
  198. return string.Format("飞花令段位达到{0}解锁", arenaRankCfg.gradeName);
  199. }
  200. return "";
  201. }
  202. /// <summary>
  203. /// 根据商品id获取下架时间
  204. /// </summary>
  205. /// <param name="goodsId"></param>
  206. /// <returns></returns>
  207. public string GetEndTime(int goodsId)
  208. {
  209. long endTime = 0;
  210. ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId);
  211. if (cfg.endTime == "") return "";
  212. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  213. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  214. }
  215. //获取商品折扣百分比
  216. public int GetShopGoodsDiscount(int goodsId)
  217. {
  218. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  219. if (shopCfg.price == 0) return 0;
  220. return (int)(((double)shopCfg.originalPrice / (double)shopCfg.price) * 100);
  221. }
  222. // public List<ShopCfg> SortGiftBagCfgs(List<ShopCfg> shopCfgs)
  223. // {
  224. // shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  225. // {
  226. // //未售罄的>未解锁>已售罄的
  227. // int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  228. // int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  229. // if (buyTypeA > buyTypeB) return -1;
  230. // if (buyTypeA < buyTypeB) return 1;
  231. // //解锁状态
  232. // int lockA = GetShopGoodsStateById(a.id) ? 1 : -1;
  233. // int lockB = GetShopGoodsStateById(b.id) ? 1 : -1;
  234. // if (lockA > lockB) return -1;
  235. // if (lockA < lockB) return 1;
  236. // //免费>钻石>现金>道具
  237. // if (a.costType < b.costType) return -1;
  238. // if (a.costType > b.costType) return 1;
  239. // //有下架时间的 > 没有下架时间的
  240. // int endTimeA = a.endTime != "" ? 1 : -1;
  241. // int endTimeB = b.endTime != "" ? 1 : -1;
  242. // if (endTimeA > endTimeB) return -1;
  243. // if (endTimeA < endTimeB) return 1;
  244. // //折扣打的>折扣小的
  245. // int disCountA = GetShopGoodsDiscount(a.id);
  246. // int disCountB = GetShopGoodsDiscount(b.id);
  247. // if (disCountA > disCountB) return -1;
  248. // if (disCountA < disCountB) return 1;
  249. // //价格低的>价格高的
  250. // if (a.price != b.price) return a.price - b.price;
  251. // return 0;
  252. // });
  253. // return shopCfgs;
  254. // }
  255. // private List<GiftBagCfg> GetNoneGiftCfg()
  256. // {
  257. // List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  258. // return giftBagCfgs;
  259. // }
  260. // private GiftBagCfg GetStoryLvGiftCfg()
  261. // {
  262. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  263. // if (giftBagCfgs.Count == 0) return null;
  264. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  265. // {
  266. // if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  267. // {
  268. // return a.storyLevelId.CompareTo(b.storyLevelId);
  269. // }
  270. // return -1;
  271. // });
  272. // for (int i = 0; i < giftBagCfgs.Count; i++)
  273. // {
  274. // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  275. // }
  276. // return giftBagCfgs[0];
  277. // }
  278. // private GiftBagCfg GetRoleLvGiftCfg()
  279. // {
  280. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  281. // if (giftBagCfgs.Count == 0) return null;
  282. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  283. // {
  284. // if (a.lv.CompareTo(b.lv) != 0)
  285. // {
  286. // return a.lv.CompareTo(b.lv);
  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. // public List<ShopExchangeCfg> GetExchangeCfgs()
  297. // {
  298. // List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  299. // shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  300. // {
  301. // //未售罄的>已售罄的
  302. // int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  303. // int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  304. // if (buyTypeA > buyTypeB) return -1;
  305. // if (buyTypeA < buyTypeB) return 1;
  306. // return 0;
  307. // });
  308. // return shopExchangeCfgs;
  309. // }
  310. }
  311. }