Quellcode durchsuchen

重置分仓额度调为触发式

lichunlei vor 2 Jahren
Ursprung
Commit
4af7f3b265

+ 48 - 0
AppStart/Helper/Operate/OperateStockService.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using LitJson;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.OpModels;
+
+namespace MySystem
+{
+    public class OperateStockService
+    {
+        public readonly static OperateStockService Instance = new OperateStockService();
+        private OperateStockService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(dosomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void dosomething()
+        {
+            while (true)
+            {
+                try
+                {
+                    string sql = "";
+                    string conn = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
+                    DataTable dt = CustomerSqlConn.dtable("select UserId,sum(LaveNum) from StoreHouse where `Status`>-1 group by UserId", conn);
+                    foreach(DataRow dr in dt.Rows)
+                    {
+                        sql += "update Users set StoreStock=" + dr[1].ToString() + " where Id=" + dr["UserId"].ToString() + ";";
+                    }
+                    CustomerSqlConn.op(sql, conn);
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "运营中心返额度异常");
+                }
+                Thread.Sleep(600000);
+            }
+        }
+    }
+}

+ 1 - 1
AppStart/Helper/SetFeeFlagService.cs

@@ -44,7 +44,7 @@ namespace MySystem
                             BrandIds.Add(4);
                             BrandIds.Add(5);
                             BrandIds.Add(7);
-                            var date = DateTime.Now.AddDays(-178);
+                            var date = DateTime.Now.AddDays(-118);
                             bool op = true;
                             int StartId = 0;
                             while(op)

+ 151 - 115
AppStart/Timer/StoreApplyHelper.cs

@@ -40,121 +40,7 @@ public class StoreApplyHelper
                     if(string.IsNullOrEmpty(check))
                     {
                         function.WritePage("/StoreApply/", DateTime.Now.ToString("yyyyMM") + ".txt", DateTime.Now.ToString());
-                        Dictionary<int, decimal> dataDic = new Dictionary<int, decimal>();
-                        string pre = DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01 00:00:00";
-                        string start = DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00";
-                        string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
-                        //上月出货额度
-                        DataTable dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (1,2,4,6,7,8) and TransType in (10,11,2) and StoreId>0 group by StoreId");
-                        foreach(DataRow dr in dt.Rows)
-                        {
-                            int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
-                            int Count = int.Parse(function.CheckInt(dr[1].ToString()));
-                            decimal AmountMore = Count * 200;
-                            StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
-                            if(!dataDic.ContainsKey(store.UserId))
-                            {
-                                dataDic.Add(store.UserId, AmountMore);
-                            }
-                            else
-                            {
-                                dataDic[store.UserId] += AmountMore;
-                            }
-                        }
-                        dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (3,5,9) and TransType in (10,11,2) and StoreId>0 group by StoreId");
-                        foreach(DataRow dr in dt.Rows)
-                        {
-                            int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
-                            int Count = int.Parse(function.CheckInt(dr[1].ToString()));
-                            decimal AmountMore = Count * 300;
-                            StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
-                            if(!dataDic.ContainsKey(store.UserId))
-                            {
-                                dataDic.Add(store.UserId, AmountMore);
-                            }
-                            else
-                            {
-                                dataDic[store.UserId] += AmountMore;
-                            }
-                        }
-                        //上月没出货的创库
-                        string ids = "0";
-                        foreach(int UserId in dataDic.Keys)
-                        {
-                            ids += "," + UserId;
-                        }
-                        DataTable dts = OtherMySqlConn.dtable("select distinct UserId from StoreHouse where UserId not in (" + ids + ") and Status>-1");
-                        foreach(DataRow dr in dts.Rows)
-                        {
-                            int UserId = int.Parse(function.CheckInt(dr[0].ToString()));
-                            if(!dataDic.ContainsKey(UserId))
-                            {
-                                dataDic.Add(UserId, 0);
-                            }
-                        }
-                        foreach(int UserId in dataDic.Keys)
-                        {
-                            decimal Amount = dataDic[UserId];
-                            //上月出货额度与保底额度之间取较高值
-                            if(Amount < 10000 && SpecialUsers10000().Contains(UserId))
-                            {
-                                Amount = 10000;
-                            }
-                            else if(Amount < 20000 && !SpecialUsers0().Contains(UserId))
-                            {
-                                Amount = 20000;
-                            }
-                            //被担保额度
-                            decimal PromissAmount = 0;
-                            dt = OtherMySqlConn.dtable("select PromissAmount from StoreHouseAmountPromiss where ToUserId=" + UserId + " and Status=1");
-                            foreach(DataRow dr in dt.Rows)
-                            {
-                                PromissAmount += decimal.Parse(function.CheckNum(dr["PromissAmount"].ToString()));
-                            }
-                            decimal AmountMore = 0;
-                            //仓库中机具占用额度+小分仓机具占用额度
-                            DataTable dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (1,2,4,6,7,8) and `Status`>-1");
-                            if(dtmore.Rows.Count > 0)
-                            {
-                                AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
-                            }
-                            dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (3,5,9) and `Status`>-1");
-                            if(dtmore.Rows.Count > 0)
-                            {
-                                AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
-                            }
-                            //除开小分仓中带“授”标记机具占用额度
-                            dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (1,2,4,6,7,8) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
-                            if(dtmore.Rows.Count > 0)
-                            {
-                                AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
-                            }
-                            dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (3,5,9) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
-                            if(dtmore.Rows.Count > 0)
-                            {
-                                AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
-                            }
-                            //申请补货订单占用额度
-                            dt = OtherMySqlConn.dtable("select UseAmount from StoreMachineApply where UserId=" + UserId + " and Status=0");
-                            foreach(DataRow dr in dt.Rows)
-                            {
-                                AmountMore += decimal.Parse(function.CheckNum(dr["UseAmount"].ToString()));
-                            }
-                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
-                            if (account == null)
-                            {
-                                account = db.UserAccount.Add(new UserAccount()
-                                {
-                                    Id = UserId,
-                                    UserId = UserId,
-                                }).Entity;
-                                db.SaveChanges();
-                            }
-                            account.FixedAmount = Amount;
-                            account.ValidAmount = Amount + PromissAmount + account.TempAmount - AmountMore;
-                            function.WriteLog("UserId:" + UserId + ";FixedAmount:" + account.FixedAmount + ";AmountMore:" + AmountMore + ";ValidAmount:" + account.ValidAmount, "计算分仓申请机具额度日志");
-                        }
-                        db.SaveChanges();
+                        DoSomething(db);
                     }
                 }
             }
