/// <summary>
 /// 初始化开奖信息(一期)
 /// </summary>
 public void InitialTodayInfo(Lotterys Lottery, DateTime dt)
 {
     using (e = new LotteryAPPEntities())
     {
         var dtS   = dt.Date.AddHours((double)Lottery.TimeStart.Value);
         var dtE   = dtS;//dtS.AddHours(Lottery..Value);
         var query = e.LotteryOpen.Count(n => n.LotteryId == Lottery.Id && (n.ScheduleOpenTime > dtS && n.ScheduleOpenTime <= dtE));
         if (query == 0)
         {
             //int AddZero = Lottery.BetweenMinute == 1 ? 4 : 3;
             using (tran = new TransactionScope())
             {
                 for (int i = 1; true; i++)
                 {
                     var ot = dtS.AddMinutes(i * (int)Lottery.BetweenMinute.Value);
                     if (ot > dtE)//超期退出循环
                     {
                         break;
                     }
                     var code = GetAllCodeList()[random.Next(0, GetAllCodeList().Count)];
                     var open = new LotteryOpen
                     {
                         LotteryId        = Lottery.Id,
                         OpenStatus       = (int)Enum_LotteryOpenStatus.Schedule,
                         ScheduleOpenCode = code, //预先开出随机号
                         ScheduleOpenTime = ot,   //间隔多少时间一期
                         Expect           = ot.Date.ToString("yyyyMMdd") + MyTool.AddZeroStr(i, Lottery.ExceptLength.HasValue? Lottery.ExceptLength.Value:0),
                         ExpectDate       = ot.Date.ToString("yyyyMMdd"),
                         RerollCount      = 0,
                     };
                     e.LotteryOpen.Add(open);
                     var info = new LotteryOpenInfo
                     {
                         Expect    = open.Expect,
                         LotteryId = open.LotteryId,
                         OpenCode  = "",
                         OpenDate  = open.ScheduleOpenTime.Date,
                         OpenTime  = open.ScheduleOpenTime,
                     };
                     e.LotteryOpenInfo.Add(info);
                 }
                 e.SaveChanges();
                 tran.Complete();
             }
         }
     }
 }
 //public object GetBetHistory(int AccountId,int count)
 //{
 //    using (e = new LotteryAPPEntities())
 //    {
 //        var query = e.BetInfo.Where(n => n.AccountId == AccountId).OrderByDescending(n => n.Id).ToList().Select(n => new
 //        {
 //            n.BackMoney,
 //            n.BetMoney,
 //            BetNum = MyTool.GetBet_danshuang(n.BetNum, n.BetPlayTypeCode),
 //            BetPlayTypeCode = LotteryOpenTool.LpList().FirstOrDefault(w => w.BetPlayTypeCode == n.BetPlayTypeCode).LotteryPlayName,
 //            n.BetTimes,
 //            n.BetUnit,
 //            n.CreateTime,
 //            n.WinMoney,
 //            n.WinUnit,
 //            OpenNo = MyTool.AddZeroStr(n.LotteryOpenInfo.Expect, 3),
 //            OpenNum = n.ResultType > 1 ? "" : MyTool.AddZeroStr(n.LotteryOpenInfo.OpenCode),
 //            Enum_ResultType = MyTool.GetBetResultType(n.ResultType),
 //        });
 //        if(count>=0)
 //        {
 //            query = query.Take(count);
 //        }
 //        return query.ToList();
 //    }
 //}
 public object GetBetHistory(int AccountId, Lotterys lottery, DateTime DtLoad)
 {
     using (e = new LotteryAPPEntities())
     {
         var query = e.BetInfo.Where(n => n.AccountId == AccountId && n.LotteryOpenInfo.LotteryId == lottery.Id && n.CreateTime >= DtLoad).OrderByDescending(n => n.Id).ToList().Select(n => new
         {
             n.BackMoney,
             n.BetMoney,
             BetNum          = lottery.LotteryType == "11x5" ? MyTool.GetBet_ZH_11X5(n.BetNum, n.BetPlayTypeCode) : n.BetNum,
             BetPlayTypeCode = MyTool.GetLotteryPlayList(lottery.LotteryType)[n.BetPlayTypeCode - 1].LotteryPlayName,
             n.BetTimes,
             n.BetUnit,
             n.CreateTime,
             n.WinMoney,
             n.WinUnit,
             OpenNo = MyTool.AddZeroStr(n.LotteryOpenInfo.Expect, 3),
             //OpenNum = n.ResultType==2 ? "" : n.LotteryOpenInfo.OpenCode,
             OpenNum         = n.LotteryOpenInfo.OpenCode,
             Enum_ResultType = EnumTool.GetBetResultType(n.ResultType),
         });
         return(query.ToList());
     }
 }
