public static object GetAgentBackMoney(decimal percent) { var query = (from a in LotteryOpenTool_11x5.LpList() select new { a.LotteryPlayName, a.PayBack, PayBack2 = Math.Ceiling(GetAgentBackMoney_11x5(a.PayBack, percent) * 1000) / 1000, }).ToList(); return(query); }
public static decimal GetAgentBackMoney_11x5(int code, decimal percent) { var key = code + "," + percent; if (!AgentBackMoneyDic2_11x5.Keys.Contains(key)) //若不再字典则计算和添加 { var j = LotteryOpenTool_11x5.LpList().FirstOrDefault(n => n.BetPlayTypeCode == code); if (j == null) { return(0); } AgentBackMoneyDic2_11x5.Add(key, GetAgentBackMoney_11x5(j.PayBack, percent)); } return(AgentBackMoneyDic2_11x5[key]); }
public static List <LotteryPlay> GetLotteryPlayList(string LotteryType) { List <LotteryPlay> list = new List <LotteryPlay>(); switch (LotteryType) { case "ssc": list = LotteryInfo_SSC.LpList(); break; case "11x5": list = LotteryOpenTool_11x5.LpList(); break; case "dpc": list = LotteryOpenTool_3D.LpList(); break; } return(list); }
/// <summary> /// 获取返点奖金 /// </summary> /// <param name="BetPlayTypeCode"></param> /// <param name="percent"></param> /// <returns></returns> public List <string> GetAgentBackMoneyByCode(int BetPlayTypeCode, decimal percent, string lotteryType) { List <string> list = new List <string>(); switch (lotteryType) { case "ssc": list.Add(AgentCalculateTool.GetAgentBackMoney_SSC(BetPlayTypeCode, percent) + "-0%"); list.Add(LotteryInfo_SSC.LpList()[BetPlayTypeCode - 1].PayBack + "-" + percent + "%"); break; case "11x5": list.Add(AgentCalculateTool.GetAgentBackMoney_11x5(BetPlayTypeCode, percent) + "-0%"); list.Add(LotteryOpenTool_11x5.LpList()[BetPlayTypeCode - 1].PayBack + "-" + percent + "%"); break; case "dpc": list.Add(AgentCalculateTool.GetAgentBackMoney_3D(BetPlayTypeCode, percent) + "-0%"); list.Add(LotteryOpenTool_3D.LpList()[BetPlayTypeCode - 1].PayBack + "-" + percent + "%"); break; } return(list); }
/// <summary> /// 进行开奖 /// </summary> /// <param name="loId"></param> /// <param name="isFixed">固定开奖</param> /// <param name="NoStrs"></param> public void OpeningNo(long loId, bool isXZ, bool isYK, bool isFixed, params string[] NoStrs) { using (e = new LotteryAPPEntities()) { var open = e.LotteryOpen.Where(n => n.Id == loId).FirstOrDefault(); if (open.OpenStatus == (int)Enum_LotteryOpenStatus.Schedule) { open.OpenStatus = (int)Enum_LotteryOpenStatus.Opening;//设置此期为开奖中 open.OpenCode = open.ScheduleOpenCode; //e.SaveChanges(); } //由最大返奖比金额开始判断 var bList = (from b in e.BetInfo where b.LotteryOpenInfo.LotteryId == open.LotteryId && b.LotteryOpenInfo.Expect == open.Expect orderby b.MaxBackMoney descending select b).ToList(); //总投注金额 var betTotalMoney = bList.Sum(n => n.BetMoney); //奖金池金额 var pool = e.LotteryPrizePool.FirstOrDefault(n => n.LotteryId == open.LotteryId); //总返点金额 var query = (from a in e.AccountBusiness from b in e.BetInfo where b.LotteryOpenInfo.LotteryId == open.LotteryId && b.LotteryOpenInfo.Expect == open.Expect && a.BusinessTypeId == (int)Enum_AccountBusinessType.BackPercent && a.EventId == b.Id && a.PayIn.HasValue select a); //总返点金额 var abTotalMoney = query.Count() > 0 ? query.Sum(n => n.PayIn.Value) : 0; //总返奖金额 decimal backTotalMoney = 0; //开奖号int型集合 var nList = open.ScheduleOpenCode.Split(',').Select(n => Convert.ToInt32(n)).ToList(); #region 开奖 if (isXZ)//规则开奖 { //var pp = e.BetInfo.Where(n =>n.LotteryOpenId != loId&&n.ResultType==(int)Enum_ResultType.Wait).ToList(); //var pool = pp.Sum(n => n.BetMoney) - pp.Sum(n => n.BackMoney); if (bList.Count > 0) { var poolMoney = pool == null ? 0 : pool.PoolMoney; List <int> OpenNumInOnce = new List <int>(); //当期已重摇号组合索引 var index = AllCodeList.FindIndex(n => n == open.ScheduleOpenCode); var cList = new List <int>(); //所有组合摇奖号的索引 for (int i = 0; i < AllCodeList.Count; i++) { cList.Add(i); } #region 进行限制开奖 for (int i = 0; true; i++) { if (!OpenNumInOnce.Contains(index)) { if (i > 0)//预开奖号不处理 { nList = GetAllCodeList()[index].Split(',').Select(n => Convert.ToInt32(n)).ToList(); } if (LotteryOpenTool_11x5.isOutBetMoney(bList, nList, isXZ, betTotalMoney, abTotalMoney, poolMoney, out backTotalMoney)) //若超额则保存此次摇号并重摇 { OpenNumInOnce.Add(index); //添加索引至已摇 cList.Remove(index); //删除该索引 index = random.Next(0, cList.Count); //从剩余索引号中随机取一个 open.RerollCount++; //重摇次数+1 } else { break;//若不超额则退出循环 } } else { index = random.Next(0, GetAllCodeList().Count); //存在同号直接重新摇 } if (OpenNumInOnce.Count >= 55440) //最多跑A(5,11):55440次 { open.RerollCount = OpenNumInOnce.Count; break; } } #endregion open.OpenCode = GetAllCodeList()[index]; } } else if (isYK)//预开号开奖 { LotteryOpenTool_11x5.isOutBetMoney(bList, nList, isXZ, 0, 0, 0, out backTotalMoney); } else if (isFixed)//固定开奖 { nList.Clear(); foreach (var item in NoStrs) { int no = 0; if (int.TryParse(item, out no) && no >= 1 && no <= 11) { nList.Add(Convert.ToInt32(item)); } else { nList.Add(-1); } } GetOpenNum_IntList1(nList); open.OpenCode = string.Format("{0},{1},{2},{3},{4}", NumList11x5_Normal[nList[0] - 1], NumList11x5_Normal[nList[1] - 1], NumList11x5_Normal[nList[2] - 1], NumList11x5_Normal[nList[3] - 1], NumList11x5_Normal[nList[4] - 1]); LotteryOpenTool_11x5.isOutBetMoney(bList, nList, isXZ, 0, 0, 0, out backTotalMoney); } if (bList.Count > 0) { bList.ForEach(n => n.ResultType = (int)Enum_ResultType.Backing); } #endregion open.OpenStatus = (int)Enum_LotteryOpenStatus.Succeed;//开奖期改为已开 var dt = EntitiesTool.GetDateTimeNow(e); open.OpenTime = dt; #region 更新开奖表LotteryOpenInfo var f = e.LotteryOpenInfo.FirstOrDefault(n => n.LotteryId == open.LotteryId && n.Expect == open.Expect); if (f != null) { f.OpenTime = dt; f.OpenCode = open.OpenCode; } else { e.LotteryOpenInfo.Add(new LotteryOpenInfo { Expect = open.Expect, LotteryId = open.LotteryId, OpenCode = open.OpenCode, OpenDate = open.ScheduleOpenTime.Date, OpenTime = dt, }); } #endregion #region 更新奖金池 if (e.LotteryPrizePoolInfo.FirstOrDefault(n => n.LotteryOpenId == open.Id) == null) { var p = new LotteryPrizePoolInfo { LotteryOpenId = open.Id, TotalAgenBack = abTotalMoney, TotalBack = backTotalMoney, TotalBet = betTotalMoney, Profit = betTotalMoney - backTotalMoney - abTotalMoney, }; e.LotteryPrizePoolInfo.Add(p);//本期利润情况 //var pool = e.LotteryPrizePool.FirstOrDefault(n => n.LotteryId == open.LotteryId); if (pool == null) { e.LotteryPrizePool.Add(new LotteryPrizePool { LotteryId = open.LotteryId, PoolMoney = p.Profit, }); } else { pool.PoolMoney += p.Profit; } } #endregion using (tran = new TransactionScope()) { e.SaveChanges(); tran.Complete(); } //var betList = e.BetInfo.Where(n => n.LotteryOpenId == loId).ToList();//当期投注信息 //betList.ForEach(n => n.ResultType = (int)Enum_ResultType.Backing);//投注单改为返奖中 //上一期 //下一期 //var query = e.LotteryOpen.Where(n => n.Id == open.Id + 1).FirstOrDefault();//获取新一期 //if (query != null) //{ // query.OpenStatus = (int)Enum_LotteryOpenStatus.Next;//修改新一期为待开 //} } }
/// <summary> /// 开奖返奖&修改下注状态 /// </summary> /// <param name="loId"></param> /// <returns></returns> public void BackWinMoney(int?LotteryId, string Except) { try { using (e = new LotteryAPPEntities()) { var dt = EntitiesTool.GetDateTimeNow(e); //获取待开奖下注信息 var query = (from a in e.LotteryOpenInfo from b in e.BetInfo where b.ResultType == (int)Enum_ResultType.Wait && a.LotteryId == b.LotteryId && a.Expect == b.LotteryExcept select b); if (LotteryId.HasValue) { query = query.Where(n => n.LotteryId == LotteryId.Value); } if (!string.IsNullOrEmpty(Except)) { query = query.Where(n => n.LotteryExcept == Except); } using (tran = new TransactionScope()) { var betList = query.ToList(); if (betList.Count > 0) { foreach (var item in betList.GroupBy(n => new { n.LotteryId, n.LotteryExcept })) { var lottery = EntitiesTool.GetLotteryList().FirstOrDefault(n => n.Id == item.Key.LotteryId); var open = e.LotteryOpenInfo.FirstOrDefault(n => n.LotteryId == item.Key.LotteryId && n.Expect == item.Key.LotteryExcept); //获取开奖期信息 var openCode = open.OpenCode.Split(',').Select(n => Convert.ToInt32(n)).ToList(); //获取开奖号 var b = betList.Where(n => n.LotteryId == item.Key.LotteryId && n.LotteryExcept == item.Key.LotteryExcept).ToList(); //获取当期投注信息 decimal backMoney = 0; switch (lottery.LotteryType) { case "ssc": LotteryOpenTool_SSC.isOutBetMoney(b, openCode, false, 0, 0, 0, out backMoney); break; case "11x5": LotteryOpenTool_11x5.isOutBetMoney(b, openCode, false, 0, 0, 0, out backMoney); break; } foreach (var BetInfo in betList.Where(n => n.LotteryId == item.Key.LotteryId && n.LotteryExcept == item.Key.LotteryExcept)) { #region 返点 var pList = EntitiesTool.GetAllParentAccount(BetInfo.AccountId, e); //上级名单(含自己) var account = e.Accounts.FirstOrDefault(n => n.Id == BetInfo.AccountId); if (BetInfo.IsGetBackPercent) //如果要返点 { var ab = new AccountBusiness { AccountId = BetInfo.AccountId, BusinessTypeId = (int)Enum_AccountBusinessType.BackPercent, CreateTime = dt, EventId = BetInfo.Id, PayBefore = account.AccountBalance, PayIn = (BetInfo.BetMoney * BetInfo.GetBackPercent / 100), }; ab.PayAfter = account.AccountBalance + ab.PayIn.Value; account.AccountBalance = ab.PayAfter; e.AccountBusiness.Add(ab);//返点业务单 } //单个玩法投注>0.2元,上级产生返点(固定等级差返点) if (BetInfo.BetMoney >= new decimal(0.2) && pList.Count > 1) { for (int i = 1; i < pList.Count; i++) { var ab = new AccountBusiness { AccountId = pList[i].Id, BusinessTypeId = (int)Enum_AccountBusinessType.BackPercent, CreateTime = dt, EventId = BetInfo.Id, PayBefore = pList[i].AccountBalance, PayIn = lottery.LotteryType == "11x5" ? BetInfo.BetMoney * (pList[i].AgentPercent11X5 - pList[i - 1].AgentPercent11X5) / 100 : BetInfo.BetMoney * (pList[i].AgentPercentSSC - pList[i - 1].AgentPercentSSC) / 100, }; ab.PayAfter = pList[i].AccountBalance + ab.PayIn.Value; pList[i].AccountBalance = ab.PayAfter; e.AccountBusiness.Add(ab);//返点业务单 } } #endregion } } betList.ForEach(n => n.ResultType = (int)Enum_ResultType.Backing); // 未中奖号码状态修改 var betList1 = betList.Where(n => n.ResultType == (int)Enum_ResultType.Backing && n.BackMoney <= 0).ToList();//所有未中奖 if (betList1.Count > 0) { betList1.ForEach(n => n.ResultType = (int)Enum_ResultType.False); betList1.ForEach(n => n.BackTime = dt); } if (betList1.Count != betList.Count) { //中奖停止追号 var zList = betList.Where(n => n.ResultType == (int)Enum_ResultType.Backing && n.BackMoney > 0).Select(n => n.AddNumNo).ToList(); var zBetList = e.BetInfo.Where(n => n.ResultType == (int)Enum_ResultType.Wait && n.IsWinCancel == true && zList.Contains(n.AddNumNo)).ToList(); zBetList.ForEach(n => n.ResultType = (int)Enum_ResultType.WinThenCancel); } e.SaveChanges(); tran.Complete(); } } } } catch (Exception ex) { throw ex; } }