@@ -168,6 +54,156 @@ public class StoreApplyHelper
         }
     }
 
+    public void ResetStoreReserve()
+    {
+        Thread th = new Thread(ResetStoreReserveDo);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void ResetStoreReserveDo()
+    {
+        while (true)
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            try
+            {
+                string data = RedisDbconn.Instance.RPop<string>("ResetStoreReserveQueue");
+                if(!string.IsNullOrEmpty(data))
+                {
+                    int UserId = int.Parse(data);
+                    if(UserId > 0) DoSomething(db, UserId);
+                }
+            }
+            catch(Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "重置分仓额度异常");
+            }
+            db.Dispose();
+        }
+    }
+
+    private void DoSomething(WebCMSEntities db, int UId = 0)
+    {
+        Dictionary<int, decimal> dataDic = new Dictionary<int, decimal>();
+        string pre = DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01 00:00:00";
+        string start = DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00";
+        string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
+        string condition = "";
+        if(UId > 0)
+        {
+            condition = " and StoreId in (select Id from StoreHouse where UserId=" + UId + ")";
+        }
+        //上月出货额度
+        DataTable dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (1,2,4,6,7,8) and TransType in (10,11,2) and StoreId>0" + condition + " group by StoreId");
+        foreach(DataRow dr in dt.Rows)
+        {
+            int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
+            int Count = int.Parse(function.CheckInt(dr[1].ToString()));
+            decimal AmountMore = Count * 200;
+            StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
+            if(!dataDic.ContainsKey(store.UserId))
+            {
+                dataDic.Add(store.UserId, AmountMore);
+            }
+            else
+            {
+                dataDic[store.UserId] += AmountMore;
+            }
+        }
+        dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (3,5,9) and TransType in (10,11,2) and StoreId>0" + condition + " group by StoreId");
+        foreach(DataRow dr in dt.Rows)
+        {
+            int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
+            int Count = int.Parse(function.CheckInt(dr[1].ToString()));
+            decimal AmountMore = Count * 300;
+            StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
+            if(!dataDic.ContainsKey(store.UserId))
+            {
+                dataDic.Add(store.UserId, AmountMore);
+            }
+            else
+            {
+                dataDic[store.UserId] += AmountMore;
+            }
+        }
+        //上月没出货的创库
+        string ids = "0";
+        foreach(int UserId in dataDic.Keys)
+        {
+            ids += "," + UserId;
+        }
+        DataTable dts = OtherMySqlConn.dtable("select distinct UserId from StoreHouse where UserId not in (" + ids + ") and Status>-1");
+        foreach(DataRow dr in dts.Rows)
+        {
+            int UserId = int.Parse(function.CheckInt(dr[0].ToString()));
+            if(!dataDic.ContainsKey(UserId))
+            {
+                dataDic.Add(UserId, 0);
+            }
+        }
+        foreach(int UserId in dataDic.Keys)
+        {
+            decimal Amount = dataDic[UserId];
+            //上月出货额度与保底额度之间取较高值,保底额度为押金的两倍                            
+            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
+            if (account == null)
+            {
+                account = db.UserAccount.Add(new UserAccount()
+                {
+                    Id = UserId,
+                    UserId = UserId,
+                }).Entity;
+                db.SaveChanges();
+            }
+            decimal StoreDeposit = account.StoreDeposit;
+            if(Amount < StoreDeposit * 2)
+            {
+                Amount = StoreDeposit * 2;
+            }
+            //被担保额度
+            decimal PromissAmount = 0;
+            dt = OtherMySqlConn.dtable("select PromissAmount from StoreHouseAmountPromiss where ToUserId=" + UserId + " and Status=1");
+            foreach(DataRow dr in dt.Rows)
+            {
+                PromissAmount += decimal.Parse(function.CheckNum(dr["PromissAmount"].ToString()));
+            }
+            decimal AmountMore = 0;
+            //仓库中机具占用额度+小分仓机具占用额度
+            DataTable dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (1,2,4,6,7,8) and `Status`>-1");
+            if(dtmore.Rows.Count > 0)
+            {
+                AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
+            }
+            dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (3,5,9) and `Status`>-1");
+            if(dtmore.Rows.Count > 0)
+            {
+                AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
+            }
+            //除开小分仓中带“授”标记机具占用额度
+            dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (1,2,4,6,7,8) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
+            if(dtmore.Rows.Count > 0)
+            {
+                AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
+            }
+            dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (3,5,9) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
+            if(dtmore.Rows.Count > 0)
+            {
+                AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
+            }
+            //申请补货订单占用额度
+            dt = OtherMySqlConn.dtable("select UseAmount from StoreMachineApply where UserId=" + UserId + " and Status=0");
+            foreach(DataRow dr in dt.Rows)
+            {
+                AmountMore += decimal.Parse(function.CheckNum(dr["UseAmount"].ToString()));
+            }
+            account.FixedAmount = Amount;
+            account.ValidAmount = Amount + PromissAmount + account.TempAmount - AmountMore;
+            function.WriteLog("UserId:" + UserId + ";FixedAmount:" + account.FixedAmount + ";AmountMore:" + AmountMore + ";ValidAmount:" + account.ValidAmount, "计算分仓申请机具额度日志");
+        }
+        db.SaveChanges();
+    }
+
     public void StartEverTime()
     {
         Thread th = new Thread(StartEverTimeDo);

+ 1 - 0
Models/PosCouponRecord.cs

@@ -19,5 +19,6 @@ namespace MySystem.Models
         public int ToUserId { get; set; }
         public int FromUserId { get; set; }
         public int PosCouponId { get; set; }
+        public int OpId { get; set; }
     }
 }

