ShopDataManager.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ET;
  5. namespace GFGGame
  6. {
  7. public class LockType
  8. {
  9. public static int NONE = 0;
  10. public static int STORY_LV = 1;
  11. public static int ROLE_LV = 2;
  12. public static int MONTH_CARD_TYPE = 3;
  13. }
  14. public class CostType
  15. {
  16. public static int FREE = 0;
  17. public static int ITEM = 1;
  18. public static int RMB = 2;
  19. }
  20. public class ShopDataManager : SingletonBase<ShopDataManager>
  21. {
  22. public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" };
  23. private Dictionary<int, int> _rechargeDic = new Dictionary<int, int>();
  24. private Dictionary<int, int> _goodsDic = new Dictionary<int, int>();
  25. private Dictionary<int, int> _exchangeDic = new Dictionary<int, int>();
  26. public void Clear()
  27. {
  28. _rechargeDic.Clear();
  29. _goodsDic.Clear();
  30. _exchangeDic.Clear();
  31. }
  32. public void UpdateRechargeData(int rechargeId, int num)
  33. {
  34. if (!_rechargeDic.ContainsKey(rechargeId))
  35. {
  36. _rechargeDic.Add(rechargeId, num);
  37. }
  38. else
  39. {
  40. _rechargeDic[rechargeId] = num;
  41. }
  42. }
  43. public void UpdateGiftData(int giftId, int num)
  44. {
  45. if (!_goodsDic.ContainsKey(giftId))
  46. {
  47. _goodsDic.Add(giftId, num);
  48. }
  49. else
  50. {
  51. _goodsDic[giftId] = num;
  52. }
  53. }
  54. public void UpdateExchangeData(int exchangeId, int num)
  55. {
  56. if (!_exchangeDic.ContainsKey(exchangeId))
  57. {
  58. _exchangeDic.Add(exchangeId, num);
  59. }
  60. else
  61. {
  62. _exchangeDic[exchangeId] = num;
  63. }
  64. }
  65. /************************************************************************************************************/
  66. public List<ShopCfg> GetList(int storeId, int typeIndex, int scoreType)
  67. {
  68. List<ShopCfg> shopCfgs = null;
  69. switch (storeId)
  70. {
  71. case ConstStoreId.CLOTHING_STORE_ID:
  72. shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.FU_ZHUANG_DIAN, ConstStoreSubId.FU_ZHUANG_DIAN, typeIndex);
  73. break;
  74. case ConstStoreId.GALLERY_STORE_ID:
  75. shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_EXCHANGE_GALLERY, typeIndex);
  76. break;
  77. }
  78. SortItemListByScore(shopCfgs, scoreType);
  79. return shopCfgs;
  80. }
  81. public void GetMoneyIdAndNum(int buyId, int count, int shopType, out int costId, out int costNum, out int buyNum)
  82. {
  83. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(buyId);
  84. costId = shopCfg.costId;
  85. costNum = shopCfg.price * count;
  86. buyNum = count;
  87. }
  88. private List<ShopCfg> SortItemListByScore(List<ShopCfg> arrayList, int scoreType)
  89. {
  90. arrayList.Sort((ShopCfg a, ShopCfg b) =>
  91. {
  92. long numA = ItemDataManager.GetItemNum(a.itemId);
  93. long numB = ItemDataManager.GetItemNum(b.itemId);
  94. bool hasA = numA > 0;
  95. bool hasB = numB > 0;
  96. if (hasA && !hasB)
  97. {
  98. return 1;
  99. }
  100. else if (!hasA && hasB)
  101. {
  102. return -1;
  103. }
  104. else if (scoreType > 0 && !hasA && !hasB)
  105. {
  106. int scoreA = ItemDataManager.GetItemAdditionScore(a.itemId, scoreType);
  107. int scoreB = ItemDataManager.GetItemAdditionScore(b.itemId, scoreType);
  108. if (scoreB > scoreA)
  109. {
  110. return 1;
  111. }
  112. else if (scoreB < scoreA)
  113. {
  114. return -1;
  115. }
  116. }
  117. return a.itemId.CompareTo(b.itemId);
  118. });
  119. return arrayList;
  120. }
  121. /**************************************************************************************************************************/
  122. /// <summary>
  123. /// 根据充值id获取购买次数
  124. /// </summary>
  125. /// <param name="rechargeId"></param>
  126. /// <returns></returns>
  127. public int GetRechargeBuyNumById(int rechargeId)
  128. {
  129. return !_rechargeDic.ContainsKey(rechargeId) ? 0 : _rechargeDic[rechargeId];
  130. }
  131. /// <summary>
  132. /// 根据商品id获取购买次数
  133. /// </summary>
  134. /// <param name="goodsId"></param>
  135. /// <returns></returns>
  136. public int GetGoodsBuyNumById(int goodsId)
  137. {
  138. return !_goodsDic.ContainsKey(goodsId) ? 0 : _goodsDic[goodsId];
  139. }
  140. /// <summary>
  141. /// 根据充值id获取购买次数
  142. /// </summary>
  143. /// <param name="exchangeId"></param>
  144. /// <returns></returns>
  145. public int GetExchangeBuyNumById(int exchangeId)
  146. {
  147. return !_exchangeDic.ContainsKey(exchangeId) ? 0 : _exchangeDic[exchangeId];
  148. }
  149. public List<GiftBagCfg> GetGiftBagCfgs()
  150. {
  151. // List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>();
  152. // List<GiftBagCfg> noneGiftBagCfgs = GetNoneGiftCfg();
  153. // giftBagCfgs = giftBagCfgs.Concat(noneGiftBagCfgs).ToList<GiftBagCfg>();
  154. // GiftBagCfg StoryLvGiftCfg = GetStoryLvGiftCfg();
  155. // if (StoryLvGiftCfg != null) giftBagCfgs.Add(StoryLvGiftCfg);
  156. // GiftBagCfg RoleLvGiftCfg = GetRoleLvGiftCfg();
  157. // if (RoleLvGiftCfg != null) giftBagCfgs.Add(RoleLvGiftCfg);
  158. // giftBagCfgs = RemoveNotOpenCfg(giftBagCfgs);
  159. // SortGiftBagCfgs(giftBagCfgs);
  160. // return giftBagCfgs;
  161. return null;
  162. }
  163. public List<ShopCfg> SortGiftBagCfgs(List<ShopCfg> shopCfgs)
  164. {
  165. shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  166. {
  167. //未售罄的>未解锁>已售罄的
  168. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  169. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  170. if (buyTypeA > buyTypeB) return -1;
  171. if (buyTypeA < buyTypeB) return 1;
  172. //解锁状态
  173. int lockA = GetShopGoodsStateById(a.id) ? 1 : -1;
  174. int lockB = GetShopGoodsStateById(b.id) ? 1 : -1;
  175. if (lockA > lockB) return -1;
  176. if (lockA < lockB) return 1;
  177. //免费>钻石>现金>道具
  178. if (a.costType < b.costType) return -1;
  179. if (a.costType > b.costType) return 1;
  180. //有下架时间的 > 没有下架时间的
  181. int endTimeA = a.endTime != "" ? 1 : -1;
  182. int endTimeB = b.endTime != "" ? 1 : -1;
  183. if (endTimeA > endTimeB) return -1;
  184. if (endTimeA < endTimeB) return 1;
  185. int disCountA = GetShopGoodsDiscount(a.id);
  186. int disCountB = GetShopGoodsDiscount(b.id);
  187. if (disCountA != disCountB) return disCountA - disCountB;
  188. if (a.price != b.price) return a.price - b.price;
  189. return 0;
  190. });
  191. return shopCfgs;
  192. }
  193. //获取商品折扣百分比
  194. public int GetShopGoodsDiscount(int goodsId)
  195. {
  196. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  197. if (shopCfg.price == 0) return 0;
  198. return (int)(((double)shopCfg.originalPrice / (double)shopCfg.price) * 100);
  199. }
  200. private List<GiftBagCfg> RemoveNotOpenCfg(List<GiftBagCfg> giftBagCfgs)
  201. {
  202. for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
  203. {
  204. if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
  205. {
  206. giftBagCfgs.RemoveAt(i);
  207. }
  208. }
  209. return giftBagCfgs;
  210. }
  211. private List<GiftBagCfg> GetNoneGiftCfg()
  212. {
  213. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  214. return giftBagCfgs;
  215. }
  216. private GiftBagCfg GetStoryLvGiftCfg()
  217. {
  218. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  219. if (giftBagCfgs.Count == 0) return null;
  220. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  221. {
  222. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  223. {
  224. return a.storyLevelId.CompareTo(b.storyLevelId);
  225. }
  226. return -1;
  227. });
  228. for (int i = 0; i < giftBagCfgs.Count; i++)
  229. {
  230. if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  231. }
  232. return giftBagCfgs[0];
  233. }
  234. private GiftBagCfg GetRoleLvGiftCfg()
  235. {
  236. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  237. if (giftBagCfgs.Count == 0) return null;
  238. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  239. {
  240. if (a.lv.CompareTo(b.lv) != 0)
  241. {
  242. return a.lv.CompareTo(b.lv);
  243. }
  244. return -1;
  245. });
  246. for (int i = 0; i < giftBagCfgs.Count; i++)
  247. {
  248. if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  249. }
  250. return giftBagCfgs[0];
  251. }
  252. public List<ShopExchangeCfg> GetExchangeCfgs()
  253. {
  254. List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  255. shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  256. {
  257. //未售罄的>已售罄的
  258. int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  259. int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  260. if (buyTypeA > buyTypeB) return -1;
  261. if (buyTypeA < buyTypeB) return 1;
  262. return 0;
  263. });
  264. return shopExchangeCfgs;
  265. }
  266. /// <summary>
  267. /// 根据商品Id获取商品是否解锁解锁
  268. /// /// </summary>
  269. /// <param name="goodsId"></param>
  270. /// <returns></returns>
  271. public bool GetShopGoodsStateById(int goodsId)
  272. {
  273. ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId);
  274. if (cfg.lockType == LockType.NONE)
  275. {
  276. return true;
  277. }
  278. else if (cfg.lockType == LockType.STORY_LV)
  279. {
  280. return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  281. }
  282. else if (cfg.lockType == LockType.MONTH_CARD_TYPE)
  283. {
  284. return RoleDataManager.CheckIsMonthCardOpenByType(cfg.MonthlyCardType);
  285. }
  286. else
  287. {
  288. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
  289. }
  290. }
  291. /// <summary>
  292. /// 根据商品id获取下架时间
  293. /// </summary>
  294. /// <param name="goodsId"></param>
  295. /// <returns></returns>
  296. public string GetEndTime(int goodsId)
  297. {
  298. long endTime = 0;
  299. ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId);
  300. if (cfg.endTime == "") return "";
  301. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  302. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  303. }
  304. }
  305. }