/// <summary>
 /// 账户充值
 /// </summary>
 /// <param name="AccountId"></param>
 /// <param name="Type"></param>
 /// <param name="Money"></param>
 public void Recharge(int AccountId, string Type, decimal Money, string OrderNo)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt      = EntitiesTool.GetDateTimeNow(e);
         var account = e.Accounts.FirstOrDefault(n => n.Id == AccountId);
         var no      = e.AccountRecharge.Count(n => n.AccountId == AccountId) + 1;
         using (var tran = new TransactionScope())
         {
             var o = new AccountRecharge
             {
                 AccountId  = AccountId,
                 CreateTime = dt,
                 Money      = Money,
                 OrderNo    = OrderNo,
                 Type       = Type,
                 Remarks    = "",
             };
             e.AccountRecharge.Add(o);
             var ab = new AccountBusiness
             {
                 AccountId      = AccountId,
                 BusinessTypeId = (int)Enum_AccountBusinessType.Recharge,
                 CreateTime     = dt,
                 PayBefore      = account.AccountBalance,
                 PayIn          = Money,
                 PayAfter       = account.AccountBalance + Money,
             };
             e.AccountBusiness.Add(ab);//充值业务单
             account.AccountBalance = ab.PayAfter;
             e.SaveChanges();
             tran.Complete();
         }
     }
 }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="orderNO"></param>
 /// <param name="pay_status">0:未支付 1:成功 2:失败</param>
 /// <param name="paydatetime"></param>
 /// <returns></returns>
 public bool DonePayRecord(string orderNO, int pay_status, string paydatetime, int payType)
 {
     using (e = new LotteryAPPEntities())
     {
         using (var tran = new TransactionScope())
         {
             var f = e.Pay_Record.FirstOrDefault(n => n.orderNO == orderNO && n.pay_status == 0);//1
             if (f == null)
             {
                 return(false);
             }
             if (f.pay_status != 0)
             {
                 return(false);
             }
             var flag = false;
             f.paydatetime = paydatetime;
             f.pay_status  = pay_status;
             f.payType     = payType;
             var ar = e.AccountRecharge.FirstOrDefault(n => n.OrderNo == orderNO);//2
             if (ar == null)
             {
                 return(false);
             }
             ar.Type   = payType.ToString();
             ar.Status = pay_status;
             if (pay_status == 1)
             {
                 var account = e.Accounts.FirstOrDefault(n => n.Id == f.userId);//3
                 if (account == null)
                 {
                     return(false);
                 }
                 var ab = new AccountBusiness
                 {
                     AccountId      = account.Id,
                     BusinessTypeId = (int)Enum_AccountBusinessType.Recharge,
                     CreateTime     = EntitiesTool.GetDateTimeNow(e),
                     EventId        = ar.Id,
                     PayBefore      = account.AccountBalance,
                     PayIn          = f.orderAmount / 100,
                     PayAfter       = account.AccountBalance + f.orderAmount / 100,
                 };
                 account.AccountBalance = ab.PayAfter;
                 e.AccountBusiness.Add(ab);//4.投注业务单
                 var add = e.SaveChanges();
                 flag = add == 4;
             }
             else
             {
                 flag = e.SaveChanges() == 2;
             }
             if (flag)
             {
                 tran.Complete();
             }
             return(flag);
         }
     }
 }
Example #3
0
 public LotteryOffcialSchedule NextOpenNo(int LotteryId)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt = EntitiesTool.GetDateTimeNow(e);
         return(e.LotteryOffcialSchedule.Where(n => LotteryId == n.LotteryId && n.ScheduleOpenTime > dt).OrderBy(n => n.ScheduleOpenTime).FirstOrDefault());
     }
 }
 /// <summary>
 /// 获取准备开奖期号
 /// </summary>
 /// <returns></returns>
 public LotteryOpenInfo NextOpenNo(int LotteryId)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt    = EntitiesTool.GetDateTimeNow(e);
         var query = e.LotteryOpenInfo.Where(n => n.LotteryId == LotteryId && n.OpenTime > dt).FirstOrDefault();
         return(query);
     }
 }
 /// <summary>
 /// 注册下级
 /// </summary>
 public void RegChildAccount(Accounts Account)
 {
     using (e = new LotteryAPPEntities())
     {
         Account.CreateTime = EntitiesTool.GetDateTimeNow(e);
         e.Accounts.Add(Account);
         e.SaveChanges();
     }
 }
 /// <summary>
 /// 单日提现次数
 /// </summary>
 /// <param name="AccountId"></param>
 /// <returns></returns>
 public int TodayWithdrawCount(int AccountId)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt  = EntitiesTool.GetDateTimeNow(e).Date;
         var dt1 = dt.AddDays(1);
         return(e.AccountWithdraw.Count(n => n.AccountId == AccountId && n.CreateTime >= dt && n.CreateTime < dt1));
     }
 }
 /// <summary>
 /// 绑定银行卡
 /// </summary>
 /// <param name="BankCard"></param>
 public void BindBankCard(BankCard BankCard)
 {
     using (e = new LotteryAPPEntities())
     {
         BankCard.CreatTime = EntitiesTool.GetDateTimeNow(e);
         BankCard.No        = e.BankCard.Count(n => n.AccountId == BankCard.AccountId) + 1;
         e.BankCard.Add(BankCard);
         e.SaveChanges();
     }
 }
