/// <summary> /// 分分彩必须保证利润,目前的做法是随机五个号码,计算中奖金额然后保证利润后才开指定数字 /// </summary> /// <param name="lotteryType"></param> /// <param name="issueCode"></param> /// <param name="openResult"></param> public override string Calculate(string lotteryType, string issueCode, string openResult) { //获取本期所有投注数据,进行计算 var source = this.mBetDetailService.GetIssuesBetDetail(lotteryType, issueCode); //获取追号数据,进行计算 var zhuiHaoSource = this.mSysCatchNumService.GetNotCompledCatchNumList(lotteryType, issueCode); if ((source == null || source.Count < 1) && (zhuiHaoSource == null || zhuiHaoSource.Count < 1)) { //没有投注,随机开 openResult = RandomResult(lotteryType); LogManager.Info(string.Format("自主开奖=====没有投注和追号项,随机开奖={0}", openResult)); return(openResult); } int sourceCount = source.Count + zhuiHaoSource.Count; bool isMaxBaseAmt = false;//投注金额是否大于奖金 decimal[] models = { 1M, 0.1M, 0.01M, 0.001M }; //计算本期最低保证利润 var sum = source.Sum(c => c.TotalAmt) + zhuiHaoSource.Sum(c => c.TotalAmt); var total = sum * (1 - ConfigHelper.ProfitMargin) + OpendHistoryLogic.CreateInstance().GetWinMonery(lotteryType);//当期可以释放的金额 LogManager.Error(lotteryType + "利润空间:" + total); List <string> openHistory = new List <string>();//开奖历史记录,开过的不冲去计算 string bettMsg = ""; /***检测代码,正式上线注释**/ Stopwatch stopwatch = new Stopwatch(); //计时 stopwatch.Start(); // 开始监视代码运行时间 /***检测代码,正式上线注释**/ int whileCount = 0; while (true) { string randomOpen = RandomResult(lotteryType); if (openHistory.Contains(randomOpen)) { continue; } openHistory.Add(randomOpen); //投注中奖金额 var bettingWinTotal = 0m; openResult = randomOpen; //string.Join(",", randomOpen.Select(c => c.ToString())); //循环进行计算普通投注中奖金额 foreach (var item in source) { int code = item.PalyRadioCode; item.WinMoney = 0; item.IsMatch = false; Ytg.Scheduler.Comm.Bets.ICalculate calculate = Ytg.Scheduler.Comm.Bets.RadioContentFactory.CreateInstance(code); calculate.Calculate(issueCode, openResult, item); item.OpenResult = openResult; if (item.IsMatch) { item.Stauts = BasicModel.BetResultType.Winning; bettingWinTotal += item.WinMoney; } else { item.Stauts = BasicModel.BetResultType.NotWinning; } isMaxBaseAmt = item.TotalAmt >= calculate.GetBaseAmt(item) * models[item.Model]; } //追号 foreach (var item in zhuiHaoSource) { var betDetail = new BetDetail() { BackNum = item.BackNum, BetContent = item.BetContent, BetCount = item.BetCount, BonusLevel = item.BonusLevel, IsMatch = item.IsMatch, IssueCode = item.IssueCode, Model = item.Model, Multiple = item.Multiple, OpenResult = item.OpenResult, PalyRadioCode = item.PalyRadioCode, PrizeType = item.PrizeType, TotalAmt = item.TotalAmt, UserId = item.UserId, WinMoney = item.WinMoney, }; ICalculate calculate = RadioContentFactory.CreateInstance(betDetail.PalyRadioCode); calculate.Calculate(issueCode, openResult, betDetail); item.OpenResult = openResult; item.WinMoney = betDetail.WinMoney; if (betDetail.IsMatch) { bettingWinTotal += betDetail.WinMoney; } isMaxBaseAmt = item.TotalAmt >= calculate.GetBaseAmt(betDetail); } LogManager.Error(string.Format("尝试自主开奖 issueCode:{0} bettingWinTotal:{1} total:{2} isMaxBaseAmt:{3} sourceCount:{4} whileCount:{5} lotteryType:{6}", issueCode, bettingWinTotal, total, isMaxBaseAmt, source, whileCount, lotteryType)); whileCount++; if ( (total - bettingWinTotal > 0) || (isMaxBaseAmt && sourceCount < 1) || (whileCount > 50 && sum >= bettingWinTotal)) //符合指定利润,开奖 { //=开奖信息=返钱:33218.00000000RMB 投注总额:4250.0000RMB 最低40%利润:-21768.00000000RMB bettMsg = "返钱:" + bettingWinTotal + "RMB 投注总额:" + sum + "RMB 最低40%利润:" + (total - bettingWinTotal) + "RMB wileCount" + whileCount + " " + lotteryType + " \t\n"; //修改期数 //处理开奖逻辑 普通投注 CalculateBetting(source, issueCode, openResult); //追号 CalculateCatchNums(zhuiHaoSource, issueCode, openResult); OpendHistoryLogic.CreateInstance().PutLotteryData(lotteryType, sum, bettingWinTotal); LogManager.Error(string.Format("自主开奖成功,开奖结果={0}=========开奖信息={1}", openResult, bettMsg)); break; } if (whileCount > 50) { sum += 500; } } /***检测代码,正式上线注释**/ TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 double milliseconds = timespan.TotalMilliseconds; // 总毫秒数 stopwatch.Stop(); /***检测代码,正式上线注释**/ //bettMsg += "分分彩:" + lotteryType + " 期数:" + issueCode + " 总毫秒数:" + milliseconds; // LogManager.Error(bettMsg); return(openResult); }