Переглянути джерело

初步完成盟主储备金逻辑代码编写

lichunlei 2 роки тому
батько
коміт
03d51499d2

+ 19 - 0
AppStart/Helper/AlipayPayBack2Service.cs

@@ -87,7 +87,26 @@ namespace MySystem
                 order.Status = 1;
                 order.PayDate = DateTime.Now;
                 order.PayStatus = 1;
+                if(order.ParentOrderId > 0)
+                {
+                    int total = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId);
+                    int paycount = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId && m.Status > 0);
+                    if(paycount + 1 >= total)
+                    {
+                        order = db.Orders.FirstOrDefault(m => m.Id == order.ParentOrderId && m.Status == 0);
+                        if (order != null)
+                        {
+                            order.Status = 1;
+                            order.PayDate = DateTime.Now;
+                            order.PayStatus = 1;
+                        }
+                    }
+                }
                 db.SaveChanges();
+                if(order.ParentOrderId > 0)
+                {
+                    return;
+                }
 
                 OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId);
                 if (pro != null)

+ 1 - 1
AppStart/Helper/BalancePayBackService.cs

@@ -98,7 +98,7 @@ namespace MySystem
                             Remark = "购买" + ProductName,
                         }).Entity;
                         db.SaveChanges();
-                        AlipayPayBack2Service.Instance.DoOrder(db, OrderId);
+                        AlipayPayBack2Service.Instance.DoOrderV2(db, OrderId);
                     }
                 }
             }

+ 69 - 0
AppStart/Helper/ReservePayBackService.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+using Library;
+using LitJson;
+
+namespace MySystem
+{
+    public class ReservePayBackService
+    {
+        public readonly static ReservePayBackService Instance = new ReservePayBackService();
+        private ReservePayBackService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(dosomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+        
+        private void dosomething()
+        {
+            while (true)
+            {
+                try
+                {
+                    string content = RedisDbconn.Instance.RPop<string>("ReservePayQueue");
+                    if (!string.IsNullOrEmpty(content))
+                    {
+                        sloveAlipayCallBack(content);
+                    }
+                    else
+                    {
+                        Thread.Sleep(2000);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "商城订单余额支付异常");
+                    Thread.Sleep(2000);
+                }
+            }
+        }
+
+        public void sloveAlipayCallBack(string content)
+        {
+            int OrderId = int.Parse(function.CheckInt(content));
+            WebCMSEntities db = new WebCMSEntities();
+            Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.PayMode == 4 && m.PayStatus == 0);
+            if (order != null)
+            {
+                decimal TotalPrice = order.TotalPrice;
+                UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
+                if (account != null)
+                {
+                    if(account.LeaderReserve >= TotalPrice)
+                    {
+                        AlipayPayBack2Service.Instance.DoOrderV2(db, OrderId);
+                    }
+                }
+            }
+            db.Dispose();
+        }
+    }
+}