Przeglądaj źródła

修复拆单支付完成后,不继续执行逻辑
退押金逻辑

lichunlei 2 lat temu
rodzic
commit
5659d1e2cd

+ 21 - 18
AppStart/Helper/AlipayPayBack2Service.cs

@@ -87,25 +87,23 @@ namespace MySystem
                 order.Status = 1;
                 order.Status = 1;
                 order.PayDate = DateTime.Now;
                 order.PayDate = DateTime.Now;
                 order.PayStatus = 1;
                 order.PayStatus = 1;
+                db.SaveChanges();
                 if(order.ParentOrderId > 0)
                 if(order.ParentOrderId > 0)
                 {
                 {
                     int total = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId);
                     int total = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId);
                     int paycount = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId && m.Status > 0);
                     int paycount = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId && m.Status > 0);
                     if(paycount + 1 >= total)
                     if(paycount + 1 >= total)
                     {
                     {
-                        order = db.Orders.FirstOrDefault(m => m.Id == order.ParentOrderId && m.Status == 0);
-                        if (order != null)
-                        {
-                            order.Status = 2;
-                            order.PayDate = DateTime.Now;
-                            order.PayStatus = 1;
-                            OrderId = order.Id;
-                        }
+                        // order = db.Orders.FirstOrDefault(m => m.Id == order.ParentOrderId && m.Status == 0);
+                        // if (order != null)
+                        // {
+                        //     order.Status = 2;
+                        //     order.PayDate = DateTime.Now;
+                        //     order.PayStatus = 1;
+                        //     OrderId = order.Id;
+                        // }
+                        DoOrderV2(db, order.ParentOrderId);
                     }
                     }
-                }
-                db.SaveChanges();
-                if(order.ParentOrderId > 0)
-                {
                     return;
                     return;
                 }
                 }
 
 
@@ -124,6 +122,7 @@ namespace MySystem
                         order.Status = 2;
                         order.Status = 2;
                         int BuyCount = pro.ProductCount;
                         int BuyCount = pro.ProductCount;
                         int Kind = 0;
                         int Kind = 0;
+                        int BeforeLeaderLevel = 0;
                         if (pro.ProductId == 10 || pro.ProductId == 34)
                         if (pro.ProductId == 10 || pro.ProductId == 34)
                         {
                         {
                             Kind = 1;
                             Kind = 1;
@@ -137,6 +136,7 @@ namespace MySystem
                             Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId && m.LeaderLevel == 0);
                             Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId && m.LeaderLevel == 0);
                             if(user != null)
                             if(user != null)
                             {
                             {
+                                BeforeLeaderLevel = user.LeaderLevel;
                                 user.LeaderLevel = 1;
                                 user.LeaderLevel = 1;
                             }
                             }
                         }
                         }
@@ -145,6 +145,7 @@ namespace MySystem
                             Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId && m.LeaderLevel < 2);
                             Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId && m.LeaderLevel < 2);
                             if(user != null)
                             if(user != null)
                             {
                             {
+                                BeforeLeaderLevel = user.LeaderLevel;
                                 user.LeaderLevel = 2;
                                 user.LeaderLevel = 2;
                             }
                             }
                         }
                         }
@@ -210,22 +211,21 @@ namespace MySystem
                             {
                             {
                                 OperateReserveBackFor(db, user.Id, order.TotalPrice);
                                 OperateReserveBackFor(db, user.Id, order.TotalPrice);
                                 decimal Prize = decimal.Parse(function.CheckNum(PublicFunction.GetPublicParam(db, "BigLeaderPrize")));
                                 decimal Prize = decimal.Parse(function.CheckNum(PublicFunction.GetPublicParam(db, "BigLeaderPrize")));
-                                if(Prize > 0 && user.LeaderLevel < 2 && user.UserType == 0)
+                                if(Prize > 0 && BeforeLeaderLevel < 2 && user.UserType == 0)
                                 {
                                 {
                                     LeaderRecommendPrize(db, order, user.Id, Prize, 122);
                                     LeaderRecommendPrize(db, order, user.Id, Prize, 122);
                                 }
                                 }
                                 //预设大盟主职级
                                 //预设大盟主职级
                                 LeaderPreUserLevel(db, order.UserId, 2);
                                 LeaderPreUserLevel(db, order.UserId, 2);
                             }
                             }
