RechargeDataManager.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. giftBagCfgs = RemoveNotOpenCfg(giftBagCfgs);
  115. SortGiftBagCfgs(giftBagCfgs);
  116. return giftBagCfgs;
  117. }
  118. private List<GiftBagCfg> SortGiftBagCfgs(List<GiftBagCfg> giftBagCfgs)
  119. {
  120. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  121. {
  122. //未售罄的>未解锁>已售罄的
  123. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGiftBuyNumById(a.id) > 0) ? 1 : -1;
  124. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGiftBuyNumById(b.id) > 0) ? 1 : -1;
  125. if (buyTypeA > buyTypeB) return -1;
  126. if (buyTypeA < buyTypeB) return 1;
  127. //解锁状态
  128. int lockA = GetGiftStateById(a.id) ? 1 : -1;
  129. int lockB = GetGiftStateById(b.id) ? 1 : -1;
  130. if (lockA > lockB) return -1;
  131. if (lockA < lockB) return 1;
  132. //免费>钻石>现金>道具
  133. if (a.costType < b.costType) return -1;
  134. if (a.costType > b.costType) return 1;
  135. //有下架时间的 > 没有下架时间的
  136. int endTimeA = a.endTime != "" ? 1 : -1;
  137. int endTimeB = b.endTime != "" ? 1 : -1;
  138. if (endTimeA > endTimeB) return -1;
  139. if (endTimeA < endTimeB) return 1;
  140. int descA = a.desc == "" ? 0 : int.Parse(a.desc);
  141. int descB = b.desc == "" ? 0 : int.Parse(b.desc);
  142. if (descA != descB) return descA - descB;
  143. if (a.price != b.price) return a.price - b.price;
  144. return 0;
  145. });
  146. return giftBagCfgs;
  147. }
  148. private List<GiftBagCfg> RemoveNotOpenCfg(List<GiftBagCfg> giftBagCfgs)
  149. {
  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 List<GiftBagCfg> GetNoneGiftCfg()
  160. {
  161. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgs(LockType.NONE));
  162. return giftBagCfgs;
  163. }
  164. private GiftBagCfg GetStoryLvGiftCfg()
  165. {
  166. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.STORY_LV);
  167. if (giftBagCfgs.Count == 0) return null;
  168. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  169. {
  170. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  171. {
  172. return a.storyLevelId.CompareTo(b.storyLevelId);
  173. }
  174. return -1;
  175. });
  176. for (int i = 0; i < giftBagCfgs.Count; i++)
  177. {
  178. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  179. }
  180. return giftBagCfgs[0];
  181. }
  182. private GiftBagCfg GetRoleLvGiftCfg()
  183. {
  184. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.ROLE_LV);
  185. if (giftBagCfgs.Count == 0) return null;
  186. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  187. {
  188. if (a.lv.CompareTo(b.lv) != 0)
  189. {
  190. return a.lv.CompareTo(b.lv);
  191. }
  192. return -1;
  193. });
  194. for (int i = 0; i < giftBagCfgs.Count; i++)
  195. {
  196. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  197. }
  198. return giftBagCfgs[0];
  199. }
  200. public List<ShopExchangeCfg> GetExchangeCfgs()
  201. {
  202. List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  203. shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  204. {
  205. //未售罄的>已售罄的
  206. int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  207. int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  208. if (buyTypeA > buyTypeB) return -1;
  209. if (buyTypeA < buyTypeB) return 1;
  210. return 0;
  211. });
  212. return shopExchangeCfgs;
  213. }
  214. /// <summary>
  215. /// 根据礼包Id获取礼包解锁状态
  216. /// /// </summary>
  217. /// <param name="giftId"></param>
  218. /// <returns></returns>
  219. public bool GetGiftStateById(int giftId)
  220. {
  221. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  222. if (cfg.lockType == LockType.NONE)
  223. {
  224. return true;
  225. }
  226. else if (cfg.lockType == LockType.STORY_LV)
  227. {
  228. return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  229. }
  230. else
  231. {
  232. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
  233. }
  234. }
  235. /// <summary>
  236. /// 根据礼包id获取下架时间
  237. /// </summary>
  238. /// <param name="giftId"></param>
  239. /// <returns></returns>
  240. public string GetEndTime(int giftId)
  241. {
  242. int endTime = 0;
  243. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  244. if (cfg.endTime == "") return "";
  245. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  246. return TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, endTime);
  247. }
  248. }
  249. }