+ 1 - 0
Models/UserAccount.cs

@@ -42,5 +42,6 @@ namespace MySystem.Models
         public decimal ThisMonthPreAmount { get; set; }
         public decimal ValidPreAmount { get; set; }
         public decimal SmallStoreDeposit { get; set; }
+        public decimal StoreDeposit { get; set; }
     }
 }

+ 3 - 0
Models/Users.cs

@@ -91,5 +91,8 @@ namespace MySystem.Models
         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; }
     }
 }

+ 15 - 0
Models/WebCMSEntities.cs

@@ -8259,6 +8259,8 @@ namespace MySystem.Models
 
                 entity.Property(e => e.FromUserId).HasColumnType("int(11)");
 
+                entity.Property(e => e.OpId).HasColumnType("int(11)");
+
                 entity.Property(e => e.OrderNo)
                     .HasColumnType("varchar(50)")
                     .HasCharSet("utf8")
@@ -15100,6 +15102,8 @@ namespace MySystem.Models
 
                 entity.Property(e => e.Status).HasColumnType("int(11)");
 
+                entity.Property(e => e.StoreDeposit).HasColumnType("decimal(18,2)");
+
                 entity.Property(e => e.TeamTotalOverProfit).HasColumnType("decimal(18,2)");
 
                 entity.Property(e => e.TeamTotalProfit).HasColumnType("decimal(18,2)");