-
                         }
                         }
                         if (pro.ProductId == 28) //购买小盟主,给上级大盟主返储备金
                         if (pro.ProductId == 28) //购买小盟主,给上级大盟主返储备金
                         {
                         {
-                            LeaderBack(db, order);
+                            bool check = LeaderBack(db, order);
                             Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
                             Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
-                            OperateReserveBackFor(db, user.Id, order.TotalPrice);
+                            if (check) OperateReserveBackFor(db, user.Id, order.TotalPrice);
                             decimal Prize = decimal.Parse(function.CheckNum(PublicFunction.GetPublicParam(db, "SmallLeaderPrize")));
                             decimal Prize = decimal.Parse(function.CheckNum(PublicFunction.GetPublicParam(db, "SmallLeaderPrize")));
-                            if(Prize > 0 && user.LeaderLevel < 1 && user.UserType == 0)
+                            if(Prize > 0 && BeforeLeaderLevel < 1 && user.UserType == 0)
                             {
                             {
                                 LeaderRecommendPrize(db, order, user.Id, Prize, 123);
                                 LeaderRecommendPrize(db, order, user.Id, Prize, 123);
                             }
                             }
@@ -630,10 +630,11 @@ namespace MySystem
         }
         }
 
 
         //小盟主购买逻辑
         //小盟主购买逻辑
-        public void LeaderBack(WebCMSEntities db, Orders order)
+        public bool LeaderBack(WebCMSEntities db, Orders order)
         {
         {
             int LeaderUserId = order.UserId;
             int LeaderUserId = order.UserId;
             int level = 0;
             int level = 0;
+            bool result = true;
             while(LeaderUserId > 0)
             while(LeaderUserId > 0)
             {
             {
                 level += 1;
                 level += 1;
@@ -650,6 +651,7 @@ namespace MySystem
                                 OpReserve(db, order, LeaderUserId, order.TotalPrice, 2, 0, "推荐小盟主");
                                 OpReserve(db, order, LeaderUserId, order.TotalPrice, 2, 0, "推荐小盟主");
                                 OpLeaderAccount(db, order, LeaderUserId, order.TotalPrice);
                                 OpLeaderAccount(db, order, LeaderUserId, order.TotalPrice);
                                 LeaderUserId = 0;
                                 LeaderUserId = 0;
+                                result = false;
                             }
                             }
                             else
                             else
                             {
                             {
@@ -670,6 +672,7 @@ namespace MySystem
                     LeaderUserId = 0;
                     LeaderUserId = 0;
                 }
                 }
             }
             }
+            return result;
         }
         }
 
 
         //操作储备金
         //操作储备金

+ 83 - 0
AppStart/Helper/DepositReturnService.cs

@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using LitJson;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+
+namespace MySystem
+{
+    public class DepositReturnService
+    {
+        public readonly static DepositReturnService Instance = new DepositReturnService();
+        private DepositReturnService()
+        { }
+
+
+        public void Start()
+        {
+            Thread th = new Thread(StartListen);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartListen()
+        {
+            while(true)
+            {
+                try
+                {
+                    string content = RedisDbconn.Instance.RPop<string>("ToAlipayAccountQueue");
+                    if(!string.IsNullOrEmpty(content))
+                    {
+                        string[] idlist = content.Split(',');
+                        foreach(string id in idlist)
+                        {
+                            int IdNum = int.Parse(id);
+                            StartListenDo(IdNum);
+                        }
+                    }
+                    else
+                    {
+                        Thread.Sleep(60000);
+                    }
+                }
+                catch(Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "退还押金到支付宝余额异常");
+                    Thread.Sleep(600000);
+                }
+            }
+        }
+
+        public void StartListenDo(int Id)
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            MerchantDepositReturns item = db.MerchantDepositReturns.FirstOrDefault(m => m.Id == Id);
+            if(item != null)
+            {
+                PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new PosMerchantInfo();
+                string Name = item.OperateMan;
+                string AccountNo = item.AlipayAccountNo;
+                string Amount = item.ReturnAmount.ToString("f2");
+                PublicAccountSet set = db.PublicAccountSet.FirstOrDefault() ?? new PublicAccountSet();
+                string result = new Alipay.AlipayPublicMethod().TransferToAccount(set.AlipayAppId, set.AlipayPrivateKey,set.AlipayPublicKey, AccountNo, Amount, "押金返还", Name, "机具SN:" + mer.KqSnNo + ";商户姓名:" + mer.MerRealName);
+                if(result.StartsWith("success"))
+                {
+                    item.Status = 1;
+                    mer.StandardStatus = 1;
+                }
+                else
+                {
+                    item.Status = 2;
+                    mer.StandardStatus = 2;
+                    mer.Remark = result;
+                }
+                db.SaveChanges();
+            }
+            db.Dispose();
+        }
+    }
+}

+ 94 - 0
AppStart/Helper/DepositReturnStatService.cs

