ShopDataManager.cs 16 KB

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