/// <summary> /// 获取用户转盘信息 /// </summary> /// <param name="managerId"></param> /// <returns></returns> public GetTurntableInfoResponse GetManagerInfo(Guid managerId) { GetTurntableInfoResponse response = new GetTurntableInfoResponse(); response.Data = new TurntableInfo(); try { var turntable = new TurntableFrame(managerId); if (turntable == null) { return(ResponseHelper.Create <GetTurntableInfoResponse>((int)MessageCode.NbParameterError)); } var data = GetTurntableInfo(turntable); if (data == null) { return(ResponseHelper.Create <GetTurntableInfoResponse>((int)MessageCode.NbParameterError)); } response.Data = data; } catch (Exception ex) { SystemlogMgr.Error("获取经理转盘信息", ex); response.Code = (int)MessageCode.NbParameterError; } return(response); }
TurntableInfo GetTurntableInfo(TurntableFrame turntable) { TurntableInfo data = new TurntableInfo(); var turntableManager = turntable.TurntableManagerEntity; data.DayProduceLuckyCoin = turntableManager.DayProduceLuckyCoin; data.FreeOfChargeNumber = turntableManager.GiveLuckyCoin; data.LuckyCoin = turntableManager.LuckyCoin; data.TurntableType = turntableManager.TurntableType; data.NextResetPoint = turntable.GetResetPoint(); data.ItemList = turntable.GetTurntableList(); data.StartTimeTick = ShareUtil.GetTimeTick(startTime); data.EndTimeTick = ShareUtil.GetTimeTick(endTime); return(data); }
/// <summary> /// 重置转盘 /// </summary> /// <param name="managerId"></param> /// <returns></returns> public TurntableResetResponse ResetTurntable(Guid managerId) { TurntableResetResponse response = new TurntableResetResponse(); response.Data = new TurntableReset(); try { var turntable = new TurntableFrame(managerId); if (turntable == null) { return(ResponseHelper.Create <TurntableResetResponse>((int)MessageCode.NbParameterError)); } if (!turntable.TurnTableDic.ItemList.Exists(r => !r.IsEffective)) //不需要重置 { return(ResponseHelper.Create <TurntableResetResponse>((int)MessageCode.TurntableNotReset)); } int consumePoint = turntable.GetResetPoint(turntable.TurntableManagerEntity.TurntableType); if (consumePoint == 0) { return(ResponseHelper.Create <TurntableResetResponse>((int)MessageCode.NbParameterError)); } var point = PayCore.Instance.GetPoint(managerId); if (point < consumePoint)//钻石不足 { return(ResponseHelper.Create <TurntableResetResponse>((int)MessageCode.NbPointShortage)); } //重置 turntable.Reset(turntable.TurntableManagerEntity.TurntableType); using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetConnectionString(EnumDbType.Main))) { transactionManager.BeginTransaction(); MessageCode messageCode = MessageCode.NbUpdateFail; do { messageCode = PayCore.Instance.GambleConsume(managerId, consumePoint, ShareUtil.GenerateComb(), EnumConsumeSourceType.Turntable, transactionManager.TransactionObject); if (messageCode != MessageCode.Success) { break; } if (!turntable.Save(transactionManager.TransactionObject)) { messageCode = MessageCode.NbUpdateFail; break; } messageCode = MessageCode.Success; } while (false); if (messageCode == MessageCode.Success) { transactionManager.Commit(); } else { transactionManager.Rollback(); return(ResponseHelper.Create <TurntableResetResponse>((int)messageCode)); } } response.Data.TurntableInfo = GetTurntableInfo(turntable); response.Data.Point = point - consumePoint; } catch (Exception ex) { SystemlogMgr.Error("重置转盘", ex); response.Code = (int)MessageCode.NbParameterError; } return(response); }
MessageCode SaveLuckDraw(Guid managerId, int addPoint, int addCoin, bool isAddPackage, ItemPackageFrame package, NbManagerEntity manager, TurntableFrame turntable, TurntableLuckyrecordEntity record, DbTransaction trans) { var messageCode = MessageCode.Success; if (addPoint > 0) { messageCode = PayCore.Instance.AddBonus(managerId, addPoint, EnumChargeSourceType.Turntable, ShareUtil.GenerateComb().ToString(), trans); if (messageCode != MessageCode.Success) { return(messageCode); } } if (addCoin > 0) { messageCode = ManagerCore.Instance.AddCoin(manager, addCoin, EnumCoinChargeSourceType.Turntable, ShareUtil.GenerateComb().ToString(), trans); if (messageCode != MessageCode.Success) { return(messageCode); } } if (!turntable.Save(trans)) { return(MessageCode.NbUpdateFail); } if (isAddPackage) { if (!package.Save(trans)) { return(MessageCode.NbUpdateFail); } package.Shadow.Save(); } TurntableLuckyrecordMgr.Insert(record, trans); return(MessageCode.Success); }
/// <summary> /// 保存抽奖 /// </summary> /// <param name="managerId"></param> /// <param name="addPoint"></param> /// <param name="addCoin"></param> /// <param name="isAddPackage"></param> /// <param name="package"></param> /// <param name="manager"></param> /// <param name="turntable"></param> /// <param name="record"></param> /// <returns></returns> MessageCode SaveLuckDraw(Guid managerId, int addPoint, int addCoin, bool isAddPackage, ItemPackageFrame package, NbManagerEntity manager, TurntableFrame turntable, TurntableLuckyrecordEntity record) { MessageCode messageCode = MessageCode.Success; using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetConnectionString(EnumDbType.Main))) { transactionManager.BeginTransaction(); messageCode = SaveLuckDraw(managerId, addPoint, addCoin, isAddPackage, package, manager, turntable, record, transactionManager.TransactionObject); if (messageCode == MessageCode.Success) { transactionManager.Commit(); } else { transactionManager.Rollback(); } } return(messageCode); }
/// <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); }