ShopDataManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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> SortShopGoodsCfgs(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. return a.id - b.id;
  160. });
  161. return shopCfgs;
  162. }
  163. public List<int> GetShopCostIds(List<ShopCfg> shopCfgs)
  164. {
  165. List<int> costIds = new List<int>();
  166. for (int i = 0; i < shopCfgs.Count; i++)
  167. {
  168. if (shopCfgs[i].costId == 0) continue;
  169. if (costIds.IndexOf(shopCfgs[i].costId) < 0)
  170. {
  171. costIds.Add(shopCfgs[i].costId);
  172. }
  173. }
  174. return costIds;
  175. }
  176. // public List<ShopCfg> SortGiftBagCfgs(List<ShopCfg> shopCfgs)
  177. // {
  178. // shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  179. // {
  180. // //未售罄的>未解锁>已售罄的
  181. // int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  182. // int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  183. // if (buyTypeA > buyTypeB) return -1;
  184. // if (buyTypeA < buyTypeB) return 1;
  185. // //解锁状态
  186. // int lockA = GetShopGoodsStateById(a.id) ? 1 : -1;
  187. // int lockB = GetShopGoodsStateById(b.id) ? 1 : -1;
  188. // if (lockA > lockB) return -1;
  189. // if (lockA < lockB) return 1;
  190. // //免费>钻石>现金>道具
  191. // if (a.costType < b.costType) return -1;
  192. // if (a.costType > b.costType) return 1;
  193. // //有下架时间的 > 没有下架时间的
  194. // int endTimeA = a.endTime != "" ? 1 : -1;
  195. // int endTimeB = b.endTime != "" ? 1 : -1;
  196. // if (endTimeA > endTimeB) return -1;
  197. // if (endTimeA < endTimeB) return 1;
  198. // //折扣打的>折扣小的
  199. // int disCountA = GetShopGoodsDiscount(a.id);
  200. // int disCountB = GetShopGoodsDiscount(b.id);
  201. // if (disCountA > disCountB) return -1;
  202. // if (disCountA < disCountB) return 1;
  203. // //价格低的>价格高的
  204. // if (a.price != b.price) return a.price - b.price;
  205. // return 0;
  206. // });
  207. // return shopCfgs;
  208. // }
  209. //获取商品折扣百分比
  210. public int GetShopGoodsDiscount(int goodsId)
  211. {
  212. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  213. if (shopCfg.price == 0) return 0;
  214. return (int)(((double)shopCfg.originalPrice / (double)shopCfg.price) * 100);
  215. }
  216. private List<GiftBagCfg> RemoveNotOpenCfg(List<GiftBagCfg> giftBagCfgs)
  217. {
  218. for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
  219. {
  220. if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
  221. {
  222. giftBagCfgs.RemoveAt(i);
  223. }
  224. }
  225. return giftBagCfgs;
  226. }
  227. private List<GiftBagCfg> GetNoneGiftCfg()
  228. {
  229. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  230. return giftBagCfgs;
  231. }
  232. private GiftBagCfg GetStoryLvGiftCfg()
  233. {
  234. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  235. if (giftBagCfgs.Count == 0) return null;
  236. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  237. {
  238. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  239. {
  240. return a.storyLevelId.CompareTo(b.storyLevelId);
  241. }
  242. return -1;
  243. });
  244. for (int i = 0; i < giftBagCfgs.Count; i++)
  245. {
  246. if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  247. }
  248. return giftBagCfgs[0];
  249. }
  250. private GiftBagCfg GetRoleLvGiftCfg()
  251. {
  252. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  253. if (giftBagCfgs.Count == 0) return null;
  254. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  255. {
  256. if (a.lv.CompareTo(b.lv) != 0)
  257. {
  258. return a.lv.CompareTo(b.lv);
  259. }
  260. return -1;
  261. });
  262. for (int i = 0; i < giftBagCfgs.Count; i++)
  263. {
  264. if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  265. }
  266. return giftBagCfgs[0];
  267. }
  268. // public List<ShopExchangeCfg> GetExchangeCfgs()
  269. // {
  270. // List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  271. // shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  272. // {
  273. // //未售罄的>已售罄的
  274. // int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  275. // int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  276. // if (buyTypeA > buyTypeB) return -1;
  277. // if (buyTypeA < buyTypeB) return 1;
  278. // return 0;
  279. // });
  280. // return shopExchangeCfgs;
  281. // }
  282. /// <summary>
  283. /// 根据商品Id获取商品是否解锁解锁
  284. /// /// </summary>
  285. /// <param name="goodsId"></param>
  286. /// <returns></returns>
  287. public bool GetShopGoodsStateById(int goodsId)
  288. {
  289. ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId);
  290. if (cfg.lockType == LockType.NONE)
  291. {
  292. return true;
  293. }
  294. else if (cfg.lockType == LockType.STORY_LV)
  295. {
  296. return InstanceZonesDataManager.CheckLevelPass(cfg.lockValue);
  297. }
  298. else if (cfg.lockType == LockType.ROLE_LV)
  299. {
  300. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lockValue;
  301. }
  302. else if (cfg.lockType == LockType.MONTH_CARD_TYPE)
  303. {
  304. return RoleDataManager.CheckIsMonthCardOpenByType(cfg.lockValue);
  305. }
  306. else if (cfg.lockType == LockType.AREND_GRADE)
  307. {
  308. return ArenaDataManager.Instance.Grade >= cfg.lockValue;
  309. }
  310. return true;
  311. }
  312. /// <summary>
  313. /// 根据商品Id获取商品解锁提示
  314. /// /// </summary>
  315. /// <param name="goodsId"></param>
  316. /// <returns></returns>
  317. public string GetShopGoodsStateTips(int goodsId)
  318. {
  319. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId);
  320. if (shopCfg.lockType == LockType.STORY_LV)
  321. {
  322. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(shopCfg.lockValue);
  323. return string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order);
  324. }
  325. else if (shopCfg.lockType == LockType.ROLE_LV)
  326. {
  327. return string.Format("角色达到{0}级解锁", shopCfg.lockValue);
  328. }
  329. else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE)
  330. {
  331. return string.Format("开通{0}解锁", shopCfg.lockValue == MonthCardType.Gold ? "金卡" : "黑金卡");
  332. }
  333. else if (shopCfg.lockType == LockType.AREND_GRADE)
  334. {
  335. ArenaRankCfg arenaRankCfg = ArenaRankCfgArray.Instance.GetCfg(shopCfg.lockValue);
  336. return string.Format("飞花令达到{0}解锁", arenaRankCfg.gradeName);
  337. }
  338. return "";
  339. }
  340. /// <summary>
  341. /// 根据商品id获取下架时间
  342. /// </summary>
  343. /// <param name="goodsId"></param>
  344. /// <returns></returns>
  345. public string GetEndTime(int goodsId)
  346. {
  347. long endTime = 0;
  348. ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId);
  349. if (cfg.endTime == "") return "";
  350. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  351. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  352. }
  353. }
  354. }