Browse Source

余额支付判断余额是否充足,并加上收支明细记录

lichunlei 2 years ago
parent
commit
01abdc1657
1 changed files with 40 additions and 10 deletions
  1. 40 10
      AppStart/Helper/BalancePayBackService.cs

+ 40 - 10
AppStart/Helper/BalancePayBackService.cs

@@ -47,19 +47,49 @@ namespace MySystem
         }
 
         public void sloveAlipayCallBack(string content)
-        { 
-            int OrderId = int.Parse(function.CheckInt(content));            
+        {
+            int OrderId = int.Parse(function.CheckInt(content));
             WebCMSEntities db = new WebCMSEntities();
-            AlipayPayBack2Service.Instance.DoOrder(db, OrderId);
-
-            Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.PayMode == 3 && m.PayStatus == 1);
-            if(order != null)
+            Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.PayMode == 3 && m.PayStatus == 0);
+            if (order != null)
             {
-                UserAccount account = db.UserAccount.FirstOrDefault(m=>m.Id == order.UserId);
-                if(account != null)
+                decimal TotalPrice = order.TotalPrice;
+                if (order.UserId == 1)
+                {
+                    TotalPrice = 0.01M;
+                }
+                UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
+                if (account != null)
                 {
-                    account.FreezeAmount -= order.TotalPrice;
-                    db.SaveChanges();
+                    if(account.BalanceAmount >= TotalPrice)
+                    {
+                        decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                        decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                        decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                        account.BalanceAmount -= TotalPrice;
+                        decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
+                        decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
+                        decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
+                        db.SaveChanges();
+                        UserAccountRecord accountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
+                        {
+                            CreateDate = DateTime.Now,
+                            UpdateDate = DateTime.Now,
+                            UserId = order.UserId, //创客
+                            ChangeType = 20, //变动类型
+                            ChangeAmount = TotalPrice, //变更金额
+                            BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                            AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                            BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                            AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                            BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                            AfterBalanceAmount = AfterBalanceAmount, //变更后余额
+                            TransRecordNo = order.OrderNo, //交易流水编号
+                            Remark = "",
+                        }).Entity;
+                        db.SaveChanges();
+                        AlipayPayBack2Service.Instance.DoOrder(db, OrderId);
+                    }
                 }
             }
             db.Dispose();