@@ -17809,6 +17813,10 @@ namespace MySystem.Models
                     .HasColumnType("bit(1)")
                     .HasDefaultValueSql("b'0'");
 
+                entity.Property(e => e.IsSign)
+                    .HasColumnType("bit(1)")
+                    .HasDefaultValueSql("b'0'");
+
                 entity.Property(e => e.LeaderLevel).HasColumnType("int(11)");
 
                 entity.Property(e => e.LockStatus)
@@ -17937,11 +17945,18 @@ namespace MySystem.Models
 
                 entity.Property(e => e.Sex).HasColumnType("int(11)");
 
+                entity.Property(e => e.SignDate).HasColumnType("datetime");
+
                 entity.Property(e => e.SignImgUrl)
                     .HasColumnType("varchar(200)")
                     .HasCharSet("utf8")
                     .HasCollation("utf8_general_ci");
 
+                entity.Property(e => e.SignPic)
+                    .HasColumnType("varchar(200)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
                 entity.Property(e => e.Sort).HasColumnType("int(11)");
 
                 entity.Property(e => e.Status).HasColumnType("int(11)");

+ 1 - 0
PxcModels/PosCouponRecord.cs

@@ -19,5 +19,6 @@ namespace MySystem.PxcModels
         public int ToUserId { get; set; }
         public int FromUserId { get; set; }
         public int PosCouponId { get; set; }
+        public int OpId { get; set; }
     }
 }

+ 1 - 0
PxcModels/UserAccount.cs

@@ -42,5 +42,6 @@ namespace MySystem.PxcModels
         public decimal ThisMonthPreAmount { get; set; }
         public decimal ValidPreAmount { get; set; }
         public decimal SmallStoreDeposit { get; set; }
+        public decimal StoreDeposit { get; set; }
     }
 }

+ 3 - 0
PxcModels/Users.cs

@@ -91,5 +91,8 @@ namespace MySystem.PxcModels
         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; }
     }
 }

+ 15 - 0
PxcModels/WebCMSEntities.cs

@@ -8259,6 +8259,8 @@ namespace MySystem.PxcModels
 
                 entity.Property(e => e.FromUserId).HasColumnType("int(11)");
 
+                entity.Property(e => e.OpId).HasColumnType("int(11)");
+
                 entity.Property(e => e.OrderNo)
                     .HasColumnType("varchar(50)")
                     .HasCharSet("utf8")
@@ -15100,6 +15102,8 @@ namespace MySystem.PxcModels
 
                 entity.Property(e => e.Status).HasColumnType("int(11)");
 
+                entity.Property(e => e.StoreDeposit).HasColumnType("decimal(18,2)");
+
                 entity.Property(e => e.TeamTotalOverProfit).HasColumnType("decimal(18,2)");
 
                 entity.Property(e => e.TeamTotalProfit).HasColumnType("decimal(18,2)");
@@ -17809,6 +17813,10 @@ namespace MySystem.PxcModels
                     .HasColumnType("bit(1)")
                     .HasDefaultValueSql("b'0'");
 
+                entity.Property(e => e.IsSign)
+                    .HasColumnType("bit(1)")
+                    .HasDefaultValueSql("b'0'");
+
                 entity.Property(e => e.LeaderLevel).HasColumnType("int(11)");
 
                 entity.Property(e => e.LockStatus)
@@ -17937,11 +17945,18 @@ namespace MySystem.PxcModels
 
                 entity.Property(e => e.Sex).HasColumnType("int(11)");
 
+                entity.Property(e => e.SignDate).HasColumnType("datetime");
+
                 entity.Property(e => e.SignImgUrl)
                     .HasColumnType("varchar(200)")
                     .HasCharSet("utf8")
                     .HasCollation("utf8_general_ci");
 
+                entity.Property(e => e.SignPic)
+                    .HasColumnType("varchar(200)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
                 entity.Property(e => e.Sort).HasColumnType("int(11)");
 
                 entity.Property(e => e.Status).HasColumnType("int(11)");

+ 2 - 0
Startup.cs

@@ -217,6 +217,8 @@ namespace MySystem
             // ResetSmallStoreHelper.Instance.Start(); //每月重置小分仓额度
             OperateService.Instance.Start(); //运营中心每天统计一次发货量、库存
             OperateAmountService.Instance.Start(); //运营中心额度变更
+            OperateStockService.Instance.Start(); //运营中心库存实时更新
+            StoreApplyHelper.Instance.ResetStoreReserve(); //重置分仓额度
 
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数