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