Browse Source

集成分账通知处理

lcl 6 months ago
parent
commit
7aa419c972

+ 5 - 9
Controllers/HomeController.cs

@@ -29,15 +29,11 @@ namespace MySystem.Controllers
             return View();
         }
 
-        // public string test2(int id)
-        // {
-        //     WebCMSEntities db = new WebCMSEntities();
-        //     MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantAddInfo();
-        //     AddInfo.MchtNo = "";
-        //     string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
-        //     db.Dispose();
-        //     return result;
-        // }
+        public string getHdOrder()
+        {
+            GetHaoDaFTPInfoService.Instance.GetFTPDataInfoYesterday();
+            return "ok";
+        }
 
         public string test()
         {

+ 4 - 2
Startup.cs

@@ -142,13 +142,12 @@ namespace MySystem
             }
             if (Library.ConfigurationManager.EnvironmentFlag == 2)
             {
-                GetHaoDaFTPInfoService.Instance.Start(); // 获取好哒FTP交易数据
-                GetTencentAddressInfoService.Instance.Start(); // 获取腾讯地图地址
                 GetStoreNoHelper.Instance.Start(); //获取商户门店号、微信支付宝商户号
                 MerchantConfirmService.Instance.Start(); //提交商户进件
                 CheckWeChatSignService.Instance.Start(); //查询商户审核状态
                 CheckWeChatBindService.Instance.Start(); //执行好哒微信绑定appid
                 ProfitShareService.Instance.Start(); //分账状态监控队列,分账完成则提交返现
+                ProfitShareService.Instance.StartCheck(); //复核头一天的分账
                 HaoDaExtHelper.Instance.StartWeChat();
                 HaoDaExtHelper.Instance.StartAlipay();
                 HaoDaExtQueryHelper.Instance.StartWeChat();
@@ -175,6 +174,9 @@ namespace MySystem
                 MerchantStandardService.Instance.Start(); //商户缴纳服务费次月活动交易额大于等于1W,奖励进件创客50元
                 MerchantStandardService.Instance.StartThree(); //商户缴纳服务费次月起连续不间断三个月,每月活动交易额大于1W,奖励进件创客100元
                 MerchantStandardService.Instance.StartActive();
+                
+                // GetHaoDaFTPInfoService.Instance.Start(); // 获取好哒FTP交易数据
+                GetTencentAddressInfoService.Instance.Start(); // 获取腾讯地图地址
             }
         }
 

+ 1 - 1
Util/HaoDa/GetHaoDaFTPInfoService.cs

@@ -325,7 +325,7 @@ namespace MySystem
 
                 // 打开数据流
                 Stream responseStream = response.GetResponseStream();
-                StreamReader reader = new StreamReader(responseStream)
+                StreamReader reader = new StreamReader(responseStream);
                 // 读取数据
                 string fileContents = reader.ReadToEnd();
                 if (!string.IsNullOrEmpty(fileContents))

+ 113 - 52
Util/HaoDa/ProfitShareService.cs

@@ -1,11 +1,11 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using MySystem.Models.Main;
-using Library;
-using LitJson;
 using System.Text.RegularExpressions;
 using System.Threading;
+using Library;
+using LitJson;
+using MySystem.Models.Main;
 
 namespace MySystem
 {
@@ -26,74 +26,135 @@ namespace MySystem
         {
             while (true)
             {
-                WebCMSEntities db = new WebCMSEntities();
-                DateTime checkDate = DateTime.Now.AddMinutes(-2);
-                var list = db.ConsumerOrders.Select(m => new { m.Id, m.DivideDate, m.DivideFlag, m.IsAct, m.PayMode }).Where(m => m.DivideFlag == 1 && m.IsAct == 1 && m.DivideDate < checkDate).OrderBy(m => m.Id).Take(100).ToList();
-                foreach (var sub in list)
+                // WebCMSEntities db = new WebCMSEntities();
+                // DateTime checkDate = DateTime.Now.AddMinutes(-2);
+                // var list = db.ConsumerOrders.Select(m => new { m.Id, m.DivideDate, m.DivideFlag, m.IsAct, m.PayMode }).Where(m => m.DivideFlag == 1 && m.IsAct == 1 && m.DivideDate < checkDate).OrderBy(m => m.Id).Take(100).ToList();
+                // foreach (var sub in list)
+                // {
+                //     RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + sub.PayMode + ":List", sub.Id.ToString());
+                //     ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
+                //     if (order != null)
+                //     {
+                //         order.DivideFlag = 2;
+                //         db.SaveChanges();
+                //     }
+                // }
+                // db.Dispose();
+                // Thread.Sleep(5000);
+
+                string content = RedisDbconn.Instance.RPop<string>("PartOrderStatusQueue");
+                if(!string.IsNullOrEmpty(content))
                 {
-                    RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + sub.PayMode + ":List", sub.Id.ToString());
-                    ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
-                    if (order != null)
-                    {
-                        order.DivideFlag = 2;
-                        db.SaveChanges();
-                    }
+                    StartExcute(content);
+                }
+                else
+                {
+                    Thread.Sleep(60000);
                 }
-                db.Dispose();
-                Thread.Sleep(5000);
             }
         }
 
