/// <summary> /// 追号投注 /// </summary> private bool CatchBetting(SysUser user, BettingDTO dto, ref ApiCode errorType, int lotteryid, bool ishtml = false) { var details = dto.BetDetails; //获取用户余额 decimal userAmt = 0; var userbalance = this.mSysUserBalanceService.GetUserBalance(user.Id); if (null != userbalance) { userAmt = userbalance.UserAmt;//获取用户余额 } int index = 0; foreach (var detail in details) { var radioContent = Ytg.Scheduler.Comm.Bets.RadioContentFactory.CreateInstance(detail.PalyRadioCode); if (null == radioContent) { errorType = ApiCode.Exception;//服务器错误 return(false); } if (ishtml) { detail.BetContent = radioContent.HtmlContentFormart(detail.BetContent); } //计算总注数 int betCount = radioContent.TotalBetCount(new BetDetail() { BetContent = detail.BetContent }); if (betCount < 0) //超过指定注数,不允许投注 { errorType = ApiCode.Fail; //服务器错误 return(false); } //验证投注时间和当前投注期数的时间差,不在时间内,不允许投注 var issueInfo = this.mLotteryIssueService.Get(lotteryid, detail.IssueCode); if (issueInfo == null || issueInfo.EndSaleTime.Value < DateTime.Now) { errorType = ApiCode.Empty; return(false); } decimal detailMonery = CalculateMonery(betCount, detail.Model, (int)detail.Multiple, lotteryid); var playRadio = Ytg.Service.Lott.BaseDataCatch.GetPalyTypeRadio().Where(radio => radio.RadioCode == detail.PalyRadioCode).FirstOrDefault(); if (playRadio == null) { errorType = ApiCode.Fail;//服务器错误 return(false); } //追号最大倍数 int maxMulite = dto.CatchDtos.Max(x => x.Multiple); int oldMulite = (int)detail.Multiple; detail.Multiple = maxMulite; //验证可能中奖的最大金额,若超过该限制,则不允许投注 if (WinMoneryHelper.GetAutoWinMonery(detail, this.LoginUser) > WinMoneryHelper.GetMaxReboMonery()) { errorType = ApiCode.NotScope;//超过限额 return(false); } detail.Multiple = oldMulite;//还原初始倍数 //追号 string catchNumCode = "c" + Utils.BuilderNum(); var fstCode = string.Empty; //计算本次追号需用的总金额 decimal sumMonery = CatchIssue(catchNumCode, detailMonery, dto.CatchDtos, lotteryid, ref fstCode); if (userAmt < sumMonery)//余额不够本次 { errorType = ApiCode.NotEnough; return(false); } userAmt -= sumMonery; var bet = new CatchNum() { CatchNumCode = catchNumCode, BetContent = detail.BetContent, Model = detail.Model, PalyRadioCode = detail.PalyRadioCode, PrizeType = detail.PrizeType, BackNum = (decimal)(detail.PrizeType == 0 ? user.Rebate : 0), UserId = user.Id, IsAutoStop = dto.IsAutoStop, Stauts = CatchNumType.Runing, SumAmt = sumMonery, BeginIssueCode = fstCode, CatchIssue = dto.CatchDtos.Count, BonusLevel = LoginUser.PlayType == UserPlayType.P1800 ? 1800 : 1700, LotteryCode = this.LotteryCode, BetCount = betCount, PostionName = detail.PostionName, HasState = betCount <= detail.MaxBetCount ? 1 : 0 }; //插入追号记录 this.mSysCatchNumService.Create(bet); //保存用户余额 // userbalance.UserAmt = userAmt - sumMonery; //投注消费记录s // this.mSysUserBalanceDetailService.Create(CreateUserBalanceDetial(user.Id, -sumMonery, TradeType.追号扣款, userAmt,bet.CatchNumCode)); //返点消费记录 //不计算返点 //if (detail.PrizeType == 1) // this.mRebateHelper.CatchCalculate(userId, sumMonery, bet.CatchNumCode, mRebateHelper.GetRadioMaxRemo(bet.PalyRadioCode, bet.BonusLevel)); this.mSysUserBalanceService.UpdateUserBalance(CreateUserBalanceDetial(user.Id, -sumMonery, TradeType.追号扣款, userAmt, bet.CatchNumCode), -sumMonery); this.mBetDetailService.Save();//保存状态 //修改账变 index++; } return(true); }
private bool DefaultDetails(SysUser user, List <BetDetailDTO> details, ref ApiCode errorType, int lotteryid, bool ishtml = false) { int index = 0; //获取用户余额 //decimal userAmt = 0; //var userbalance = this.mSysUserBalanceService.GetUserBalance(user.Id); //if (null != userbalance) // userAmt = userbalance.UserAmt;//获取用户余额 foreach (var detail in details) { var radioContent = Ytg.Scheduler.Comm.Bets.RadioContentFactory.CreateInstance(detail.PalyRadioCode); if (null == radioContent) { errorType = ApiCode.Exception;//服务器错误 } if (ishtml) { detail.BetContent = radioContent.HtmlContentFormart(detail.BetContent); } if (string.IsNullOrEmpty(detail.BetContent)) { continue; } //验证投注时间和当前投注期数的时间差,不在时间内,不允许投注 //var issueInfo=this.mLotteryIssueService.Get(lotteryid,detail.IssueCode); //if (issueInfo == null // || issueInfo.EndSaleTime.Value < DateTime.Now) //{ // errorType = ApiCode.Empty; // return false; //} // //计算总注数 int betCount = radioContent.TotalBetCount(new BetDetail() { BetContent = detail.BetContent }); if (betCount < 0) //超过指定注数,不允许投注 { errorType = ApiCode.Fail; //服务器错误 非法请求 return(false); } //var playRadio = Ytg.Service.Lott.BaseDataCatch.GetPalyTypeRadio().Where(radio => radio.RadioCode == detail.PalyRadioCode).FirstOrDefault(); //if (playRadio == null) //{ // errorType = ApiCode.Fail;//服务器错误 // return false; //} //计算本注需用金额 decimal sumMonery = CalculateMonery(betCount, detail.Model, (int)detail.Multiple, lotteryid); if (lotteryid == 21)//六合彩 { detail.Multiple = 1; } //验证可能中奖的最大金额,若超过该限制,则不允许投注 if (WinMoneryHelper.GetAutoWinMonery(detail, this.LoginUser) > WinMoneryHelper.GetMaxReboMonery()) { errorType = ApiCode.NotScope;//超过限额 return(false); } //if (userAmt < sumMonery)//余额不够本次 //{ // errorType = ApiCode.NotEnough;//余额不够本次 // return false; //} //userAmt -= sumMonery; var bet = new BetDetail() { BetCode = "b" + Utils.BuilderNum(), IsMatch = false, IssueCode = detail.IssueCode, BetContent = detail.BetContent, Model = detail.Model, Multiple = (int)detail.Multiple, PalyRadioCode = detail.PalyRadioCode, PrizeType = detail.PrizeType, UserId = user.Id, TotalAmt = sumMonery, LotteryCode = this.LotteryCode, BetCount = betCount, BackNum = (decimal)(detail.PrizeType == 0 ? user.Rebate : 0), BonusLevel = LoginUser.PlayType == UserPlayType.P1800 ? 1800 : 1700, PostionName = detail.PostionName, HasState = betCount <= detail.MaxBetCount ? 1 : 0 }; /**最新投注方法 提高性能*/ int state = 0; var userAmt = this.mBetDetailService.AddBetting(bet, CreateUserBalanceDetial(user.Id, -sumMonery, TradeType.投注扣款, 0, bet.BetCode), lotteryid, ref state); if (state == 1) {//超过投注时间,不允许投注 errorType = ApiCode.Empty; return(false); } else if (state == 2) { //用户余额不够 errorType = ApiCode.NotEnough;//余额不够本次 return(false); } else { //提交成功 } /**最新投注方法*/ //this.mBetDetailService.Create(bet); //保存用户余额 // userbalance.UserAmt = userAmt - sumMonery; //投注消费记录s // this.mSysUserBalanceDetailService.Create(CreateUserBalanceDetial(user.Id, -sumMonery, TradeType.投注扣款, userAmt, bet.BetCode)); //返点消费记录 //不在投注时计算返点,hqh 2015/04/17 by update //if (bet.PrizeType == 1) // this.mRebateHelper.BettingCalculate(userId, sumMonery, bet.BetCode); //this.mSysUserBalanceService.UpdateUserBalance(CreateUserBalanceDetial(user.Id, -sumMonery, TradeType.投注扣款, userAmt, bet.BetCode), -sumMonery); //this.mBetDetailService.Save(); index++; } return(true); }