Browse Source

检查未结算分账订单

lcl 1 month ago
parent
commit
5e0cd1c04c
1 changed files with 61 additions and 0 deletions
  1. 61 0
      Util/HaoDa/SettleAmountCheckHelper.cs

+ 61 - 0
Util/HaoDa/SettleAmountCheckHelper.cs

@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Data;
+using MySystem.Models.Main;
+using Library;
+using System.Threading;
+using Microsoft.Extensions.Hosting;
+using System.Threading.Tasks;
+using LitJson;
+
+namespace MySystem
+{
+    public class SettleAmountCheckHelper
+    {
+        public readonly static SettleAmountCheckHelper Instance = new SettleAmountCheckHelper();
+        private SettleAmountCheckHelper()
+        {
+        }
+
+        public void Start()
+        {
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+        public void StartDo()
+        {
+            while (true)
+            {
+                DoSomeThing();
+                Thread.Sleep(2000);
+            }
+        }
+
+        public void DoSomeThing()
+        { 
+            try
+            {
+                WebCMSEntities db = new WebCMSEntities();
+                DateTime checkDate = DateTime.Now.AddHours(-2);
+                var orders = db.ConsumerOrders.Select(m => new { m.Id, m.Status, m.IsAct, m.UpdateDate, m.SettleAmount }).Where(m => m.Status > 0 && m.IsAct == 1 && m.UpdateDate < checkDate && m.SettleAmount == 0).ToList();
+                foreach(var sub in orders)
+                {
+                    ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
+                    if (order != null)
+                    {
+                        string text = function.GetWebRequest(Library.ConfigurationManager.AppSettings["SpHost"].ToString() + "/Api/PublicMethod/GetSettleOrderAmount?orderNo=" + order.SeoTitle + "&date=" + order.CreateDate.Value.ToString("yyyy-M-d"));
+                        order.SettleAmount = int.Parse(function.CheckInt(text));
+                        db.SaveChanges();
+                    }
+                }
+                db.Dispose();
+            }
+            catch(Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "检查未结算分账订单异常");
+            }
+        }
+    }
+}