ShopDataManager.cs 13 KB

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