Browse Source

Merge branch 'main' of http://47.109.31.237:13000/lichunlei/mp-main-v2 into DuGuYang

DuGuYang 11 months ago
parent
commit
c1e6e4d9c0

+ 52 - 3
Controllers/HomeController.cs

@@ -29,7 +29,7 @@ namespace MySystem.Controllers
             return View();
         }
 
-        public string test(decimal a, decimal b, decimal g)
+        public string test()
         {
             // List<int> MerchantIds = new List<int>();
             // MerchantIds.Add(5);
@@ -40,7 +40,56 @@ namespace MySystem.Controllers
             // TianYuVoiceHelper.Instance.doSomething(DateTime.Now.ToString("yyyyMMddHHmmssfff"),"2023100701","100");
             // MqLinksHelper.Instance.doSomething("LKB01230600250000585","100");
 
-            // WebCMSEntities db = new WebCMSEntities();
+            WebCMSEntities db = new WebCMSEntities();
+            DateTime start = DateTime.Parse("2024-03-10 00:00:00");
+            List<ConsumerOrders> orders = db.ConsumerOrders.Where(m => m.Status > 0 && m.IsAct == 1 && m.CreateDate > start && m.CurDivi < m.MaxDivi && m.SettleAmount > 0).OrderBy(m => m.Id).ToList();
+            foreach(ConsumerOrders order in orders)
+            {
+                bool check = RedisDbconn.Instance.GetList<ConsumerOrders>("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId, 1, 10000).Any(m => m.Id == order.Id);
+                bool check1 = db.ConsumerProfit.Any(m => m.OrderId == order.Id);
+                if(!check && !check1)
+                {
+                    RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
+                    ConsumerOrders edit = db.ConsumerOrders.FirstOrDefault(m => m.Id == order.Id);
+                    if(edit != null)
+                    {
+                        edit.ReturnFlag = 1;
+                        db.SaveChanges();
+                    }
+                }
+                else
+                {
+                    if(!check)
+                    {
+                        RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId, order);
+                        ConsumerOrders edit = db.ConsumerOrders.FirstOrDefault(m => m.Id == order.Id);
+                        if(edit != null)
+                        {
+                            edit.ReturnFlag = 1;
+                            db.SaveChanges();
+                        }
+                    }
+                    else if(!check1)
+                    {
+                        ConsumerOrders edit = RedisDbconn.Instance.GetList<ConsumerOrders>("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId, 1, 10000).FirstOrDefault(m => m.Id == order.Id);
+                        long count = RedisDbconn.Instance.DelFromList("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId,edit);
+                        if(count > 0)
+                        {
+                            RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
+                        }
+                    }
+                }
+                if(order.ReturnFlag == 0 && check && check1)
+                {
+                    ConsumerOrders edit = db.ConsumerOrders.FirstOrDefault(m => m.Id == order.Id);
+                    if(edit != null)
+                    {
+                        edit.ReturnFlag = 1;
+                        db.SaveChanges();
+                    }
+                }
+            }
+
             // Dictionary<string, decimal> ids = new Dictionary<string, decimal>();
             // ids.Add("2023123120272680842405573", 30.08M);
             // foreach(string orderno in ids.Keys)
@@ -167,7 +216,7 @@ namespace MySystem.Controllers
             //     function.WriteLog("\n\n", "返现id");
             // }
 
-            // db.Dispose();
+            db.Dispose();
 
             // RedisDbconn.Instance.AddRightList("testlist", "1");
             // RedisDbconn.Instance.AddRightList("testlist", "2");

+ 14 - 0
Entity/AgentProfit.cs

@@ -0,0 +1,14 @@
+using System;
+namespace MySystem
+{
+    public class AgentProfit
+    {
+        public int IsAct { get; set; }
+        public string ManageAreas { get; set; }
+        public int AgentLevel { get; set; }
+        public decimal TotalAmount { get; set; }
+        public decimal Percent { get; set; }
+        public decimal Profit { get; set; }
+        public decimal ProfitResult { get; set; }
+    }
+}

+ 17 - 0
Models/Main/AgentLevels.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models.Main
+{
+    public partial class AgentLevels
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int Status { get; set; }
+        public int Version { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string Name { get; set; }
+        public decimal Percent { get; set; }
+    }
+}

+ 22 - 0
Models/Main/AgentProfitRecord.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models.Main
+{
+    public partial class AgentProfitRecord
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int Status { get; set; }
+        public int Version { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string TradeMonth { get; set; }
+        public string Remark { get; set; }
+        public int CheckStatus { get; set; }
+        public decimal TradeProfit { get; set; }
+        public decimal CreditTradeAmt { get; set; }
+        public int ProfitType { get; set; }
+        public int UserId { get; set; }
+    }
+}

+ 23 - 0
Models/Main/AgentTradeStatSummary.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models.Main
+{
+    public partial class AgentTradeStatSummary
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int Status { get; set; }
+        public int Version { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string ManageAreas { get; set; }
+        public int IsAct { get; set; }
+        public int TradeCount { get; set; }
+        public int PayMode { get; set; }
+        public decimal TotalAmount { get; set; }
+        public string TradeMonth { get; set; }
+        public string TradeDate { get; set; }
+        public int UserId { get; set; }
+    }
+}

+ 164 - 0
Models/Main/WebCMSEntities.cs

@@ -24,6 +24,9 @@ namespace MySystem.Models.Main
         public virtual DbSet<ActivityRedPackageTop10> ActivityRedPackageTop10 { get; set; }
         public virtual DbSet<Advertisment> Advertisment { get; set; }
         public virtual DbSet<AgentLevelSet> AgentLevelSet { get; set; }
+        public virtual DbSet<AgentLevels> AgentLevels { get; set; }
+        public virtual DbSet<AgentProfitRecord> AgentProfitRecord { get; set; }
+        public virtual DbSet<AgentTradeStatSummary> AgentTradeStatSummary { get; set; }
         public virtual DbSet<AppBottomNavs> AppBottomNavs { get; set; }
         public virtual DbSet<AppVersion> AppVersion { get; set; }
         public virtual DbSet<AppVideo> AppVideo { get; set; }
@@ -925,6 +928,167 @@ namespace MySystem.Models.Main
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
+            modelBuilder.Entity<AgentLevels>(entity =>
+            {
+                entity.HasComment("区域代理等级");
+
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("创建时间");
+
+                entity.Property(e => e.Name)
+                    .HasColumnType("varchar(50)")
+                    .HasComment("名称")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Percent)
+                    .HasColumnType("decimal(18,2)")
+                    .HasComment("分润比例");
+
+                entity.Property(e => e.Sort)
+                    .HasColumnType("int(11)")
+                    .HasComment("排序序号");
+
+                entity.Property(e => e.Status)
+                    .HasColumnType("int(11)")
+                    .HasComment("状态");
+
+                entity.Property(e => e.UpdateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("修改时间");
+
+                entity.Property(e => e.Version)
+                    .HasColumnType("int(11)")
+                    .HasComment("版本号");
+            });
+
+            modelBuilder.Entity<AgentProfitRecord>(entity =>
+            {
+                entity.HasComment("区域代理等级");
+
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CheckStatus)
+                    .HasColumnType("int(11)")
+                    .HasComment("验证和同步账户状态");
+
+                entity.Property(e => e.CreateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("创建时间");
+
+                entity.Property(e => e.CreditTradeAmt)
+                    .HasColumnType("decimal(18,2)")
+                    .HasComment("贷记卡交易总金额");
+
+                entity.Property(e => e.ProfitType)
+                    .HasColumnType("int(11)")
+                    .HasComment("创客分润类型");
+
+                entity.Property(e => e.Remark)
+                    .HasColumnType("varchar(64)")
+                    .HasComment("备注")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort)
+                    .HasColumnType("int(11)")
+                    .HasComment("排序序号");
+
+                entity.Property(e => e.Status)
+                    .HasColumnType("int(11)")
+                    .HasComment("状态");
+
+                entity.Property(e => e.TradeMonth)
+                    .HasColumnType("varchar(6)")
+                    .HasComment("交易月")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.TradeProfit)
+                    .HasColumnType("decimal(18,2)")
+                    .HasComment("交易分润");
+
+                entity.Property(e => e.UpdateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("修改时间");
+
+                entity.Property(e => e.UserId)
+                    .HasColumnType("int(11)")
+                    .HasComment("创客");
+
+                entity.Property(e => e.Version)
+                    .HasColumnType("int(11)")
+                    .HasComment("版本号");
+            });
+
+            modelBuilder.Entity<AgentTradeStatSummary>(entity =>
+            {
+                entity.HasComment("创客区域代理");
+
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("创建时间");
+
+                entity.Property(e => e.IsAct)
+                    .HasColumnType("int(11)")
+                    .HasComment("是否活动");
+
+                entity.Property(e => e.ManageAreas)
+                    .HasColumnType("varchar(50)")
+                    .HasComment("管辖区域")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.PayMode)
+                    .HasColumnType("int(11)")
+                    .HasComment("支付方式");
+
+                entity.Property(e => e.Sort)
+                    .HasColumnType("int(11)")
+                    .HasComment("排序序号");
+
+                entity.Property(e => e.Status)
+                    .HasColumnType("int(11)")
+                    .HasComment("状态");
+
+                entity.Property(e => e.TotalAmount)
+                    .HasColumnType("decimal(18,2)")
+                    .HasComment("订单总额");
+
+                entity.Property(e => e.TradeCount)
+                    .HasColumnType("int(11)")
+                    .HasComment("交易笔数");
+
+                entity.Property(e => e.TradeDate)
+                    .HasColumnType("varchar(8)")
+                    .HasComment("交易日")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.TradeMonth)
+                    .HasColumnType("varchar(6)")
+                    .HasComment("交易月")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.UpdateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("修改时间");
+
+                entity.Property(e => e.UserId)
+                    .HasColumnType("int(11)")
+                    .HasComment("创客");
+
+                entity.Property(e => e.Version)
+                    .HasColumnType("int(11)")
+                    .HasComment("版本号");
+            });
+
             modelBuilder.Entity<AppBottomNavs>(entity =>
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");

+ 18 - 0
Models/Main1/AgentLevels.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models.Main1
+{
+    public partial class AgentLevels
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int Status { get; set; }
+        public int Version { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string Name { get; set; }
+        public decimal Percent { get; set; }
+        public decimal UnActPercent { get; set; }
+    }
+}

+ 22 - 0
Models/Main1/AgentProfitRecord.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models.Main1
+{
+    public partial class AgentProfitRecord
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int Status { get; set; }
+        public int Version { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string TradeMonth { get; set; }
+        public string Remark { get; set; }
+        public int CheckStatus { get; set; }
+        public decimal TradeProfit { get; set; }
+        public decimal CreditTradeAmt { get; set; }
+        public int ProfitType { get; set; }
+        public int UserId { get; set; }
+    }
+}

+ 23 - 0
Models/Main1/AgentTradeStatSummary.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models.Main1
+{
+    public partial class AgentTradeStatSummary
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int Status { get; set; }
+        public int Version { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string ManageAreas { get; set; }
+        public int IsAct { get; set; }
+        public int TradeCount { get; set; }
+        public int PayMode { get; set; }
+        public decimal TotalAmount { get; set; }
+        public string TradeMonth { get; set; }
+        public string TradeDate { get; set; }
+        public int UserId { get; set; }
+    }
+}

+ 19 - 0
Models/Main1/UserAgent.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models.Main1
+{
+    public partial class UserAgent
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int Status { get; set; }
+        public int Version { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public int AgentLevel { get; set; }
+        public string ManageAreas { get; set; }
+        public int UserId { get; set; }
+        public string Operator { get; set; }
+    }
+}

+ 216 - 0
Models/Main1/WebCMSEntities.cs

@@ -24,6 +24,9 @@ namespace MySystem.Models.Main1
         public virtual DbSet<ActivityRedPackageTop10> ActivityRedPackageTop10 { get; set; }
         public virtual DbSet<Advertisment> Advertisment { get; set; }
         public virtual DbSet<AgentLevelSet> AgentLevelSet { get; set; }
+        public virtual DbSet<AgentLevels> AgentLevels { get; set; }
+        public virtual DbSet<AgentProfitRecord> AgentProfitRecord { get; set; }
+        public virtual DbSet<AgentTradeStatSummary> AgentTradeStatSummary { get; set; }
         public virtual DbSet<AppBottomNavs> AppBottomNavs { get; set; }
         public virtual DbSet<AppVersion> AppVersion { get; set; }
         public virtual DbSet<AppVideo> AppVideo { get; set; }
@@ -237,6 +240,7 @@ namespace MySystem.Models.Main1
         public virtual DbSet<UserAccount> UserAccount { get; set; }
         public virtual DbSet<UserAccountRecord> UserAccountRecord { get; set; }
         public virtual DbSet<UserAddress> UserAddress { get; set; }
+        public virtual DbSet<UserAgent> UserAgent { get; set; }
         public virtual DbSet<UserAmountSummary> UserAmountSummary { get; set; }
         public virtual DbSet<UserAuthRecord> UserAuthRecord { get; set; }
         public virtual DbSet<UserBack> UserBack { get; set; }
@@ -928,6 +932,171 @@ namespace MySystem.Models.Main1
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
+            modelBuilder.Entity<AgentLevels>(entity =>
+            {
+                entity.HasComment("区域代理等级");
+
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("创建时间");
+
+                entity.Property(e => e.Name)
+                    .HasColumnType("varchar(50)")
+                    .HasComment("名称")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Percent)
+                    .HasColumnType("decimal(18,5)")
+                    .HasComment("分润比例");
+
+                entity.Property(e => e.Sort)
+                    .HasColumnType("int(11)")
+                    .HasComment("排序序号");
+
+                entity.Property(e => e.Status)
+                    .HasColumnType("int(11)")
+                    .HasComment("状态");
+
+                entity.Property(e => e.UnActPercent)
+                    .HasColumnType("decimal(18,5)")
+                    .HasComment("非活动分润比例");
+
+                entity.Property(e => e.UpdateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("修改时间");
+
+                entity.Property(e => e.Version)
+                    .HasColumnType("int(11)")
+                    .HasComment("版本号");
+            });
+
+            modelBuilder.Entity<AgentProfitRecord>(entity =>
+            {
+                entity.HasComment("区域代理等级");
+
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CheckStatus)
+                    .HasColumnType("int(11)")
+                    .HasComment("验证和同步账户状态");
+
+                entity.Property(e => e.CreateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("创建时间");
+
+                entity.Property(e => e.CreditTradeAmt)
+                    .HasColumnType("decimal(18,2)")
+                    .HasComment("贷记卡交易总金额");
+
+                entity.Property(e => e.ProfitType)
+                    .HasColumnType("int(11)")
+                    .HasComment("创客分润类型");
+
+                entity.Property(e => e.Remark)
+                    .HasColumnType("varchar(64)")
+                    .HasComment("备注")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort)
+                    .HasColumnType("int(11)")
+                    .HasComment("排序序号");
+
+                entity.Property(e => e.Status)
+                    .HasColumnType("int(11)")
+                    .HasComment("状态");
+
+                entity.Property(e => e.TradeMonth)
+                    .HasColumnType("varchar(6)")
+                    .HasComment("交易月")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.TradeProfit)
+                    .HasColumnType("decimal(18,2)")
+                    .HasComment("交易分润");
+
+                entity.Property(e => e.UpdateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("修改时间");
+
+                entity.Property(e => e.UserId)
+                    .HasColumnType("int(11)")
+                    .HasComment("创客");
+
+                entity.Property(e => e.Version)
+                    .HasColumnType("int(11)")
+                    .HasComment("版本号");
+            });
+
+            modelBuilder.Entity<AgentTradeStatSummary>(entity =>
+            {
+                entity.HasComment("创客区域代理");
+
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("创建时间");
+
+                entity.Property(e => e.IsAct)
+                    .HasColumnType("int(11)")
+                    .HasComment("是否活动");
+
+                entity.Property(e => e.ManageAreas)
+                    .HasColumnType("varchar(50)")
+                    .HasComment("管辖区域")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.PayMode)
+                    .HasColumnType("int(11)")
+                    .HasComment("支付方式");
+
+                entity.Property(e => e.Sort)
+                    .HasColumnType("int(11)")
+                    .HasComment("排序序号");
+
+                entity.Property(e => e.Status)
+                    .HasColumnType("int(11)")
+                    .HasComment("状态");
+
+                entity.Property(e => e.TotalAmount)
+                    .HasColumnType("decimal(18,2)")
+                    .HasComment("订单总额");
+
+                entity.Property(e => e.TradeCount)
+                    .HasColumnType("int(11)")
+                    .HasComment("交易笔数");
+
+                entity.Property(e => e.TradeDate)
+                    .HasColumnType("varchar(8)")
+                    .HasComment("交易日")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.TradeMonth)
+                    .HasColumnType("varchar(6)")
+                    .HasComment("交易月")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.UpdateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("修改时间");
+
+                entity.Property(e => e.UserId)
+                    .HasColumnType("int(11)")
+                    .HasComment("创客");
+
+                entity.Property(e => e.Version)
+                    .HasColumnType("int(11)")
+                    .HasComment("版本号");
+            });
+
             modelBuilder.Entity<AppBottomNavs>(entity =>
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");
@@ -16611,6 +16780,53 @@ namespace MySystem.Models.Main1
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
+            modelBuilder.Entity<UserAgent>(entity =>
+            {
+                entity.HasComment("创客区域代理");
+
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.AgentLevel)
+                    .HasColumnType("int(11)")
+                    .HasComment("等级");
+
+                entity.Property(e => e.CreateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("创建时间");
+
+                entity.Property(e => e.ManageAreas)
+                    .HasColumnType("varchar(50)")
+                    .HasComment("管辖区域")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Operator)
+                    .HasColumnType("varchar(50)")
+                    .HasComment("操作人")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort)
+                    .HasColumnType("int(11)")
+                    .HasComment("排序序号");
+
+                entity.Property(e => e.Status)
+                    .HasColumnType("int(11)")
+                    .HasComment("状态");
+
+                entity.Property(e => e.UpdateDate)
+                    .HasColumnType("datetime")
+                    .HasComment("修改时间");
+
+                entity.Property(e => e.UserId)
+                    .HasColumnType("int(11)")
+                    .HasComment("创客Id");
+
+                entity.Property(e => e.Version)
+                    .HasColumnType("int(11)")
+                    .HasComment("版本号");
+            });
+
             modelBuilder.Entity<UserAmountSummary>(entity =>
             {
                 entity.HasIndex(e => new { e.UserId, e.IsAct, e.TradeMonth, e.TradeDate, e.SeoTitle })

+ 110 - 0
Util/HaoDa/AgentProfitHelper.cs

@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Data;
+using Library;
+using LitJson;
+using System.Threading;
+using Microsoft.Extensions.Hosting;
+using System.Threading.Tasks;
+using MySystem.Models.Main;
+
+namespace MySystem
+{
+    public class AgentProfitHelper
+    {
+        public readonly static AgentProfitHelper Instance = new AgentProfitHelper();
+        private AgentProfitHelper()
+        {
+        }
+
+
+        public void StartListenProfit()
+        {
+            Thread th = new Thread(StartListenProfitDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartListenProfitDo()
+        {
+            while(true)
+            {
+                if(DateTime.Now.Day < 10 && DateTime.Now.Hour > 2 && DateTime.Now.Hour < 23)
+                {
+                    try
+                    {
+                        DoProfit();
+                    }
+                    catch(Exception ex)
+                    {
+                        LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "来客吧区域代理分润异常");
+                    }
+                    Thread.Sleep(600000);
+                }
+                else
+                {
+                    Thread.Sleep(3600000);
+                }
+            }
+        }
+
+        //分润算法
+        public void DoProfit()
+        {
+            string TradeMonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
+            string check = function.ReadInstance("/AgentProfitFlag/" + TradeMonth + ".txt");
+            if(!string.IsNullOrEmpty(check))
+            {
+                return;
+            }
+            function.WritePage("/AgentProfitFlag/", TradeMonth + ".txt", DateTime.Now.ToString());
+            MySystem.Models.Main1.WebCMSEntities dbnew1 = new MySystem.Models.Main1.WebCMSEntities();
+            WebCMSEntities dbnew = new WebCMSEntities();
+            List<AgentProfit> ProfitList = new List<AgentProfit>();
+            DataTable dt = CustomerSqlConn.dtable("select IsAct,ManageAreas,AgentLevel,TotalAmount,(case when IsAct=1 then l.Percent else l.UnActPercent end) Percent,(case when IsAct=1 then l.Percent*TotalAmount else l.UnActPercent*TotalAmount end) Profit from (select IsAct,ManageAreas,(LENGTH(ManageAreas)-LENGTH(REPLACE(ManageAreas,',',''))+1) AgentLevel,sum(TotalAmount) TotalAmount from AgentTradeStatSummary where TradeMonth='" + TradeMonth + "' group by IsAct,ManageAreas) tb left join AgentLevels l on tb.AgentLevel=l.Id", AppConfig.Base.SqlConnStr);
+            foreach(DataRow dr in dt.Rows)
+            {
+                ProfitList.Add(new AgentProfit()
+                {
+                    IsAct = int.Parse(dr["IsAct"].ToString()),
+                    ManageAreas = dr["ManageAreas"].ToString(),
+                    AgentLevel = int.Parse(dr["IsAct"].ToString()),
+                    TotalAmount = decimal.Parse(dr["TotalAmount"].ToString()),
+                    Percent = decimal.Parse(dr["Percent"].ToString()),
+                    Profit = decimal.Parse(dr["Profit"].ToString()),
+                });
+            }
+            foreach(AgentProfit SubProfit in ProfitList)
+            {
+                int SubLevel = SubProfit.AgentLevel + 1;
+                decimal SubProfitAmt = 0;
+                if(ProfitList.Any(m => m.ManageAreas.StartsWith(SubProfit.ManageAreas) && m.AgentLevel == SubLevel && m.IsAct == SubProfit.IsAct))
+                {
+                    SubProfitAmt = ProfitList.Where(m => m.ManageAreas.StartsWith(SubProfit.ManageAreas) && m.AgentLevel == SubLevel && m.IsAct == SubProfit.IsAct).Sum(m => m.Profit);
+                }
+                if(SubProfitAmt > 0) SubProfit.ProfitResult -= SubProfitAmt;
+            }
+            foreach(AgentProfit SubProfit in ProfitList)
+            {
+                MySystem.Models.Main1.UserAgent user = dbnew1.UserAgent.FirstOrDefault(m => m.ManageAreas == SubProfit.ManageAreas);
+                if(user != null)
+                {
+                    dbnew.AgentProfitRecord.Add(new AgentProfitRecord()
+                    {
+                        CreateDate = DateTime.Now,
+                        UpdateDate = DateTime.Now,
+                        TradeMonth = TradeMonth,
+                        Remark = "来客吧区域代理奖励\n" + SubProfit.ManageAreas,
+                        TradeProfit = SubProfit.ProfitResult,
+                        CreditTradeAmt = SubProfit.TotalAmount,
+                        UserId = user.UserId,
+                    });
+                    dbnew.Dispose();
+                }
+            }
+            dbnew1.Dispose();
+            dbnew.Dispose();
+        }
+    }
+}

+ 40 - 14
Util/HaoDa/ProfitHelper.cs

@@ -112,9 +112,11 @@ namespace MySystem
                                     order.ReturnFlag = 1;
                                     db.SaveChanges();
                                     DiviMoney = DiviMoney / DiviPersons;
-                                    DiviMoney = Math.Round(DiviMoney, 2);
+                                    DiviMoney = PublicFunction.NumberFormat(DiviMoney);
                                     List<int> deletes = new List<int>();
                                     long CurDiviPersons = DiviPersons;
+                                    int DiviTimes = 0;
+                                    int CheckTime = 0;
                                     long QueueCount = RedisDbconn.Instance.Count("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId);
                                     long CurQueueCount = QueueCount;
                                     if (CurDiviPersons >= CurQueueCount)
@@ -151,30 +153,51 @@ namespace MySystem
                                                 function.WriteLog("GetMoney:" + GetMoney, "返现逻辑日志");
                                                 if (GetMoney > minProfit)
                                                 {
-                                                    suborder.CurDivi += GetMoney;
                                                     MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == suborder.MerchantId) ?? new MerchantAddInfo();
                                                     
                                                     //聚合支付退款
                                                     bool BackStatus = false;
 
                                                     //拆单算法
-                                                    int CheckTime = SplitOrder(suborder.PayMoney,subset.MinPayMoney);
-                                                    if(CheckTime > 0)
+                                                    string MerchantList = function.CheckNull(RedisDbconn.Instance.Get<string>("SplitOrderMerchants"));
+                                                    string SplitOrderStatus = function.CheckNull(RedisDbconn.Instance.Get<string>("SplitOrderStatus"));
+                                                    if(MerchantList.Contains("," + suborder.MerchantId + ",") || SplitOrderStatus == "1")
                                                     {
-                                                        GetMoney = GetMoney * CheckTime;
-                                                        db.SaveChanges();
-                                                        CurDiviPersons -= CheckTime - 1;
+                                                        CheckTime = SplitOrder(suborder.PayMoney,subset.MinPayMoney);
+                                                        function.WriteLog("CheckTime:" + CheckTime, "返现逻辑日志");
+                                                        if(CheckTime > 0)
+                                                        {
+                                                            if(set.DiviPersons - DiviTimes < CheckTime)
+                                                            {
+                                                                CheckTime = set.DiviPersons - DiviTimes;
+                                                            }
+                                                            function.WriteLog("CheckTime:" + CheckTime, "返现逻辑日志");
+                                                            GetMoney = GetMoney * CheckTime;
+                                                            db.SaveChanges();
+                                                            function.WriteLog("CurDiviPersons1:" + CurDiviPersons, "返现逻辑日志");
+                                                            if(RedisDbconn.Instance.Count("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId) >= set.DiviPersons)
+                                                            {
+                                                                CurDiviPersons -= CheckTime - 1;
+                                                            }
+                                                            function.WriteLog("CurDiviPersons2:" + CurDiviPersons, "返现逻辑日志");
+                                                            decimal CheckMoney = suborder.MaxDivi - suborder.CurDivi;
+                                                            if (GetMoney >= CheckMoney)
+                                                            {
+                                                                GetMoney = CheckMoney;
+                                                            }
+                                                        }
                                                     }
+                                                    suborder.CurDivi += GetMoney;
 
                                                     decimal RefundAmount = GetMoney * 100;
-                                                    RefundAmount = Math.Round(RefundAmount, 2);
-                                                    if(!orderids.Contains(suborder.Id))
+                                                    RefundAmount = PublicFunction.NumberFormat(RefundAmount, 0);
+                                                    if(!orderids.Contains(suborder.Id) && DiviTimes < set.DiviPersons)
                                                     {
                                                         function.WriteLog("请求退款接口", "返现逻辑日志");
                                                         string RefundNo = "HDTK" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
-                                                        // var info = HaoDaHelper.Instance.AggregatedPayRefund(merchantAdd.OutMchtNo, merchantAdd.StoreNo, RefundNo, suborder.OrderNo, RefundAmount.ToString("f0"));
-                                                        // if(info.Contains("\"resultCode\":\"1\"") && info.Contains("\"tradeStatus\":\"2\""))
-                                                        // {
+                                                        var info = HaoDaHelper.Instance.AggregatedPayRefund(merchantAdd.OutMchtNo, merchantAdd.StoreNo, RefundNo, suborder.OrderNo, RefundAmount.ToString("f0"));
+                                                        if(info.Contains("\"resultCode\":\"1\"") && info.Contains("\"tradeStatus\":\"2\""))
+                                                        {
                                                             db.ConsumerProfit.Add(new ConsumerProfit()
                                                             {
                                                                 CreateDate = DateTime.Now,
@@ -190,9 +213,10 @@ namespace MySystem
                                                             });
                                                             db.SaveChanges();
                                                             BackStatus = true;
-                                                        // }
-                                                        // function.WriteLog("接口返回:" + info, "返现逻辑日志");
+                                                        }
+                                                        function.WriteLog("接口返回:" + info, "返现逻辑日志");
                                                         orderids.Add(suborder.Id);
+                                                        DiviTimes += CheckTime;
                                                     }
 
                                                     if(BackStatus)
@@ -218,6 +242,7 @@ namespace MySystem
                                                                 db.SaveChanges();
                                                                 RedisDbconn.Instance.AddList("ConsumerOrdersSetDiviHd", "{\"OrderId\":\"" + suborder.Id + "\",\"DiviAmt\":\"" + suborder.MaxDivi + "\"}");
                                                             }
+                                                            function.WriteLog("删除队列数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(suborder), "返现逻辑日志");
                                                             RedisDbconn.Instance.DelFromList("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId, suborder);
                                                         }
                                                     }
@@ -236,6 +261,7 @@ namespace MySystem
                                                     db.SaveChanges();
                                                     RedisDbconn.Instance.AddList("ConsumerOrdersSetDiviHd", "{\"OrderId\":\"" + suborder.Id + "\",\"DiviAmt\":\"" + suborder.MaxDivi + "\"}");
                                                 }
+                                                function.WriteLog("删除队列数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(suborder), "返现逻辑日志");
                                                 RedisDbconn.Instance.DelFromList("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId, suborder);
                                                 CurDiviPersons += 1;
                                                 function.WriteLog("出局:CurDiviPersons:" + CurDiviPersons, "返现逻辑日志");