/// <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(); } } }
/// <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); } } }
/// <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); }
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="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> /// <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; } }