Exemplo n.º 3
0
 //TransactionScope tran;
 /// <summary>
 /// 初始化开奖信息
 /// </summary>
 public void InitialTodayInfo(Lotterys Lottery)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt    = EntitiesTool.GetDateTimeNow(e);
         var dtDel = dt.AddDays(-1);
         e.LotteryOffcialSchedule.RemoveRange(e.LotteryOffcialSchedule.Where(n => n.LotteryId == Lottery.Id && n.ScheduleOpenTime <= dtDel));//删除前一天的时刻表
         var sp  = Lottery.TimeStart.Value.ToString().Split('.');
         var dtS = dt.Date.AddHours(Convert.ToInt32(sp[0]));
         if (sp.Length > 1)
         {
             dtS = dtS.AddMinutes(Convert.ToInt32(sp[1]));
         }
         var dtE   = dtS.AddDays(3);
         var query = e.LotteryOffcialSchedule.Where(n => n.LotteryId == Lottery.Id && n.ScheduleOpenTime >= dtS && n.ScheduleOpenTime < dtE).ToList();
         if (query.Count >= Lottery.ExceptOneDay * 2)
         {
             return;//至少保留两天预设期
         }
         int j        = -1;
         var sdt      = dtS;
         var openList = new List <LotteryOffcialSchedule>();
         if (Lottery.LotteryCode == "cqssc")
         {
             for (int i = 0; i < Lottery.ExceptOneDay * 3; i++)
             {
                 if (i > 0 && i % Lottery.ExceptOneDay.Value == 0)
                 {
                     dtS = dtS.AddDays(1);
                     sdt = dtS;
                     j   = -1;
                 }
                 j++;
                 var ex = j + 24 > 120 ? j + 24 - 120 : j + 24;
                 if (ex == 1)
                 {
                     dt = dt.AddDays(1);
                 }
                 var expect = dt.Date.ToString("yyyyMMdd") + MyTool.AddZeroStr(ex, Lottery.ExceptLength.Value);
                 if (query.Exists(n => n.Expect == expect))
                 {
                     continue;
                 }
                 if (ex >= 97 || ex <= 23)
                 {
                     sdt = sdt.AddMinutes(5);
                 }
                 else if (ex > 24)
                 {
                     sdt = sdt.AddMinutes((int)Lottery.BetweenMinute.Value);
                 }
                 var open = new LotteryOffcialSchedule
                 {
                     LotteryId        = Lottery.Id,
                     ScheduleOpenTime = sdt,//间隔多少时间一期
                     Expect           = expect,
                 };
                 openList.Add(open);
             }
         }
         else
         {
             for (int i = 0; i < Lottery.ExceptOneDay * 3; i++)
             {
                 if (i > 0 && i % Lottery.ExceptOneDay.Value == 0)
                 {
                     dt  = dt.AddDays(1);
                     dtS = dtS.AddDays(1);
                     j   = -1;
                 }
                 j++;
                 var expect = dt.Date.ToString("yyyyMMdd") + MyTool.AddZeroStr(j + 1, Lottery.ExceptLength.Value);
                 if (query.Exists(n => n.Expect == expect))
                 {
                     continue;
                 }
                 var open = new LotteryOffcialSchedule
                 {
                     LotteryId        = Lottery.Id,
                     ScheduleOpenTime = dtS.AddSeconds(Convert.ToDouble(j * Lottery.BetweenMinute.Value * 60)),//间隔多少时间一期
                     Expect           = expect,
                 };
                 if (Lottery.IsPrivate)
                 {
                     open.ScheduleOpenCode = CreateOpenCode(Lottery.LotteryType);//TODO
                 }
                 openList.Add(open);
             }
         }
         e.LotteryOffcialSchedule.AddRange(openList);
         e.SaveChanges();
     }
 }