Example #8
0
 /// <summary>
 /// 获取指定数量的预开奖信息
 /// </summary>
 /// <param name="LotteryId"></param>
 /// <param name="Count"></param>
 /// <returns></returns>
 public List <LotteryOffcialSchedule> GetLotteryOffcialScheduleList(int LotteryId, int Count)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt    = EntitiesTool.GetDateTimeNow(e);
         var query = e.LotteryOffcialSchedule.Where(n => n.LotteryId == LotteryId && n.ScheduleOpenTime > dt).Take(Count).ToList();
         //query.ForEach(n => n.ScheduleOpenCode = "");
         return(query);
     }
 }
 /// <summary>
 /// 获取上一期号码
 /// </summary>
 /// <returns></returns>
 public LotteryOpenInfo LastOpenNo(int LotteryId)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt    = EntitiesTool.GetDateTimeNow(e);
         var query = e.LotteryOpenInfo.Where(n => n.LotteryId == LotteryId && n.OpenTime <= dt).OrderByDescending(n => n.OpenTime).FirstOrDefault(); //获取已开奖的最后一期
         if (query == null)                                                                                                                          //如果没有已开奖期号
         {
             query = e.LotteryOpenInfo.Where(n => n.LotteryId == LotteryId && n.OpenTime > dt).FirstOrDefault();                                     //获取第一期
         }
         return(query);
     }
 }
Example #10
0
 public List <LotteryOffcialSchedule> NextOpenNo(List <int> LotteryId)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt    = EntitiesTool.GetDateTimeNow(e);
         var query = new List <LotteryOffcialSchedule>();
         foreach (var item in LotteryId)
         {
             query.Add(e.LotteryOffcialSchedule.Where(n => item == n.LotteryId && n.ScheduleOpenTime > dt).OrderBy(n => n.ScheduleOpenTime).FirstOrDefault());
         }
         return(query);
     }
 }
 /// <summary>
 /// 链接注册下级用户
 /// </summary>
 /// <returns></returns>
 public bool RegAccountBySet(int AccountRegInfoSetId, string Name, string Pwd, string MoneyPwd, string NickName, string Email)
 {
     using (e = new LotteryAPPEntities())
     {
         if (e.Accounts.FirstOrDefault(n => n.AccountName == Name) != null)
         {
             return(false);
         }
         var s       = e.AccountRegInfoSet.FirstOrDefault(n => n.Id == AccountRegInfoSetId);
         var account = new Accounts
         {
             AccountMoneyPwd = MoneyPwd,
             AccountName     = Name,
             AccountPwd      = Pwd,
             AccountNickname = NickName,
             Email           = Email,
             //AgentPercent11X5 = s.AgentPercent11X5,
             //AgentPercentDPC = s.AgentPercentDPC,
             //AgentPercentSSC = s.AgentPercentSSC,
             //AccountParentId = s.AccountId,
             CreateTime    = EntitiesTool.GetDateTimeNow(e),
             AccountStatus = (int)Enum_AccountStatus.Normal,
         };
         if (s != null)
         {
             var acc = e.Accounts.FirstOrDefault(n => n.Id == s.AccountId);
             if (acc != null)
             {
                 if (s.AgentPercent11X5 > acc.AgentPercent11X5)
                 {
                     return(false);
                 }
                 if (s.AgentPercentDPC > acc.AgentPercentDPC)
                 {
                     return(false);
                 }
                 if (s.AgentPercentSSC > acc.AgentPercentSSC)
                 {
                     return(false);
                 }
                 account.AgentPercent11X5 = s.AgentPercent11X5;
                 account.AgentPercentDPC  = s.AgentPercentDPC;
                 account.AgentPercentSSC  = s.AgentPercentSSC;
                 account.AccountParentId  = s.AccountId;
             }
         }
         e.Accounts.Add(account);
         return(e.SaveChanges() == 1);
     }
 }
