/// <summary> /// 领取竞猜正确活动奖励 /// </summary> /// <param name="managerId"></param> /// <param name="step"></param> /// <returns></returns> public EuropeGambleMatchResponse DrawPrize(Guid managerId, int step) { EuropeGambleMatchResponse response = new EuropeGambleMatchResponse(); response.Data = new EuropeGambleMatch(); try { var manager = ManagerCore.Instance.GetManager(managerId); if (manager == null) { response.Code = (int)MessageCode.MissManager; return(response); } var info = GetMyGambleInfo(managerId); var prizeList = info.PrizeRecord.Split(','); if (prizeList.Length < step || prizeList[step - 1] == "0") { response.Code = (int)MessageCode.TourNoPassPrize; return(response); } if (prizeList[step - 1] == "2") { response.Code = (int)MessageCode.NbPrizeRepeat; return(response); } var prizeConfig = EuropeConfig.Instance.GetPrize(step); if (prizeConfig.Count <= 0) { response.Code = (int)MessageCode.ActivityNoConfigPrize; return(response); } ItemPackageFrame package = null; prizeList[step - 1] = "2"; info.PrizeRecord = String.Join(",", prizeList); info.UpdateTime = DateTime.Now; int addPoint = 0; int addCoin = 0; foreach (var prize in prizeConfig) { switch (prize.PrizeType) { case 1: addPoint += prize.PrizeCount; break; case 2: addCoin += prize.PrizeCount; break; case 3: if (package == null) { package = ItemCore.Instance.GetPackage(managerId, Entity.Enums.Shadow.EnumTransactionType.EuropeConfig); if (package == null) { return(ResponseHelper.Create <EuropeGambleMatchResponse>(MessageCode.NbNoPackage)); } } package.AddItems(prize.PrizeCode, prize.PrizeCount); break; } } if (addCoin > 0) { ManagerUtil.AddManagerData(manager, 0, addCoin, 0, EnumCoinChargeSourceType.Eruope, ShareUtil.GenerateComb().ToString()); } using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault())) { transactionManager.BeginTransaction(); var code = MessageCode.FailUpdate; do { if (addPoint > 0) { code = PayCore.Instance.AddBonus(managerId, addPoint, EnumChargeSourceType.Europe, ShareUtil.GenerateComb().ToString(), transactionManager.TransactionObject); if (code != MessageCode.Success) { break; } } if (addCoin > 0) { if (!ManagerUtil.SaveManagerData(manager, null, transactionManager.TransactionObject)) { break; } } if (package != null) { if (!package.Save(transactionManager.TransactionObject)) { break; } package.Shadow.Save(); } if (!EuropeGambleMgr.Update(info, transactionManager.TransactionObject)) { break; } code = MessageCode.Success; } while (false); if (code != MessageCode.Success) { transactionManager.Rollback(); response.Code = (int)MessageCode.GamblePayError; return(response); } transactionManager.Commit(); response.Data.Point = PayCore.Instance.GetPoint(managerId); } } catch (Exception ex) { SystemlogMgr.Error("领取竞猜正确活动奖励", ex); response.Code = (int)MessageCode.NbParameterError; } return(response); }
/// <summary> /// 竞猜比赛 /// </summary> /// <param name="managerId"></param> /// <param name="matchId"></param> /// <param name="gambleType"></param> /// <param name="pointType"></param> /// <returns></returns> public EuropeGambleMatchResponse GambleMatch(Guid managerId, int matchId, int gambleType, int pointType) { EuropeGambleMatchResponse response = new EuropeGambleMatchResponse(); try { DateTime date = DateTime.Now; var manager = ManagerCore.Instance.GetManager(managerId); if (manager == null) { response.Code = (int)MessageCode.MissManager; return(response); } var match = EuropeConfig.Instance.GetOneMatch(matchId); if (match == null) { response.Code = (int)MessageCode.NotHaveMatch; return(response); } if (match.States != (int)EnumEuropeStatus.Gamble || match.MatchTime < date)//不可以竞猜 { response.Code = (int)MessageCode.HaveGambleTime; return(response); } var gambleRecord = EuropeGamblerecordMgr.GambleRecord(managerId, matchId); if (gambleRecord != null)//已经竞猜过 { response.Code = (int)MessageCode.HaveGamble; return(response); } var pointConfig = EuropeConfig.Instance.GetGamblePoint(pointType); if (pointConfig == null || pointConfig.VipLevel > manager.VipLevel)//竞猜点卷有误 { response.Code = (int)MessageCode.PointConfigNotHave; return(response); } var managerPoint = PayCore.Instance.GetPoint(managerId); if (managerPoint < pointConfig.Point)//钻石不足 { response.Code = (int)MessageCode.NbPointShortage; return(response); } gambleRecord = new EuropeGamblerecordEntity(0, managerId, matchId, gambleType, pointConfig.Point, 0, false, false, date, date); using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault())) { transactionManager.BeginTransaction(); MessageCode code = MessageCode.FailUpdate; do { if (!EuropeGamblerecordMgr.Insert(gambleRecord, transactionManager.TransactionObject)) { break; } code = PayCore.Instance.GambleTrueMatch(managerId, pointConfig.Point, ShareUtil.GenerateComb().ToString(), transactionManager.TransactionObject); } while (false); if (code != MessageCode.Success) { transactionManager.Rollback(); response.Code = (int)code; return(response); } transactionManager.Commit(); response.Data = new EuropeGambleMatch(); response.Data.Point = managerPoint - pointConfig.Point; } } catch (Exception ex) { SystemlogMgr.Error("欧洲杯竞猜", ex); response.Code = (int)MessageCode.NbParameterError; } return(response); }