Browse Source

运营中心定时程序

lichunlei 2 years ago
parent
commit
08636fda81

+ 121 - 0
AppStart/Helper/OperateService.cs

@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Threading;
+using MySystem.PxcModels;
+using Library;
+
+namespace MySystem
+{
+    /// <summary>
+    /// 运营中心定时程序
+    /// </summary>
+    public class OperateService
+    {
+        public readonly static OperateService Instance = new OperateService();
+        private OperateService()
+        { }
+
+
+        #region 每天统计一次数据
+        public void Start()
+        {
+            Thread th = new Thread(doSomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void doSomething()
+        {
+            while (true)
+            {
+                if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 4)
+                {
+                    try
+                    {
+                        string Month = DateTime.Now.ToString("yyyyMM");
+                        string Date = DateTime.Now.ToString("yyyyMMdd");
+                        string check = function.ReadInstance("/Operate/" + Month + ".txt");
+                        if (string.IsNullOrEmpty(check))
+                        {
+                            function.WritePage("/Operate/", "" + Month + ".txt", DateTime.Now.ToString("HH:mm:ss"));
+                            WebCMSEntities db = new WebCMSEntities();
+                            OpModels.WebCMSEntities opdb = new OpModels.WebCMSEntities();
+
+                            //统计发货量
+                            Dictionary<int, int> OpData = new Dictionary<int, int>();
+                            if(DateTime.Now.Day == 1)
+                            {
+                                var list = opdb.SendMonthSummary.Select(m => new { m.TradeMonth, m.OpId, m.SendCount }).Where(m => m.TradeMonth == Month).ToList();
+                                foreach(var sub in list)
+                                {
+                                    if(OpData.ContainsKey(sub.OpId))
+                                    {
+                                        OpData[sub.OpId] += sub.SendCount;
+                                    }
+                                    else
+                                    {
+                                        OpData.Add(sub.OpId, sub.SendCount);
+                                    }
+                                }
+                                foreach(int OpId in OpData.Keys)
+                                {
+                                    Users user = db.Users.FirstOrDefault(m => m.Id == OpId);
+                                    if(user != null)
+                                    {
+                                        user.ThisMonthSend = OpData[OpId];
+                                    }
+                                }
+                                db.SaveChanges();
+                            }
+                            OpData.Clear();
+                            var datelist = opdb.SendDaySummary.Select(m => new { m.TradeDate, m.OpId, m.SendCount }).Where(m => m.TradeDate == Date).ToList();
+                            foreach(var sub in datelist)
+                            {
+                                if(OpData.ContainsKey(sub.OpId))
+                                {
+                                    OpData[sub.OpId] += sub.SendCount;
+                                }
+                                else
+                                {
+                                    OpData.Add(sub.OpId, sub.SendCount);
+                                }
+                            }
+                            foreach(int OpId in OpData.Keys)
+                            {
+                                Users user = db.Users.FirstOrDefault(m => m.Id == OpId);
+                                if(user != null)
+                                {
+                                    user.ThisMonthSend += OpData[OpId];
+                                }
+                            }
+                            db.SaveChanges();
+
+                            //统计库存
+                            Dictionary<int, int> StoreList = db.StoreHouse.Select(m => new { m.UserId, m.LaveNum }).Where(m => m.LaveNum > 0).GroupBy(m => m.UserId).Select(m => new { UserId = m.Key, Count = m.Count() }).ToDictionary(m => m.UserId, m => m.Count);
+                            foreach(int UserId in StoreList.Keys)
+                            {
+                                Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
+                                if(user != null)
+                                {
+                                    user.StoreStock += StoreList[UserId];
+                                }
+                            }
+                            db.SaveChanges();
+
+                            opdb.Dispose();
+                            db.Dispose();
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "运营中心重置本月发货量异常");
+                    }
+                }
+                Thread.Sleep(800000);
+            }
+        }
+        #endregion
+    }
+}

+ 3 - 0
Models/Users.cs

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

+ 6 - 0
Models/WebCMSEntities.cs

@@ -17755,6 +17755,8 @@ namespace MySystem.Models
                     .HasCharSet("utf8")
                     .HasCollation("utf8_general_ci");
 
+                entity.Property(e => e.CreateStoreDate).HasColumnType("datetime");
+
                 entity.Property(e => e.DeviceId)
                     .HasColumnType("varchar(128)")
                     .HasCharSet("utf8")
@@ -17944,11 +17946,15 @@ namespace MySystem.Models
 
                 entity.Property(e => e.Status).HasColumnType("int(11)");
 
+                entity.Property(e => e.StoreStock).HasColumnType("int(11)");
+
                 entity.Property(e => e.Tags)
                     .HasColumnType("varchar(200)")
                     .HasCharSet("utf8")
                     .HasCollation("utf8_general_ci");
 
+                entity.Property(e => e.ThisMonthSend).HasColumnType("int(11)");
+
                 entity.Property(e => e.ThisMonthTrade).HasColumnType("decimal(18,2)");
 
                 entity.Property(e => e.UpdateDate).HasColumnType("datetime");

+ 20 - 0
OpModels/PosCoupons.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.OpModels
+{
+    public partial class PosCoupons
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int QueryCount { get; set; }
+        public int Status { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string SeoTitle { get; set; }
+        public string SeoKeyword { get; set; }
+        public string SeoDescription { get; set; }
+        public int PosCouponId { get; set; }
+        public int OpId { get; set; }
+    }
+}

+ 21 - 0
OpModels/PosMachines.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.OpModels
+{
+    public partial class PosMachines
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int QueryCount { get; set; }
+        public int Status { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string SeoTitle { get; set; }
+        public string SeoKeyword { get; set; }
+        public string SeoDescription { get; set; }
+        public int PosId { get; set; }
+        public int OpId { get; set; }
+        public int BrandId { get; set; }
+    }
+}

+ 27 - 0
OpModels/StoreMachineApply.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.OpModels
+{
+    public partial class StoreMachineApply
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int QueryCount { get; set; }
+        public int Status { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string SeoTitle { get; set; }
+        public string SeoKeyword { get; set; }
+        public string SeoDescription { get; set; }
+        public int UserId { get; set; }
+        public string SendSn { get; set; }
+        public string ErpCode { get; set; }
+        public string SendMode { get; set; }
+        public decimal UseAmount { get; set; }
+        public int SendNum { get; set; }
+        public int ApplyNum { get; set; }
+        public string ApplyNo { get; set; }
+        public int BrandId { get; set; }
+    }
+}

+ 1 - 0
OpModels/SysAdmin.cs

@@ -30,5 +30,6 @@ namespace MySystem.OpModels
         public string RealName { get; set; }
         public string Password { get; set; }
         public string AdminName { get; set; }
+        public int TotalMachineCount { get; set; }
     }
 }