Example #12
0
 public bool AddPayRecord(Pay_Record pay)
 {
     using (e = new LotteryAPPEntities())
     {
         using (var tran = new TransactionScope())
         {
             pay.creation_time = EntitiesTool.GetDateTimeNow(e);
             e.Pay_Record.Add(pay);
             var ar = new AccountRecharge
             {
                 AccountId  = pay.userId,
                 CreateTime = pay.creation_time,
                 Money      = pay.orderAmount / 100,
                 OrderNo    = pay.orderNO,
                 Status     = pay.pay_status,
                 Remarks    = "",
             };
             if (pay.payType.HasValue)
             {
                 if (GetPayTypeDic().ContainsKey(pay.payType.Value))
                 {
                     ar.Type = GetPayTypeDic()[pay.payType.Value];
                 }
                 else
                 {
                     ar.Type = pay.payType.Value + "";
                 }
             }
             else
             {
                 ar.Type = "";
             }
             e.AccountRecharge.Add(ar);
             if (e.SaveChanges() == 2)
             {
                 tran.Complete();
                 return(true);
             }
         }
         return(false);
     }
 }
 /// <summary>
 /// 开奖号存在或停止投注
 /// </summary>
 /// <param name="LotteryId"></param>
 /// <param name="Expect"></param>
 /// <param name="isPrivate"></param>
 /// <returns></returns>
 public string IsExistsExpect(int LotteryId, string Expect, bool isPrivate)
 {
     using (e = new LotteryAPPEntities())
     {
         var dt = EntitiesTool.GetDateTimeNow(e);
         var f  = e.LotteryOffcialSchedule.FirstOrDefault(n => n.LotteryId == LotteryId && n.Expect == Expect);
         if (f != null)
         {
             dt = dt.AddSeconds(isPrivate ? 3 : 30);//30秒截止
             if (dt > f.ScheduleOpenTime)
             {
                 return("该期已截止投注");
             }
             else
             {
                 return("");
             }
         }
         return("下注期号无效");
     }
 }
        /// <summary>
        /// 更新中奖用户金额
        /// </summary>
        public int UpdateAccountMoney()
        {
            int count = 0;

            using (e = new LotteryAPPEntities())
            {
                var query = e.BetInfo.Where(n => n.ResultType == (int)Enum_ResultType.Backing && n.BackMoney > 0).ToList();
                if (query.Count > 0)
                {
                    var dt = EntitiesTool.GetDateTimeNow(e);
                    foreach (var item in query.GroupBy(n => n.AccountId))
                    {
                        var     account   = e.Accounts.FirstOrDefault(n => n.Id == item.Key);
                        decimal lastMoney = 0;
                        foreach (var bet in query.Where(n => n.AccountId == item.Key))
                        {
                            count++;
                            var ab = new AccountBusiness
                            {
                                AccountId      = account.Id,
                                BusinessTypeId = (int)Enum_AccountBusinessType.Win,
                                CreateTime     = dt,
                                EventId        = bet.Id,
                                PayBefore      = account.AccountBalance,
                                PayIn          = bet.BackMoney,
                                PayAfter       = account.AccountBalance + bet.BackMoney,
                            };
                            e.AccountBusiness.Add(ab);                  //添加业务单
                            bet.ResultType = (int)Enum_ResultType.True; //投注单变成已中奖
                            lastMoney      = ab.PayAfter;               //余额
                            bet.BackTime   = dt;
                        }
                        account.AccountBalance = lastMoney;
                        e.SaveChanges();
                    }
                }
            }
            return(count);
        }
        /// <summary>
        /// 账户提现
        /// </summary>
        /// <returns>-1失败,0人工,1自动</returns>
        public AccountWithdraw Withdraw(int AccountId, decimal Money, string OrderNo, string BankCardNo, string BankName)
        {
            using (e = new LotteryAPPEntities())
            {
                var dt      = EntitiesTool.GetDateTimeNow(e);
                var account = e.Accounts.FirstOrDefault(n => n.Id == AccountId);
                var o       = new AccountWithdraw
                {
                    AccountId  = AccountId,
                    CreateTime = dt,
                    Money      = Money,
                    //No = e.AccountWithdraw.Count(n => n.AccountId == AccountId) + 1,
                    OrderNo    = OrderNo,
                    Remarks    = "",
                    BankCardNo = BankCardNo,
                    BankName   = BankName,
                    Status     = 0,
                };
                if (Money > 1)
                {
                    o.isAutoPay = false;
                }
                else
                {
                    o.isAutoPay = true;
                    o.auditor   = "[自助提现]";
                    o.auditTime = dt;
                }
                e.AccountWithdraw.Add(o);

                if (e.SaveChanges() != 1)
                {
                    return(null);
                }
                return(o);
            }
        }
 public bool DoneWithdraw(SinglePay_Record record)
 {
     using (e = new LotteryAPPEntities())
     {
         var w = e.AccountWithdraw.FirstOrDefault(n => n.OrderNo == record.orderNO);
         if (w != null && w.BankCardNo == record.accountNo && w.Money == record.amt)
         {
             var account = e.Accounts.FirstOrDefault(n => n.Id == w.AccountId);
             var ab      = new AccountBusiness
             {
                 AccountId      = w.AccountId,
                 BusinessTypeId = (int)Enum_AccountBusinessType.Withdraw,
                 CreateTime     = EntitiesTool.GetDateTimeNow(e),
                 PayBefore      = account.AccountBalance,
                 PayIn          = w.Money,
                 PayAfter       = account.AccountBalance + w.Money,
             };
             e.AccountBusiness.Add(ab);//提现业务单
             account.AccountBalance = ab.PayAfter;
             return(e.SaveChanges() >= 2);
         }
         return(false);
     }
 }
        /// <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;
            }
        }
        /// <summary>
        /// 变更余额
        /// </summary>
        /// <param name="account"></param>
        /// <param name="money"></param>
        //public Accounts BalanceChange(Accounts account, decimal money)
        //{
        //    using (e = new LotteryAPPEntities())
        //    {
        //        var a = e.Accounts.FirstOrDefault(n => n.Id == account.Id);
        //        a.AccountBalance += money;
        //        e.SaveChanges();
        //        return a;
        //    }
        //}
        /// <summary>
        /// 下注扣款
        /// </summary>
        /// <param name="account"></param>
        /// <param name="money"></param>
        public Accounts BalanceChange(int AccountId, BetInfo BetInfo)
        {
            using (e = new LotteryAPPEntities())
            {
                var dt = EntitiesTool.GetDateTimeNow(e);
                using (var tran = new TransactionScope())
                {
                    e.BetInfo.Add(BetInfo);
                    e.SaveChanges();
                    var account = e.Accounts.FirstOrDefault(n => n.Id == AccountId);

                    #region 添加业务单
                    var ab = new AccountBusiness
                    {
                        AccountId      = BetInfo.AccountId,
                        BusinessTypeId = (int)Enum_AccountBusinessType.Bet,
                        CreateTime     = dt,
                        EventId        = BetInfo.Id,
                        PayBefore      = account.AccountBalance,
                        PayOut         = BetInfo.BetMoney,
                        PayAfter       = account.AccountBalance - BetInfo.BetMoney,
                    };
                    e.AccountBusiness.Add(ab);                     //投注业务单
                    account.AccountBalance = ab.PayAfter;
                    var pList = GetAllParentAccount(AccountId, e); //上级名单(含自己)
                    if (BetInfo.GetBackPercent > 0)                //如果要返点
                    {
                        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);//返点业务单
                    }
                    #region 单个玩法投注>0.2元,上级产生返点(固定等级差返点)
                    if (BetInfo.BetMoney >= new decimal(0.2) && pList.Count > 1)
                    {
                        for (int i = 1; i < pList.Count; i++)
                        {
                            ab = new AccountBusiness
                            {
                                AccountId      = pList[i].Id,
                                BusinessTypeId = (int)Enum_AccountBusinessType.BackPercent,
                                CreateTime     = dt,
                                EventId        = BetInfo.Id,
                                PayBefore      = pList[i].AccountBalance,
                                PayIn          = BetInfo.BetMoney * (pList[i].AgentPercent11X5 - pList[i - 1].AgentPercent11X5) / 100,
                            };
                            ab.PayAfter             = pList[i].AccountBalance + ab.PayIn.Value;
                            pList[i].AccountBalance = ab.PayAfter;
                            e.AccountBusiness.Add(ab);//返点业务单
                        }
                    }
                    #endregion
                    #endregion
                    e.SaveChanges();
                    tran.Complete();
                    return(account);
                }
            }
        }
        /// <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;//修改新一期为待开
                //}
            }
        }
Example #20
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();
     }
 }