/// <summary> /// 负责将对象同步至数据库 /// </summary> private void UpdateBetDetail(object param) { /****初始化开始**/ IDbContextFactory factory = new DbContextFactory(); Ytg.Comm.IHasher hasher = new Ytg.Comm.Hasher(); var sysUser = new SysUserService(new Repo <SysUser>(factory), hasher); var sysUserBalanceService = new SysUserBalanceService(new Repo <SysUserBalance>(factory), hasher, sysUser); var sysUserBalanceDetailService = new SysUserBalanceDetailService(new Repo <SysUserBalanceDetail>(factory), sysUserBalanceService); var rebateHelper = new Service.Logic.RebateHelper(sysUser, sysUserBalanceService, sysUserBalanceDetailService); /****初始化结束**/ while (true) { var betDetail = this.Dequeue(); try { if (null == betDetail) { LogManager.Info("追号同步数据队列中暂无数据,开始休眠一秒!"); System.Threading.Thread.Sleep(1000);//休眠一秒 continue; } //计算返点 游戏返点 rebateHelper.BettingCalculate(betDetail.CatchDetail.PrizeType, betDetail.CatchDetail.UserId, betDetail.CatchNumIssue.TotalAmt, betDetail.CatchNumIssue.CatchNumIssueCode, rebateHelper.GetRadioMaxRemo(betDetail.CatchDetail.PalyRadioCode, betDetail.CatchDetail.BonusLevel)); if (betDetail.CatchNumIssue.IsMatch)//是否中奖 { rebateHelper.UpdateUserBanance(betDetail.CatchDetail.UserId, betDetail.CatchNumIssue.WinMoney, TradeType.奖金派送, betDetail.CatchNumIssue.CatchNumIssueCode, 0); } if (null != betDetail.ExitCatNumIssues) { //是否有结束追号的期数 var exitCount = betDetail.ExitCatNumIssues.Count; for (var i = 0; i < exitCount; i++) { var exit = betDetail.ExitCatNumIssues[i]; //if (betDetail.CatchDetail.PrizeType == 1) // rebateHelper.BettingCannelIssue(betDetail.CatchDetail.UserId, exit.TotalAmt, exit.CatchNumIssueCode, rebateHelper.GetRadioMaxRemo(betDetail.CatchDetail.PalyRadioCode, betDetail.CatchDetail.BonusLevel));//处理返点 //else rebateHelper.UpdateUserBanance(betDetail.CatchDetail.UserId, exit.TotalAmt, TradeType.追号返款, exit.CatchNumIssueCode, 0); } } LogManager.Info("修改追号信息成功!" + betDetail.ToString()); } catch (Exception ex) { LogManager.Error("修改追号用户信息异常,投注信息:" + betDetail.ToString() + "\n", ex); } } }
protected readonly MessageService mMessageService; //消息处理类 public BetDetailsCalculate_Auto() { IDbContextFactory factory = new DbContextFactory(); this.mBetDetailService = new BetDetailService(new Repo <BetDetail>(factory)); this.mSysCatchNumService = new SysCatchNumService(new Repo <CatchNum>(factory)); this.mSysCatchNumIssueService = new SysCatchNumIssueService(new Repo <CatchNumIssue>(factory)); Ytg.Comm.IHasher hasher = new Ytg.Comm.Hasher(); var sysUser = new SysUserService(new Repo <SysUser>(factory), hasher); mMessageService = new MessageService(new Repo <Message>(factory)); this.mSysUserBalanceService = new SysUserBalanceService(new Repo <SysUserBalance>(factory), hasher, sysUser); this.mSysUserBalanceDetailService = new SysUserBalanceDetailService(new Repo <SysUserBalanceDetail>(factory), this.mSysUserBalanceService); mRebateHelper = new Service.Logic.RebateHelper(sysUser, this.mSysUserBalanceService, this.mSysUserBalanceDetailService); }
/// <summary> /// 负责将对象同步至数据库 /// </summary> private void UpdateBetDetail(object param) { /****初始化开始**/ IDbContextFactory factory = new DbContextFactory(); Ytg.Comm.IHasher hasher = new Ytg.Comm.Hasher(); var sysUser = new SysUserService(new Repo <SysUser>(factory), hasher); var sysUserBalanceService = new SysUserBalanceService(new Repo <SysUserBalance>(factory), hasher, sysUser); var sysUserBalanceDetailService = new SysUserBalanceDetailService(new Repo <SysUserBalanceDetail>(factory), sysUserBalanceService); var rebateHelper = new Service.Logic.RebateHelper(sysUser, sysUserBalanceService, sysUserBalanceDetailService); var buyTogetherService = new BuyTogetherService(new Repo <BuyTogether>(factory)); /****初始化结束**/ while (true) { var betDetail = this.Dequeue(); try { if (null == betDetail) { LogManager.Info("同步数据队列中暂无数据,开始休眠一秒!"); System.Threading.Thread.Sleep(1000);//休眠一秒 continue; } if (betDetail.IsMatch) { if (betDetail.IsBuyTogether == 0) { //代购,使用原来方式进行处理 rebateHelper.UpdateUserBanance(betDetail.UserId, betDetail.WinMoney, TradeType.奖金派送, betDetail.BetCode, 0); } else { var source = buyTogetherService.GetForBettid(betDetail.Id); if (source != null && source.Count > 0) { var winMonery = betDetail.WinMoney;//总中奖总金额 var totalMonery = betDetail.TotalAmt; decimal bili = 0m; Console.WriteLine("处理合买/投注期数=" + betDetail.BetCode + "中奖金额=" + winMonery + " 投注金额=" + totalMonery); foreach (var item in source) { var subscription = item.Subscription; bili = subscription / totalMonery; var itemWinMonery = bili * winMonery; LogManager.Info("认购金额:" + subscription + "分配奖金:" + itemWinMonery); rebateHelper.UpdateUserBanance(betDetail.UserId, itemWinMonery, TradeType.奖金派送, item.BuyTogetherCode, 0); System.Threading.Thread.Sleep(1); //修改中奖金额和状态 item.WinMonery = itemWinMonery; item.Stauts = BetResultType.Winning; LotteryIssuesData.UpdateBuyTogerher(betDetail.Id, 1, itemWinMonery); } //处理自身用户奖金 bili = betDetail.Subscription / totalMonery; var usWinMonery = bili * winMonery; rebateHelper.UpdateUserBanance(betDetail.UserId, usWinMonery, TradeType.奖金派送, betDetail.BetCode, 0); } } } //线程同步计算返点 rebateHelper.BettingCalculate(betDetail.PrizeType, betDetail.UserId, betDetail.TotalAmt, betDetail.BetCode, rebateHelper.GetRadioMaxRemo(betDetail.PalyRadioCode, betDetail.BonusLevel)); LogManager.Info("修改投注信息成功!" + betDetail.ToString()); } catch (Exception ex) { LogManager.Error("修改投注用户信息异常,投注信息:" + betDetail.ToString() + "\n", ex); } } }