RechargeDataManager.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. // if (buyTypeA > 0 && buyTypeB < 0) return -1;
  132. // if (buyTypeB > 0 && buyTypeA < 0) return 1;
  133. //免费>钻石>现金>道具
  134. if (a.costType < b.costType) return -1;
  135. if (a.costType > b.costType) return 1;
  136. //有下架时间的 > 没有下架时间的
  137. int endTimeA = a.endTime != "" ? 1 : -1;
  138. int endTimeB = b.endTime != "" ? 1 : -1;
  139. if (endTimeA > endTimeB) return -1;
  140. if (endTimeA < endTimeB) return 1;
  141. int descA = a.desc == "" ? 0 : int.Parse(a.desc);
  142. int descB = b.desc == "" ? 0 : int.Parse(b.desc);
  143. if (descA != descB) return descA - descB;
  144. if (a.price != b.price) return a.price - b.price;
  145. return 0;
  146. });
  147. return giftBagCfgs;
  148. }
  149. private List<GiftBagCfg> GetNoneGiftCfg()
  150. {
  151. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgs(LockType.NONE));
  152. for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
  153. {
  154. if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
  155. {
  156. giftBagCfgs.RemoveAt(i);
  157. }
  158. }
  159. return giftBagCfgs;
  160. }
  161. private GiftBagCfg GetStoryLvGiftCfg()
  162. {
  163. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.STORY_LV);
  164. if (giftBagCfgs.Count == 0) return null;
  165. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  166. {
  167. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  168. {
  169. return a.storyLevelId.CompareTo(b.storyLevelId);
  170. }
  171. return -1;
  172. });
  173. for (int i = 0; i < giftBagCfgs.Count; i++)
  174. {
  175. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  176. }
  177. return giftBagCfgs[0];
  178. }
  179. private GiftBagCfg GetRoleLvGiftCfg()
  180. {
  181. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.ROLE_LV);
  182. if (giftBagCfgs.Count == 0) return null;
  183. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  184. {
  185. if (a.lv.CompareTo(b.lv) != 0)
  186. {
  187. return a.lv.CompareTo(b.lv);
  188. }
  189. return -1;
  190. });
  191. for (int i = 0; i < giftBagCfgs.Count; i++)
  192. {
  193. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  194. }
  195. return giftBagCfgs[0];
  196. }
  197. /// <summary>
  198. /// 根据礼包Id获取礼包解锁状态
  199. /// /// </summary>
  200. /// <param name="giftId"></param>
  201. /// <returns></returns>
  202. public bool GetGiftStateById(int giftId)
  203. {
  204. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  205. if (cfg.lockType == LockType.NONE)
  206. {
  207. return true;
  208. }
  209. else if (cfg.lockType == LockType.STORY_LV)
  210. {
  211. return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  212. }
  213. else
  214. {
  215. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
  216. }
  217. }
  218. /// <summary>
  219. /// 根据礼包id获取下架时间
  220. /// </summary>
  221. /// <param name="giftId"></param>
  222. /// <returns></returns>
  223. public string GetEndTime(int giftId)
  224. {
  225. int endTime = 0;
  226. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  227. if (cfg.endTime == "") return "";
  228. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  229. return TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, endTime);
  230. }
  231. }
  232. }