/// <summary> /// 发奖 /// </summary> /// <param name="managerId"></param> /// <param name="prizeEntity"></param> /// <param name="specialItem"></param> /// <param name="addpoint"></param> /// <param name="addcoin"></param> /// <param name="isAddPackage"></param> /// <param name="package"></param> /// <param name="response"></param> /// <param name="record"></param> /// <returns></returns> MessageCode SendPrize(Guid managerId, ConfigTurntableprizeEntity prizeEntity, int specialItem, ref int addpoint, ref int addcoin, ref bool isAddPackage, ref ItemPackageFrame package, TurntableLuckDrawResponse response, TurntableLuckyrecordEntity record) { var messCode = MessageCode.Success; response.Data.PrizeCount = prizeEntity.ItemCount; switch (prizeEntity.PrizeType) { case (int)EnumTurntablePrizeType.Point: addpoint = prizeEntity.ItemCount; response.Data.PrizeCode = 0; response.Data.PrizeType = (int)EnumTurntablePrizeType.Point; record.LuckDrawString = (int)prizeEntity.PrizeType + "," + prizeEntity.SubType + "," + prizeEntity.ItemCount; break; case (int)EnumTurntablePrizeType.Coin: addcoin = prizeEntity.ItemCount; response.Data.PrizeCode = 0; response.Data.PrizeType = (int)EnumTurntablePrizeType.Coin; record.LuckDrawString = (int)prizeEntity.PrizeType + "," + prizeEntity.SubType + "," + prizeEntity.ItemCount; break; case (int)EnumTurntablePrizeType.Item: isAddPackage = true; messCode = package.AddItems(prizeEntity.SubType, prizeEntity.ItemCount); if (messCode != MessageCode.Success) { return(messCode); } response.Data.PrizeCode = prizeEntity.SubType; response.Data.PrizeType = (int)EnumTurntablePrizeType.Item; record.LuckDrawString = (int)prizeEntity.PrizeType + "," + prizeEntity.SubType + "," + prizeEntity.ItemCount; break; case (int)EnumTurntablePrizeType.Random: isAddPackage = true; var itemCode = CacheFactory.LotteryCache.LotteryByLib(prizeEntity.SubType); var itemCache = CacheFactory.ItemsdicCache.GetItem(itemCode); if (itemCache == null) { return(MessageCode.ItemNotExists); } if (itemCache.ItemType == (int)EnumItemType.PlayerCard) { messCode = package.AddPlayerCard(itemCode, 1, false, 1, false); } else { messCode = package.AddItems(itemCode, prizeEntity.ItemCount); } if (messCode != MessageCode.Success) { return(messCode); } response.Data.PrizeCode = itemCode; response.Data.PrizeType = (int)EnumTurntablePrizeType.Item; record.LuckDrawString = (int)prizeEntity.PrizeType + "," + itemCode + "," + prizeEntity.ItemCount; break; case (int)EnumTurntablePrizeType.Turntable: record.LuckDrawString = (int)prizeEntity.PrizeType + "," + prizeEntity.SubType + "," + prizeEntity.ItemCount; break; case (int)EnumTurntablePrizeType.Special: isAddPackage = true; if (specialItem == 0) { return(MessageCode.NbParameterError); } messCode = package.AddItems(specialItem, prizeEntity.ItemCount); if (messCode != MessageCode.Success) { return(messCode); } response.Data.PrizeCode = specialItem; response.Data.PrizeType = (int)EnumTurntablePrizeType.Item; record.LuckDrawString = (int)prizeEntity.PrizeType + "," + specialItem + "," + prizeEntity.ItemCount; break; default: break; } return(MessageCode.Success); }
/// <summary> /// 转盘抽奖 /// </summary> /// <param name="managerId"></param> /// <returns></returns> public TurntableLuckDrawResponse TurntableLuckDraw(Guid managerId) { TurntableLuckDrawResponse response = new TurntableLuckDrawResponse(); response.Data = new TurntableLuckDraw(); try { var turntable = new TurntableFrame(managerId); if (turntable == null) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)MessageCode.NbParameterError)); } var turntableManager = turntable.TurntableManagerEntity; if (turntableManager == null) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)MessageCode.NbParameterError)); } if (turntableManager.GiveLuckyCoin <= 0 && turntableManager.LuckyCoin <= 0) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)MessageCode.LuckyCoinInsufficient)); } var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.Turntable); if (package == null) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)MessageCode.NbNoPackage)); } if (package.BlankCount < 1) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)MessageCode.ItemPackageFull)); } //抽奖 int specialItem = 0; var resultPrize = turntable.LuckDraw(ref specialItem); if (resultPrize == null) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)MessageCode.NbParameterError)); } int addPoint = 0; int addCoin = 0; bool isAddPackage = false; NbManagerEntity manager = null; var record = new TurntableLuckyrecordEntity(0, managerId, false, 1, DateTime.Now, ""); var messageCode = SendPrize(managerId, resultPrize, specialItem, ref addPoint, ref addCoin, ref isAddPackage, ref package, response, record); if (addCoin > 0) { manager = ManagerCore.Instance.GetManager(managerId); if (manager == null) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)MessageCode.NbParameterError)); } } if (messageCode != MessageCode.Success) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)messageCode)); } messageCode = SaveLuckDraw(managerId, addPoint, addCoin, isAddPackage, package, manager, turntable, record); if (messageCode != MessageCode.Success) { return(ResponseHelper.Create <TurntableLuckDrawResponse>((int)messageCode)); } response.Data.WinAlotteryId = resultPrize.TurntableId; response.Data.TurntableInfo = GetTurntableInfo(turntable); } catch (Exception ex) { SystemlogMgr.Error("转盘抽奖", ex); response.Code = (int)MessageCode.NbParameterError; } return(response); }