RechargeDataManager.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ET;
  5. namespace GFGGame
  6. {
  7. public class RechargeStoreType
  8. {
  9. public static int RECHARGE = 0;
  10. public static int GIFT = 1;
  11. public static int EXCHANGE = 2;
  12. }
  13. public class LockType
  14. {
  15. public static int NONE = 0;
  16. public static int STORY_LV = 1;
  17. public static int ROLE_LV = 2;
  18. }
  19. // public class RefreshType
  20. // {
  21. // public static int NONE = 0;
  22. // public static int DAY = 1;
  23. // public static int WEEK = 2;
  24. // public static int MONTH = 3;
  25. // }
  26. public class CostType
  27. {
  28. public static int FREE = 0;
  29. public static int MONEY = 1;
  30. public static int RMB = 2;
  31. public static int ITEM = 3;
  32. }
  33. public class RechargeDataManager : SingletonBase<RechargeDataManager>
  34. {
  35. public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" };
  36. private Dictionary<int, int> _rechargeDic = new Dictionary<int, int>();
  37. private Dictionary<int, int> _giftDic = new Dictionary<int, int>();
  38. private Dictionary<int, int> _exchangeDic = new Dictionary<int, int>();
  39. public void Clear()
  40. {
  41. _rechargeDic.Clear();
  42. _giftDic.Clear();
  43. _exchangeDic.Clear();
  44. }
  45. public void UpdateRechargeData(int rechargeId, int num)
  46. {
  47. if (!_rechargeDic.ContainsKey(rechargeId))
  48. {
  49. _rechargeDic.Add(rechargeId, num);
  50. }
  51. else
  52. {
  53. _rechargeDic[rechargeId] = num;
  54. }
  55. }
  56. public void UpdateGiftData(int giftId, int num)
  57. {
  58. if (!_giftDic.ContainsKey(giftId))
  59. {
  60. _giftDic.Add(giftId, num);
  61. }
  62. else
  63. {
  64. _giftDic[giftId] = num;
  65. }
  66. }
  67. public void UpdateExchangeData(int exchangeId, int num)
  68. {
  69. if (!_exchangeDic.ContainsKey(exchangeId))
  70. {
  71. _exchangeDic.Add(exchangeId, num);
  72. }
  73. else
  74. {
  75. _exchangeDic[exchangeId] = num;
  76. }
  77. }
  78. /// <summary>
  79. /// 根据充值id获取购买次数
  80. /// </summary>
  81. /// <param name="rechargeId"></param>
  82. /// <returns></returns>
  83. public int GetRechargeBuyNumById(int rechargeId)
  84. {
  85. return !_rechargeDic.ContainsKey(rechargeId) ? 0 : _rechargeDic[rechargeId];
  86. }
  87. /// <summary>
  88. /// 根据礼包id获取购买次数
  89. /// </summary>
  90. /// <param name="giftId"></param>
  91. /// <returns></returns>
  92. public int GetGiftBuyNumById(int giftId)
  93. {
  94. return !_giftDic.ContainsKey(giftId) ? 0 : _giftDic[giftId];
  95. }
  96. /// <summary>
  97. /// 根据充值id获取购买次数
  98. /// </summary>
  99. /// <param name="exchangeId"></param>
  100. /// <returns></returns>
  101. public int GetExchangeBuyNumById(int exchangeId)
  102. {
  103. return !_exchangeDic.ContainsKey(exchangeId) ? 0 : _exchangeDic[exchangeId];
  104. }
  105. public List<GiftBagCfg> GetGiftBagCfgs()
  106. {
  107. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>();
  108. List<GiftBagCfg> noneGiftBagCfgs = GetNoneGiftCfg();
  109. giftBagCfgs = giftBagCfgs.Concat(noneGiftBagCfgs).ToList<GiftBagCfg>();
  110. GiftBagCfg StoryLvGiftCfg = GetStoryLvGiftCfg();
  111. if (StoryLvGiftCfg != null) giftBagCfgs.Add(StoryLvGiftCfg);
  112. GiftBagCfg RoleLvGiftCfg = GetRoleLvGiftCfg();
  113. if (RoleLvGiftCfg != null) giftBagCfgs.Add(RoleLvGiftCfg);
  114. SortGiftBagCfgs(giftBagCfgs);
  115. return giftBagCfgs;
  116. }
  117. private List<GiftBagCfg> SortGiftBagCfgs(List<GiftBagCfg> giftBagCfgs)
  118. {
  119. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  120. {
  121. //未售罄的>未解锁>已售罄的
  122. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGiftBuyNumById(a.id) > 0) ? 1 : -1;
  123. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGiftBuyNumById(b.id) > 0) ? 1 : -1;
  124. if (buyTypeA > buyTypeB) return -1;
  125. if (buyTypeA < buyTypeB) return 1;
  126. //解锁状态
  127. int lockA = GetGiftStateById(a.id) ? 1 : -1;
  128. int lockB = GetGiftStateById(b.id) ? 1 : -1;
  129. if (lockA > lockB) return -1;
  130. if (lockA < lockB) return 1;
  131. //免费>钻石>现金>道具
  132. if (a.costType < b.costType) return -1;
  133. if (a.costType > b.costType) return 1;
  134. //有下架时间的 > 没有下架时间的
  135. int endTimeA = a.endTime != "" ? 1 : -1;
  136. int endTimeB = b.endTime != "" ? 1 : -1;
  137. if (endTimeA > endTimeB) return -1;
  138. if (endTimeA < endTimeB) return 1;
  139. int descA = a.desc == "" ? 0 : int.Parse(a.desc);
  140. int descB = b.desc == "" ? 0 : int.Parse(b.desc);
  141. if (descA != descB) return descA - descB;
  142. if (a.price != b.price) return a.price - b.price;
  143. return 0;
  144. });
  145. return giftBagCfgs;
  146. }
  147. private List<GiftBagCfg> GetNoneGiftCfg()
  148. {
  149. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgs(LockType.NONE));
  150. for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
  151. {
  152. if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
  153. {
  154. giftBagCfgs.RemoveAt(i);
  155. }
  156. }
  157. return giftBagCfgs;
  158. }
  159. private GiftBagCfg GetStoryLvGiftCfg()
  160. {
  161. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.STORY_LV);
  162. if (giftBagCfgs.Count == 0) return null;
  163. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  164. {
  165. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  166. {
  167. return a.storyLevelId.CompareTo(b.storyLevelId);
  168. }
  169. return -1;
  170. });
  171. for (int i = 0; i < giftBagCfgs.Count; i++)
  172. {
  173. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  174. }
  175. return giftBagCfgs[0];
  176. }
  177. private GiftBagCfg GetRoleLvGiftCfg()
  178. {
  179. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.ROLE_LV);
  180. if (giftBagCfgs.Count == 0) return null;
  181. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  182. {
  183. if (a.lv.CompareTo(b.lv) != 0)
  184. {
  185. return a.lv.CompareTo(b.lv);
  186. }
  187. return -1;
  188. });
  189. for (int i = 0; i < giftBagCfgs.Count; i++)
  190. {
  191. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  192. }
  193. return giftBagCfgs[0];
  194. }
  195. public List<ShopExchangeCfg> GetExchangeCfgs()
  196. {
  197. List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  198. shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  199. {
  200. //未售罄的>已售罄的
  201. int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  202. int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  203. if (buyTypeA > buyTypeB) return -1;
  204. if (buyTypeA < buyTypeB) return 1;
  205. return 0;
  206. });
  207. return shopExchangeCfgs;
  208. }
  209. /// <summary>
  210. /// 根据礼包Id获取礼包解锁状态
  211. /// /// </summary>
  212. /// <param name="giftId"></param>
  213. /// <returns></returns>
  214. public bool GetGiftStateById(int giftId)
  215. {
  216. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  217. if (cfg.lockType == LockType.NONE)
  218. {
  219. return true;
  220. }
  221. else if (cfg.lockType == LockType.STORY_LV)
  222. {
  223. return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  224. }
  225. else
  226. {
  227. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
  228. }
  229. }
  230. /// <summary>
  231. /// 根据礼包id获取下架时间
  232. /// </summary>
  233. /// <param name="giftId"></param>
  234. /// <returns></returns>
  235. public string GetEndTime(int giftId)
  236. {
  237. int endTime = 0;
  238. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  239. if (cfg.endTime == "") return "";
  240. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  241. return TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, endTime);
  242. }
  243. }
  244. }