+ 135 - 0
OpModels/WebCMSEntities.cs

@@ -39,11 +39,14 @@ namespace MySystem.OpModels
         public virtual DbSet<PosCouponMonthSummary> PosCouponMonthSummary { get; set; }
         public virtual DbSet<PosCouponOrders> PosCouponOrders { get; set; }
         public virtual DbSet<PosCouponRecord> PosCouponRecord { get; set; }
+        public virtual DbSet<PosCoupons> PosCoupons { get; set; }
+        public virtual DbSet<PosMachines> PosMachines { get; set; }
         public virtual DbSet<PublicAccountSet> PublicAccountSet { get; set; }
         public virtual DbSet<RightDic> RightDic { get; set; }
         public virtual DbSet<SendDaySummary> SendDaySummary { get; set; }
         public virtual DbSet<SendMonthSummary> SendMonthSummary { get; set; }
         public virtual DbSet<StoreForOperate> StoreForOperate { get; set; }
+        public virtual DbSet<StoreMachineApply> StoreMachineApply { get; set; }
         public virtual DbSet<SysAdmin> SysAdmin { get; set; }
         public virtual DbSet<SysAdminRole> SysAdminRole { get; set; }
         public virtual DbSet<SysLog> SysLog { get; set; }
@@ -1569,6 +1572,76 @@ namespace MySystem.OpModels
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
+            modelBuilder.Entity<PosCoupons>(entity =>
+            {
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate).HasColumnType("datetime");
+
+                entity.Property(e => e.OpId).HasColumnType("int(11)");
+
+                entity.Property(e => e.PosCouponId).HasColumnType("int(11)");
+
+                entity.Property(e => e.QueryCount).HasColumnType("int(11)");
+
+                entity.Property(e => e.SeoDescription)
+                    .HasColumnType("varchar(500)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoKeyword)
+                    .HasColumnType("varchar(200)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoTitle)
+                    .HasColumnType("varchar(100)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort).HasColumnType("int(11)");
+
+                entity.Property(e => e.Status).HasColumnType("int(11)");
+
+                entity.Property(e => e.UpdateDate).HasColumnType("datetime");
+            });
+
+            modelBuilder.Entity<PosMachines>(entity =>
+            {
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.BrandId).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate).HasColumnType("datetime");
+
+                entity.Property(e => e.OpId).HasColumnType("int(11)");
+
+                entity.Property(e => e.PosId).HasColumnType("int(11)");
+
+                entity.Property(e => e.QueryCount).HasColumnType("int(11)");
+
+                entity.Property(e => e.SeoDescription)
+                    .HasColumnType("varchar(500)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoKeyword)
+                    .HasColumnType("varchar(200)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoTitle)
+                    .HasColumnType("varchar(100)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort).HasColumnType("int(11)");
+
+                entity.Property(e => e.Status).HasColumnType("int(11)");
+
+                entity.Property(e => e.UpdateDate).HasColumnType("datetime");
+            });
+
             modelBuilder.Entity<PublicAccountSet>(entity =>
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");
@@ -1946,6 +2019,66 @@ namespace MySystem.OpModels
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
+            modelBuilder.Entity<StoreMachineApply>(entity =>
+            {
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.ApplyNo)
+                    .HasColumnType("varchar(50)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.ApplyNum).HasColumnType("int(11)");
+
+                entity.Property(e => e.BrandId).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate).HasColumnType("datetime");
+
+                entity.Property(e => e.ErpCode)
+                    .HasColumnType("varchar(50)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.QueryCount).HasColumnType("int(11)");
+
+                entity.Property(e => e.SendMode)
+                    .HasColumnType("varchar(50)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SendNum).HasColumnType("int(11)");
+
+                entity.Property(e => e.SendSn)
+                    .HasColumnType("mediumtext")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoDescription)
+                    .HasColumnType("varchar(500)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoKeyword)
+                    .HasColumnType("varchar(200)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoTitle)
+                    .HasColumnType("varchar(100)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort).HasColumnType("int(11)");
+
+                entity.Property(e => e.Status).HasColumnType("int(11)");
+
+                entity.Property(e => e.UpdateDate).HasColumnType("datetime");
+
+                entity.Property(e => e.UseAmount).HasColumnType("decimal(18,2)");
+
+                entity.Property(e => e.UserId).HasColumnType("int(11)");
+            });
+
             modelBuilder.Entity<SysAdmin>(entity =>
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");
@@ -2032,6 +2165,8 @@ namespace MySystem.OpModels
 
                 entity.Property(e => e.StoreCount).HasColumnType("int(11)");
 
+                entity.Property(e => e.TotalMachineCount).HasColumnType("int(11)");
+
                 entity.Property(e => e.UpdateDate).HasColumnType("datetime");
 
                 entity.Property(e => e.UpdateMan)

+ 3 - 0
PxcModels/Users.cs

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

+ 6 - 0
PxcModels/WebCMSEntities.cs

@@ -17755,6 +17755,8 @@ namespace MySystem.PxcModels
                     .HasCharSet("utf8")
                     .HasCollation("utf8_general_ci");
 
+                entity.Property(e => e.CreateStoreDate).HasColumnType("datetime");
+
                 entity.Property(e => e.DeviceId)
                     .HasColumnType("varchar(128)")
                     .HasCharSet("utf8")
@@ -17944,11 +17946,15 @@ namespace MySystem.PxcModels
 
                 entity.Property(e => e.Status).HasColumnType("int(11)");
 
+                entity.Property(e => e.StoreStock).HasColumnType("int(11)");
+
                 entity.Property(e => e.Tags)
                     .HasColumnType("varchar(200)")
                     .HasCharSet("utf8")
                     .HasCollation("utf8_general_ci");
 
+                entity.Property(e => e.ThisMonthSend).HasColumnType("int(11)");
+
                 entity.Property(e => e.ThisMonthTrade).HasColumnType("decimal(18,2)");
 
                 entity.Property(e => e.UpdateDate).HasColumnType("datetime");

+ 1 - 0
Startup.cs

@@ -213,6 +213,7 @@ namespace MySystem
             SetDepositPostService.Instance.StartKdb(); //监控开店宝费率设置结果
             SetFeeFlagService.Instance.Start(); //178天提前通知创客费率调升消息
             ResetSmallStoreHelper.Instance.Start(); //每月重置小分仓额度
+            OperateService.Instance.Start(); //运营中心每天统计一次发货量、库存
 
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数