@@ -0,0 +1,94 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using LitJson;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+
+namespace MySystem
+{
+    public class DepositReturnStatService
+    {
+        public readonly static DepositReturnStatService Instance = new DepositReturnStatService();
+        private DepositReturnStatService()
+        { }
+
+
+        public void Start()
+        {
+            Thread th = new Thread(StartEverDay);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartEverDay()
+        {
+            while(true)
+            {
+                if(DateTime.Now.Day == 1 && DateTime.Now.Hour == 1)
+                {
+                    StartEverDayDo();
+                }
+                Thread.Sleep(60000);
+            }
+        }
+
+        public void StartEverDayDo()
+        {
+            string Month = DateTime.Now.ToString("yyyyMM");
+            string chk = function.ReadInstance("/DepositReturn/" + Month + ".txt");
+            if(!string.IsNullOrEmpty(chk))
+            {
+                return;
+            }
+            function.WritePage("/DepositReturn/", Month + ".txt", DateTime.Now.ToString());
+            WebCMSEntities db = new WebCMSEntities();
+            int startid = int.Parse(function.CheckInt(function.ReadInstance("/DepositReturn/MerchantId.txt")));
+            List<PosMerchantInfo> merchants = db.PosMerchantInfo.Where(m => m.Id > startid && m.StandardStatus == 0).OrderBy(m => m.Id).Take(50).ToList();
+            foreach(PosMerchantInfo merchant in merchants)
+            {
+                if(merchant.ActiveStatus == 1)
+                {
+                    int StandardMonths = merchant.StandardMonths;
+                    int StandardStatus = merchant.StandardStatus;
+                    DateTime ActDate = merchant.MerStandardDate.Value;
+                    int MonthNum = StandardMonths;
+                    for (int i = StandardMonths + 1; i <= 10; i++)
+                    {
+                        string TradeMonth = ActDate.AddMonths(i).ToString("yyyyMM");
+                        if(int.Parse(TradeMonth) < int.Parse(DateTime.Now.ToString("yyyyMM")))
+                        {
+                            decimal TradeAmount = 0;
+                            bool CheckAmount = db.PosMerchantTradeSummay.Any(m => m.MerchantId == merchant.Id && m.TradeMonth == TradeMonth);
+                            if(CheckAmount)
+                            {
+                                TradeAmount = db.PosMerchantTradeSummay.Where(m => m.MerchantId == merchant.Id && m.TradeMonth == TradeMonth).Sum(m => m.TradeAmount);
+                            }
+                            if(TradeAmount >= 10000)
+                            {
+                                MonthNum = i;
+                            }
+                            else
+                            {
+                                StandardStatus = -1;
+                                break;
+                            }
+                        }
+                    }
+                    PosMerchantInfo edit = db.PosMerchantInfo.FirstOrDefault(m => m.Id == merchant.Id);
+                    if(edit != null)
+                    {
+                        edit.StandardMonths = MonthNum;
+                        edit.StandardStatus = StandardStatus;
+                        db.Dispose();
+                    }
+                }
+                startid = merchant.Id;
+            }
+            function.WritePage("/DepositReturn/", "MerchantId.txt", startid.ToString());
+            db.Dispose();
+        }
+    }
+}

+ 0 - 19
AppStart/Helper/TestService.cs

@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Library;
-using LitJson;
-using System.Linq;
-using System.Data;
-using System.Threading;
-using MySystem.PxcModels;
-
-namespace MySystem
-{
-    public class TestService
-    {
-        public readonly static TestService Instance = new TestService();
-        private TestService()
-        { }
-
-    }
-}

+ 9 - 0
Controllers/HomeController.cs

@@ -1154,5 +1154,14 @@ namespace MySystem.Controllers
             db.Dispose();
             db.Dispose();
             return "ok";
             return "ok";
         }
         }
+    
+        public string test5()
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            StoreApplyHelper.Instance.DoSomething(db);
+            db.Dispose();
+            return "ok";
+        }
+    
     }
     }
 }
 }

+ 2 - 0
Models/PosMerchantInfo.cs

@@ -43,5 +43,7 @@ namespace MySystem.Models
         public string MerchantMobile { get; set; }
         public string MerchantMobile { get; set; }
         public string MerchantName { get; set; }
         public string MerchantName { get; set; }
         public string MerchantNo { get; set; }
         public string MerchantNo { get; set; }
+        public int StandardMonths { get; set; }
+        public int StandardStatus { get; set; }
     }
     }
 }
 }

+ 5 - 5
Models/Users.cs

@@ -88,11 +88,11 @@ namespace MySystem.Models
         public string DeviceType { get; set; }
         public string DeviceType { get; set; }
         public DateTime? HelpProfitAgreeDate { get; set; }
         public DateTime? HelpProfitAgreeDate { get; set; }
         public ulong HelpProfitAgree { get; set; }
         public ulong HelpProfitAgree { get; set; }