-        public void StartDo(string content)
+        public void StartExcute(string content)
         {
-            try
+            JsonData jsonData = JsonMapper.ToObject(content);
+            string applyNo = jsonData["applyNo"].ToString();
+            string mchtNo = jsonData["mchtNo"].ToString();
+            string status = jsonData["status"].ToString();
+            string payTime = jsonData["payTime"].ToString();
+            string desc = jsonData["desc"].ToString();
+            WebCMSEntities db = new WebCMSEntities();
+            ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.TradePayNo == applyNo);
+            if(order != null)
             {
-                JsonData jsonObj = JsonMapper.ToObject(content);
-                string ApplyNo = jsonObj["ApplyNo"].ToString(); //微信订单号
-                string MchtNo = jsonObj["MchtNo"].ToString(); //商户订单号
-                string OrderNo = jsonObj["OrderNo"].ToString(); //商户订单号
-                WebCMSEntities db = new WebCMSEntities();
-
-                ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.OrderNo == OrderNo && m.Status == 2);
-                MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
+                if(status == "0")
+                {
+                    order.DivideFlag = 2;
+                    order.DivideDate = DateTime.Now;
+                }
+                else
+                {
+                    order.DivideFlag = -1;
+                }
+                order.DivideLog = desc;
+                db.SaveChanges();
+                RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
+            }
+            db.Dispose();
+        }
 
-                JsonData result = JsonMapper.ToObject(HaoDaHelper.Instance.OrderDivideAccountsQuery(ApplyNo, MchtNo, merchantAdd.BrandId));
-                string state = result["data"]["status"].ToString();
-                if (result["data"]["status"].ToString() == "0")
+        public void StartCheck()
+        {
+            Thread th = new Thread(StartCheckListen);
+            th.IsBackground = true;
+            th.Start();
+        }
+        public void StartCheckListen()
+        {
+            while (true)
+            {
+                try
                 {
-                    if (order != null)
+                    if(DateTime.Now.Hour > 0 && DateTime.Now.Hour < 20)
                     {
-                        RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
+                        string CheckDate = DateTime.Now.ToString("yyyyMMdd");
+                        string check = function.ReadInstance("/CheckYesterdayPartOrder/" + CheckDate + ".txt");
+                        if (string.IsNullOrEmpty(check))
+                        {
+                            function.WritePage("/CheckYesterdayPartOrder/", CheckDate + ".txt", DateTime.Now.ToString());
+                            WebCMSEntities db = new WebCMSEntities();
+                            DateTime checkDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
+                            var list = db.ConsumerOrders.Select(m => new { m.Id, m.DivideDate, m.DivideFlag, m.IsAct, m.PayMode }).Where(m => m.DivideFlag < 2 && m.IsAct == 1 && m.DivideDate < checkDate).OrderBy(m => m.Id).Take(100).ToList();
+                            foreach (var sub in list)
+                            {
+                                StartCheckDo(sub.Id);
+                            }
+                            db.Dispose();
+                        }
                     }
-                    db.Dispose();
+                }
+                catch (Exception ex)
+                {
+                    LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "分账复核头天订单异常");
+                }
+                Thread.Sleep(3600000);
+            }
+        }
+
+        public void StartCheckDo(int Id)
+        {
+            WebCMSEntities db = new WebCMSEntities();
+
+            ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == Id) ?? new ConsumerOrders();
+            MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
+
+            JsonData result = JsonMapper.ToObject(HaoDaHelper.Instance.OrderDivideAccountsQuery(order.TradePayNo, merchantAdd.OutMchtNo, merchantAdd.BrandId));
+            if(result["resultCode"].ToString() == "1")
+            {
+                string status = result["data"]["status"].ToString();
+                string desc = result["data"]["desc"].ToString();
+                if (status == "0")
+                {
+                    order.DivideFlag = 2;
+                    order.DivideDate = DateTime.Now;                        
+                    RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
                 }
                 else
                 {
-                    RedisDbconn.Instance.AddList("ProfitShareHdQueue", content);
+                    order.DivideFlag = -1;
                 }
+                order.DivideLog = desc;
             }
-            catch (Exception ex)
+            else
             {
-                LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "分账队列异常");
+                string errorCode = result["errorCode"].ToString();
+                string errorDesc = result["errorDesc"].ToString();
+                order.DivideFlag = -1;
+                order.DivideLog = errorCode + ":" + errorDesc;
             }
-        }
-
+            db.SaveChanges();
 
-        // public void StartListen()
-        // {
-        //     while (true)
-        //     {
-        //         string content = RedisDbconn.Instance.RPop<string>("ProfitShareHdQueue");
-        //         if (!string.IsNullOrEmpty(content))
-        //         {
-        //             StartDo(content);
-        //         }
-        //         else
-        //         {
-        //             Thread.Sleep(2000);
-        //         }
-        //     }
-        // }
+            db.Dispose();
+        }
 
         // public void StartDo(string content)
         // {

+ 1 - 0
Util/HaoDa/WeChatPayBackService.cs

@@ -218,6 +218,7 @@ namespace MySystem
                                     string amountAmount = amount.ToString("f0");
                                     string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, amountAmount, seviceAmount), merchantAdd.BrandId);
                                     order.DivideLog = "请求分账日志:" + result;
+                                    order.TradePayNo = applyNo;
                                     if (result.Contains("\"resultCode\":\"0\"") && (result.Contains("分账金额不足") || result.Contains("不存在")))
                                     {
                                         Status = 1;