ShopDataManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using cfg.GfgCfg;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public class ShopDataManager : SingletonBase<ShopDataManager>
  9. {
  10. public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" };
  11. private Dictionary<int, int> _goodsDic = new Dictionary<int, int>();
  12. public List<int> GrowthFundRewardList = new List<int>();
  13. public void Clear()
  14. {
  15. _goodsDic.Clear();
  16. }
  17. public void UpdateGoodsData(int giftId, int num)
  18. {
  19. if (!_goodsDic.ContainsKey(giftId))
  20. {
  21. _goodsDic.Add(giftId, num);
  22. }
  23. else
  24. {
  25. _goodsDic[giftId] = num;
  26. }
  27. }
  28. /************************************************************************************************************/
  29. public List<ShopCfg> GetList(int storeId, int typeIndex, int scoreType)
  30. {
  31. List<ShopCfg> shopCfgs = null;
  32. switch (storeId)
  33. {
  34. case ConstStoreId.CLOTHING_STORE_ID:
  35. shopCfgs = ShopConfigManager.Instance.GetConfigs(ConstStoreTabId.FU_ZHUANG_DIAN,
  36. ConstStoreSubId.FU_ZHUANG_DIAN, typeIndex.ToString());
  37. break;
  38. case ConstStoreId.GALLERY_STORE_ID:
  39. shopCfgs = ShopConfigManager.Instance.GetConfigs(ConstStoreTabId.STORE_EXCHANGE,
  40. ConstStoreSubId.STORE_EXCHANGE_GALLERY, typeIndex.ToString());
  41. break;
  42. }
  43. SortItemListByScore(shopCfgs, scoreType);
  44. return shopCfgs;
  45. }
  46. public void GetMoneyIdAndNum(int buyId, int count, int shopType, out int costId, out int costNum,
  47. out int buyNum)
  48. {
  49. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(buyId);
  50. costId = shopCfg.CostIdReal;
  51. costNum = shopCfg.Price * count;
  52. buyNum = count;
  53. }
  54. private List<ShopCfg> SortItemListByScore(List<ShopCfg> arrayList, int scoreType)
  55. {
  56. arrayList.Sort((ShopCfg a, ShopCfg b) =>
  57. {
  58. long numA = ItemDataManager.GetItemNum(a.ItemId);
  59. long numB = ItemDataManager.GetItemNum(b.ItemId);
  60. bool hasA = numA > 0;
  61. bool hasB = numB > 0;
  62. if (hasA && !hasB)
  63. {
  64. return 1;
  65. }
  66. else if (!hasA && hasB)
  67. {
  68. return -1;
  69. }
  70. else if (scoreType > 0 && !hasA && !hasB)
  71. {
  72. int scoreA = ItemDataManager.GetItemAdditionScore(a.ItemId, scoreType);
  73. int scoreB = ItemDataManager.GetItemAdditionScore(b.ItemId, scoreType);
  74. if (scoreB > scoreA)
  75. {
  76. return 1;
  77. }
  78. else if (scoreB < scoreA)
  79. {
  80. return -1;
  81. }
  82. }
  83. return a.ItemId.CompareTo(b.ItemId);
  84. });
  85. return arrayList;
  86. }
  87. /**************************************************************************************************************************/
  88. /// <summary>
  89. /// 根据商品id获取购买次数
  90. /// </summary>
  91. /// <param name="goodsId"></param>
  92. /// <returns></returns>
  93. public int GetGoodsBuyNumById(int goodsId)
  94. {
  95. return !_goodsDic.ContainsKey(goodsId) ? 0 : _goodsDic[goodsId];
  96. }
  97. //移除未上架商品
  98. public List<ShopCfg> RemoveNotOpenCfg(List<ShopCfg> shop)
  99. {
  100. List<ShopCfg> shopCfgs = new List<ShopCfg>();
  101. for (int i = shop.Count - 1; i >= 0; i--)
  102. {
  103. if (!string.IsNullOrEmpty(shop[i].StartTime) && !TimeUtil.IsBeforeCurTime(shop[i].StartTime) ||
  104. !string.IsNullOrEmpty(shop[i].EndTime) && !TimeUtil.IsLaterCurTime(shop[i].EndTime))
  105. {
  106. continue;
  107. }
  108. shopCfgs.Add(shop[i]);
  109. }
  110. return shopCfgs;
  111. }
  112. //移除原价商品
  113. public List<ShopCfg> RemoveNotSaleCfg(List<ShopCfg> shop, List<int> idList)
  114. {
  115. List<ShopCfg> shopCfgs = new List<ShopCfg>();
  116. for (int i = 0; i < idList.Count; i++)
  117. {
  118. ShopCfg shopcfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(idList[i]);
  119. shopCfgs.Add(shopcfg);
  120. }
  121. return shopCfgs;
  122. }
  123. //商品排序
  124. public List<ShopCfg> SortShopGoodsCfgs(List<ShopCfg> shopCfgs)
  125. {
  126. shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  127. {
  128. //未售罄的>已售罄的
  129. int buyTypeA = (a.MaxBuyNum == 0 || a.MaxBuyNum - GetGoodsBuyNumById(a.Id) > 0) ? 1 : -1;
  130. int buyTypeB = (b.MaxBuyNum == 0 || b.MaxBuyNum - GetGoodsBuyNumById(b.Id) > 0) ? 1 : -1;
  131. if (buyTypeA > buyTypeB) return -1;
  132. if (buyTypeA < buyTypeB) return 1;
  133. int sortTypeA = a.Sort == 0 ? 999 : a.Sort;
  134. int sortTypeB = b.Sort == 0 ? 999 : b.Sort;
  135. if (sortTypeA > sortTypeB) return 1;
  136. if (sortTypeA < sortTypeB) return -1;
  137. return a.Id - b.Id;
  138. });
  139. return shopCfgs;
  140. }
  141. //获取商店所有消耗品id列表
  142. public List<int> GetShopCostIds(List<ShopCfg> shopCfgs)
  143. {
  144. List<int> costIds = new List<int>();
  145. for (int i = 0; i < shopCfgs.Count; i++)
  146. {
  147. if (shopCfgs[i].CostIdReal == 0) continue;
  148. if (costIds.IndexOf(shopCfgs[i].CostIdReal) < 0)
  149. {
  150. costIds.Add(shopCfgs[i].CostIdReal);
  151. }
  152. }
  153. return costIds;
  154. }
  155. /// <summary>
  156. /// 根据商品Id获取商品是否已解锁
  157. /// /// </summary>
  158. /// <param name="goodsId"></param>
  159. /// <returns></returns>
  160. public bool GetShopGoodsStateById(int goodsId)
  161. {
  162. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId);
  163. if (shopCfg.LockType == LockType.NONE)
  164. {
  165. return true;
  166. }
  167. else if (shopCfg.LockType == LockType.STORY_LV)
  168. {
  169. return InstanceZonesDataManager.CheckLevelPass(shopCfg.LockValue);
  170. }
  171. else if (shopCfg.LockType == LockType.ROLE_LV)
  172. {
  173. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= shopCfg.LockValue;
  174. }
  175. else if (shopCfg.LockType == LockType.MONTH_CARD_TYPE)
  176. {
  177. return RoleDataManager.CheckIsMonthCardOpenByType(shopCfg.LockValue);
  178. }
  179. else if (shopCfg.LockType == LockType.AREND_GRADE)
  180. {
  181. int lockValue = shopCfg.LockValue;
  182. if (shopCfg.Menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.Menu2 != ConstStoreSubId.STORE_ARENA_ITEM &&
  183. shopCfg.Menu2 < ArenaDataManager.Instance.SeasonId)
  184. {
  185. bool isDown = ArenaDataManager.Instance.SeasonId -
  186. CommonDataManager.Tables.TblGlobalCfg.SeasonReduce > 0;
  187. lockValue = isDown
  188. ? Math.Max(1, shopCfg.LockValue - CommonDataManager.Tables.TblGlobalCfg.RankReduce)
  189. : shopCfg.LockValue;
  190. }
  191. return ArenaDataManager.Instance.HighestGrade >= lockValue;
  192. }
  193. return true;
  194. }
  195. /// <summary>
  196. /// 根据商品Id获取商品解锁提示
  197. /// /// </summary>
  198. /// <param name="goodsId"></param>
  199. /// <returns></returns>
  200. public string GetShopGoodsStateTips(int goodsId)
  201. {
  202. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId);
  203. if (shopCfg.LockType == LockType.STORY_LV)
  204. {
  205. StoryLevelCfg storyLevelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(shopCfg.LockValue);
  206. return string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.ChapterId),
  207. storyLevelCfg.Order);
  208. }
  209. else if (shopCfg.LockType == LockType.ROLE_LV)
  210. {
  211. return string.Format("角色达到{0}级解锁", shopCfg.LockValue);
  212. }
  213. else if (shopCfg.LockType == LockType.MONTH_CARD_TYPE)
  214. {
  215. return string.Format("开通{0}解锁", shopCfg.LockValue == MonthCardType.Gold ? "红包卡" : "福气卡");
  216. }
  217. else if (shopCfg.LockType == LockType.AREND_GRADE)
  218. {
  219. int lockValue = shopCfg.LockValue;
  220. if (shopCfg.Menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.Menu2 != ConstStoreSubId.STORE_ARENA_ITEM &&
  221. shopCfg.Menu2 < ArenaDataManager.Instance.SeasonId)
  222. {
  223. bool isDown = ArenaDataManager.Instance.SeasonId -
  224. CommonDataManager.Tables.TblGlobalCfg.SeasonReduce > 0;
  225. lockValue = isDown
  226. ? Math.Max(1, shopCfg.LockValue - CommonDataManager.Tables.TblGlobalCfg.RankReduce)
  227. : shopCfg.LockValue;
  228. }
  229. ArenaRankCfg arenaRankCfg = CommonDataManager.Tables.TblArenaRankCfg.GetOrDefault(lockValue);
  230. return string.Format("飞花令段位达到{0}解锁", arenaRankCfg.GradeName);
  231. }
  232. return "";
  233. }
  234. /// <summary>
  235. /// 根据商品id获取下架时间
  236. /// </summary>
  237. /// <param name="goodsId"></param>
  238. /// <returns></returns>
  239. public string GetEndTime(int goodsId)
  240. {
  241. long endTime = 0;
  242. ShopCfg cfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId);
  243. if (cfg.EndTime == "") return "";
  244. endTime = TimeUtil.DateTimeToTimestamp(cfg.EndTime);
  245. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  246. }
  247. //获取商品折扣百分比
  248. public int GetShopGoodsDiscount(int goodsId)
  249. {
  250. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(goodsId);
  251. if (shopCfg.Price == 0) return 0;
  252. return (int)(((double)shopCfg.OriginalPrice / (double)shopCfg.Price) * 100);
  253. }
  254. // public List<ShopCfg> SortGiftBagCfgs(List<ShopCfg> shopCfgs)
  255. // {
  256. // shopCfgs.Sort((ShopCfg a, ShopCfg b) =>
  257. // {
  258. // //未售罄的>未解锁>已售罄的
  259. // int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1;
  260. // int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1;
  261. // if (buyTypeA > buyTypeB) return -1;
  262. // if (buyTypeA < buyTypeB) return 1;
  263. // //解锁状态
  264. // int lockA = GetShopGoodsStateById(a.id) ? 1 : -1;
  265. // int lockB = GetShopGoodsStateById(b.id) ? 1 : -1;
  266. // if (lockA > lockB) return -1;
  267. // if (lockA < lockB) return 1;
  268. // //免费>钻石>现金>道具
  269. // if (a.costType < b.costType) return -1;
  270. // if (a.costType > b.costType) return 1;
  271. // //有下架时间的 > 没有下架时间的
  272. // int endTimeA = a.endTime != "" ? 1 : -1;
  273. // int endTimeB = b.endTime != "" ? 1 : -1;
  274. // if (endTimeA > endTimeB) return -1;
  275. // if (endTimeA < endTimeB) return 1;
  276. // //折扣打的>折扣小的
  277. // int disCountA = GetShopGoodsDiscount(a.id);
  278. // int disCountB = GetShopGoodsDiscount(b.id);
  279. // if (disCountA > disCountB) return -1;
  280. // if (disCountA < disCountB) return 1;
  281. // //价格低的>价格高的
  282. // if (a.price != b.price) return a.price - b.price;
  283. // return 0;
  284. // });
  285. // return shopCfgs;
  286. // }
  287. // private List<GiftBagCfg> GetNoneGiftCfg()
  288. // {
  289. // List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  290. // return giftBagCfgs;
  291. // }
  292. // private GiftBagCfg GetStoryLvGiftCfg()
  293. // {
  294. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  295. // if (giftBagCfgs.Count == 0) return null;
  296. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  297. // {
  298. // if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  299. // {
  300. // return a.storyLevelId.CompareTo(b.storyLevelId);
  301. // }
  302. // return -1;
  303. // });
  304. // for (int i = 0; i < giftBagCfgs.Count; i++)
  305. // {
  306. // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  307. // }
  308. // return giftBagCfgs[0];
  309. // }
  310. // private GiftBagCfg GetRoleLvGiftCfg()
  311. // {
  312. // List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  313. // if (giftBagCfgs.Count == 0) return null;
  314. // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  315. // {
  316. // if (a.lv.CompareTo(b.lv) != 0)
  317. // {
  318. // return a.lv.CompareTo(b.lv);
  319. // }
  320. // return -1;
  321. // });
  322. // for (int i = 0; i < giftBagCfgs.Count; i++)
  323. // {
  324. // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  325. // }
  326. // return giftBagCfgs[0];
  327. // }
  328. // public List<ShopExchangeCfg> GetExchangeCfgs()
  329. // {
  330. // List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  331. // shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  332. // {
  333. // //未售罄的>已售罄的
  334. // int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  335. // int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  336. // if (buyTypeA > buyTypeB) return -1;
  337. // if (buyTypeA < buyTypeB) return 1;
  338. // return 0;
  339. // });
  340. // return shopExchangeCfgs;
  341. // }
  342. /// <summary>
  343. /// 返回活动商城是否显示
  344. /// /// </summary>
  345. public bool GetShopActivityIsShow(int shopType, int menuType)
  346. {
  347. List<ShopCfg> shopCfgs = CommonDataManager.Tables.TblShopCfg.DataList
  348. .Where(a => a.Menu1 == shopType && a.Menu2 == menuType).ToList();
  349. if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0)
  350. return false;
  351. else
  352. return true;
  353. }
  354. public bool GetShopIdCanBuyInShop(int menuType, List<int> shopListId)
  355. {
  356. List<ShopCfg> shopCfgs =
  357. CommonDataManager.Tables.TblShopCfg.DataList
  358. .Where(a => a.Menu1 == ConstStoreTabId.STORE_GIFT_BAG && a.Menu2 == menuType).ToList();
  359. if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0)
  360. return false;
  361. foreach (var shopId in shopListId)
  362. {
  363. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopId);
  364. foreach (var cfg in shopCfgs)
  365. {
  366. if (cfg.Id == shopId && buyNum < cfg.MaxBuyNum)
  367. return true;
  368. }
  369. }
  370. return false;
  371. }
  372. }
  373. }