Browse Source

增加每月归档注销创客

lcl 2 năm trước cách đây
mục cha
commit
b405ffbfe7
2 tập tin đã thay đổi với 90 bổ sung0 xóa
  1. 1 0
      AppStart/Helper/StatService.cs
  2. 89 0
      AppStart/Timer/LogoutUserHelper.cs

+ 1 - 0
AppStart/Helper/StatService.cs

@@ -1713,6 +1713,7 @@ namespace MySystem
                     if (string.IsNullOrEmpty(flag))
                     {
                         function.WritePage("/ProfitFlag/", Month + ".txt", DateTime.Now.ToString("HH:mm:ss"));
+                        LogoutUserHelper.Instance.DoWorks(); //每月一号归档注销创客,把伞下创客归到注销创客的上级
                         StatUserLevelStart();
                     }
                 }

+ 89 - 0
AppStart/Timer/LogoutUserHelper.cs

@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Linq;
+using System.Data;
+using MySystem;
+using MySystem.PxcModels;
+using Library;
+using LitJson;
+
+public class LogoutUserHelper
+{
+    public readonly static LogoutUserHelper Instance = new LogoutUserHelper();
+    private LogoutUserHelper()
+    {
+    }
+
+    public void Start()
+    {
+        Thread th = new Thread(DoWorks);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    // 判断已注销的创客在每月1号,分离创客表之后,伞下自动归到注销创客的上级
+    public void DoWorks()
+    {
+        function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "每月归档注销创客日志");
+        WebCMSEntities db = new WebCMSEntities();
+        OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
+        try
+        {
+            string Month = DateTime.Now.ToString("yyyyMM");
+            string check = function.ReadInstance("/LogoutUser/" + Month + ".txt");
+            if(string.IsNullOrEmpty(check))
+            {
+                function.WritePage("/LogoutUser/", Month + ".txt", DateTime.Now.ToString());
+                var users = db.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav, m.Status }).Where(m => m.Status == -1).ToList();
+                foreach(var user in users)
+                {
+                    int ParentUserId = user.ParentUserId;
+                    bool op = true;
+                    while(op)
+                    {
+                        Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId);
+                        if(puser != null)
+                        {
+                            if(puser.Status > -1)
+                            {
+                                op = false;
+                                RelationForUserSub(db, user.Id, puser);
+                                db.SaveChanges();
+                            }
+                            else
+                            {
+                                ParentUserId = puser.ParentUserId;
+                            }
+                        }
+                        else
+                        {
+                            op = false;
+                        }
+                    }
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月归档注销创客异常");
+        }
+        db.Dispose();
+        function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "每月归档注销创客日志");
+    }
+
+    private void RelationForUserSub(WebCMSEntities db, int ParentUserId, Users puser)
+    {
+        var subusers = db.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
+        foreach (var subuser in subusers)
+        {
+            Users user = db.Users.FirstOrDefault(m => m.Id == subuser.Id);
+            if (user != null)
+            {
+                user.ParentUserId = puser.Id;
+                user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
+                RelationForUserSub(db, user.Id, user);
+            }
+        }
+    }
+}