-        public int ThisMonthSend { get; set; }
-        public int StoreStock { get; set; }
-        public DateTime? CreateStoreDate { get; set; }
-        public ulong IsSign { get; set; }
-        public DateTime? SignDate { get; set; }
         public string SignPic { get; set; }
         public string SignPic { get; set; }
+        public DateTime? SignDate { get; set; }
+        public ulong IsSign { get; set; }
+        public DateTime? CreateStoreDate { get; set; }
+        public int StoreStock { get; set; }
+        public int ThisMonthSend { get; set; }
     }
     }
 }
 }

+ 4 - 0
Models/WebCMSEntities.cs

@@ -8805,6 +8805,10 @@ namespace MySystem.Models
 
 
                 entity.Property(e => e.Sort).HasColumnType("int(11)");
                 entity.Property(e => e.Sort).HasColumnType("int(11)");
 
 
+                entity.Property(e => e.StandardMonths).HasColumnType("int(11)");
+
+                entity.Property(e => e.StandardStatus).HasColumnType("int(11)");
+
                 entity.Property(e => e.Status).HasColumnType("int(11)");
                 entity.Property(e => e.Status).HasColumnType("int(11)");
 
 
                 entity.Property(e => e.TopUserId).HasColumnType("int(11)");
                 entity.Property(e => e.TopUserId).HasColumnType("int(11)");

+ 2 - 0
PxcModels/PosMerchantInfo.cs

@@ -43,5 +43,7 @@ namespace MySystem.PxcModels
         public string MerchantMobile { get; set; }
         public string MerchantMobile { get; set; }
         public string MerchantName { get; set; }
         public string MerchantName { get; set; }
         public string MerchantNo { get; set; }
         public string MerchantNo { get; set; }
+        public int StandardMonths { get; set; }
+        public int StandardStatus { get; set; }
     }
     }
 }
 }

+ 5 - 5
PxcModels/Users.cs

@@ -88,11 +88,11 @@ namespace MySystem.PxcModels
         public string DeviceType { get; set; }
         public string DeviceType { get; set; }
         public DateTime? HelpProfitAgreeDate { get; set; }
         public DateTime? HelpProfitAgreeDate { get; set; }
         public ulong HelpProfitAgree { get; set; }
         public ulong HelpProfitAgree { get; set; }
-        public int ThisMonthSend { get; set; }
-        public int StoreStock { get; set; }
-        public DateTime? CreateStoreDate { get; set; }
-        public ulong IsSign { get; set; }
-        public DateTime? SignDate { get; set; }
         public string SignPic { get; set; }
         public string SignPic { get; set; }
+        public DateTime? SignDate { get; set; }
+        public ulong IsSign { get; set; }
+        public DateTime? CreateStoreDate { get; set; }
+        public int StoreStock { get; set; }
+        public int ThisMonthSend { get; set; }
     }
     }
 }
 }

+ 4 - 0
PxcModels/WebCMSEntities.cs

@@ -8805,6 +8805,10 @@ namespace MySystem.PxcModels
 
 
                 entity.Property(e => e.Sort).HasColumnType("int(11)");
                 entity.Property(e => e.Sort).HasColumnType("int(11)");
 
 
+                entity.Property(e => e.StandardMonths).HasColumnType("int(11)");
+
+                entity.Property(e => e.StandardStatus).HasColumnType("int(11)");
+
                 entity.Property(e => e.Status).HasColumnType("int(11)");
                 entity.Property(e => e.Status).HasColumnType("int(11)");
 
 
                 entity.Property(e => e.TopUserId).HasColumnType("int(11)");
                 entity.Property(e => e.TopUserId).HasColumnType("int(11)");

+ 1 - 1
Startup.cs

@@ -222,7 +222,7 @@ namespace MySystem
             OperateAmountService.Instance.Start(); //运营中心额度变更
             OperateAmountService.Instance.Start(); //运营中心额度变更
             OperateStockService.Instance.Start(); //运营中心库存实时更新
             OperateStockService.Instance.Start(); //运营中心库存实时更新
             StoreApplyHelper.Instance.ResetStoreReserve(); //重置分仓额度
             StoreApplyHelper.Instance.ResetStoreReserve(); //重置分仓额度
-            // LeaderApplyCouponsHelper.Instance.Start(); //盟主储蓄金申请机具券打标记
+            LeaderApplyCouponsHelper.Instance.Start(); //盟主储蓄金申请机具券打标记
             // UserMonthFeeHelper.Instance.Start(); //每月创客服务费
             // UserMonthFeeHelper.Instance.Start(); //每月创客服务费
             UserMonthFeeHelper.Instance.Start2(); //临时扣创客服务费
             UserMonthFeeHelper.Instance.Start2(); //临时扣创客服务费