Jelajahi Sumber

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

DuGuYang 1 tahun lalu
induk
melakukan
a54d0d5c07

+ 76 - 2
AppStart/Helper/AlipayPayBackService.cs

@@ -142,13 +142,19 @@ namespace MySystem
                                 {
                                     string TradeNo = order.SeoTitle;
                                     string OrderNo = order.OrderNo;
+                                    decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent - 0.01M);
+                                    hdfee = decimal.Parse(hdfee.ToString("f2"));
+                                    decimal servicefee = 0.01M * order.PayMoney - hdfee;
+                                    servicefee = decimal.Parse(servicefee.ToString("f2"));
                                     List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
                                     Parameters.Add(new RoyaltyParameters()
                                     {
                                         Account = AlipayFunction.Instance.Pid,
-                                        Amount = fee.ToString("f2"),
+                                        Amount = servicefee.ToString("f2"),
                                     });
-                                    AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
+                                    string ProfitShareResult = AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
+                                    order.DivideLog = "请求分账日志:" + ProfitShareResult;
+                                    db.SaveChanges();
 
                                     //开始监听分账状态
                                     Dictionary<string, object> req = new Dictionary<string, object>();
@@ -175,5 +181,73 @@ namespace MySystem
                 Thread.Sleep(2000);
             }
         }
+
+
+
+        //触发分账接口
+        public void StartDivi()
+        {
+            Thread th = new Thread(ListenDivi);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void ListenDivi()
+        {
+            bool op = true;
+            while (op)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("AddAlipayDiviQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        int id = int.Parse(function.CheckInt(content));
+                        WebCMSEntities db = new WebCMSEntities();
+                        ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == id);
+                        if (order != null)
+                        {
+                            MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
+                            MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
+                            if (order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
+                            {
+                                //发起分账
+                                decimal fee = order.PayMoney * 0.01M;
+                                if(fee >= 0.01M)
+                                {
+                                    string TradeNo = order.SeoTitle;
+                                    string OrderNo = order.OrderNo;
+                                    List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
+                                    Parameters.Add(new RoyaltyParameters()
+                                    {
+                                        Account = AlipayFunction.Instance.Pid,
+                                        Amount = fee.ToString("f2"),
+                                    });
+                                    string ProfitShareResult = AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
+                                    order.DivideLog = "请求分账日志:" + ProfitShareResult;
+                                    db.SaveChanges();
+
+                                    //开始监听分账状态
+                                    Dictionary<string, object> req = new Dictionary<string, object>();
+                                    req.Add("TradeNo", TradeNo); //支付宝订单号
+                                    req.Add("OrderNo", OrderNo); //商户订单号
+                                    req.Add("AuthToken", merchantAdd.AlipayAuthToken);
+                                    RedisDbconn.Instance.AddList("AlipayShareQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
+                                }
+                            }
+                        }
+                        db.Dispose();
+                    }
+                    catch (Exception ex)
+                    {
+                        LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "补微信分账异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(2000);
+                }
+            }
+        }
     }
 }

+ 2 - 0
AppStart/Helper/AlipayShareService.cs

@@ -57,6 +57,8 @@ namespace MySystem
                         ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.OrderNo == OrderNo && m.Status == 2);
                         if (order != null)
                         {
+                            order.DivideLog = "分账审核结果:" + result;
+                            db.SaveChanges();
                             RedisDbconn.Instance.AddList("ConsumerOrders:Divi:" + order.PayMode + ":List", order.Id.ToString());
                             // RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:" + order.PayMode + ":" + order.MerchantId, order);
                         }

+ 1 - 0
AppStart/Helper/MerchantConfirmService.cs

@@ -170,6 +170,7 @@ namespace MySystem
                             if (json["alipay_open_agent_confirm_response"]["code"].ToString() == "10000")
                             {
                                 // AddInfo.AlipayAuthToken = json["alipay_open_agent_confirm_response"]["app_auth_token"].ToString();
+                                AddInfo.SeoTitle = batch_no;
                                 db.SaveChanges();
                                 RedisDbconn.Instance.AddList("AlipaySignQueue", new MerchantSign()
                                 {

+ 11 - 11
AppStart/Helper/MerchantStandardService.cs

@@ -46,15 +46,15 @@ namespace MySystem
             DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
             string month = DateTime.Now.ToString("yyyyMM");
             function.WriteLog(DateTime.Now.ToString() + "-start", "达标奖励日志");
-            var orders = db.MerchantDepositOrder.Where(m => m.Status > 0 && m.Version == 0 && m.UpdateDate >= start && m.UpdateDate < end);
+            var orders = db.MerchantDepositOrder.Where(m => m.Status > 0 && m.Version == 0 && m.UpdateDate >= start && m.UpdateDate < end).ToList();
             foreach(var order in orders)
             {
                 function.WriteLog("MerchantId:" + order.MerchantId, "达标奖励日志");
                 decimal TradeMoney = 0;
-                bool has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.TradeMonth == month);
+                bool has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month);
                 if(has)
                 {
-                    TradeMoney = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.TradeMonth == month).Sum(m => m.TradeAmount);
+                    TradeMoney = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month).Sum(m => m.TradeAmount);
                 }
                 function.WriteLog("TradeMoney:" + TradeMoney, "达标奖励日志");
                 if(TradeMoney >= 10000)
@@ -103,28 +103,28 @@ namespace MySystem
         { 
             WebCMSEntities db = new WebCMSEntities();
             DateTime start = DateTime.Parse(DateTime.Now.AddMonths(-3).ToString("yyyy-MM") + "-01 00:00:00");
-            DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
+            DateTime end = DateTime.Parse(DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01 00:00:00");
             string month = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
             string month2 = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
             string month3 = DateTime.Now.ToString("yyyyMM");
-            var orders = db.MerchantDepositOrder.Where(m => m.Status > 0 && m.Version == 1 && m.UpdateDate >= start && m.UpdateDate < end);
+            var orders = db.MerchantDepositOrder.Where(m => m.Status > 0 && m.Version == 1 && m.UpdateDate >= start && m.UpdateDate < end).ToList();
             foreach(var order in orders)
             {
                 decimal TradeMoney = 0, TradeMoney2 = 0, TradeMoney3 = 0;
-                bool has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.TradeMonth == month);
+                bool has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month);
                 if(has)
                 {
-                    TradeMoney = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.TradeMonth == month).Sum(m => m.TradeAmount);
+                    TradeMoney = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month).Sum(m => m.TradeAmount);
                 }
-                has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.TradeMonth == month2);
+                has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month2);
                 if(has)
                 {
-                    TradeMoney2 = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.TradeMonth == month2).Sum(m => m.TradeAmount);
+                    TradeMoney2 = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month2).Sum(m => m.TradeAmount);
                 }
-                has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.TradeMonth == month3);
+                has = db.MerchantAmountSummay.Any(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month3);
                 if(has)
                 {
-                    TradeMoney3 = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.TradeMonth == month3).Sum(m => m.TradeAmount);
+                    TradeMoney3 = db.MerchantAmountSummay.Where(m => m.MerchantId == order.MerchantId && m.IsAct == 1 && m.TradeMonth == month3).Sum(m => m.TradeAmount);
                 }
                 if(TradeMoney >= 10000 && TradeMoney2 >= 10000 && TradeMoney3 >= 10000)
                 {

+ 2 - 0
AppStart/Helper/ProfitShareService.cs

@@ -57,6 +57,8 @@ namespace MySystem
                         ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.OrderNo == OrderNo && m.Status == 2);
                         if (order != null)
                         {
+                            order.DivideLog = "分账审核结果:" + result;
+                            db.SaveChanges();
                             RedisDbconn.Instance.AddList("ConsumerOrders:Divi:" + order.PayMode + ":List", order.Id.ToString());
                             // RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:" + order.PayMode + ":" + order.MerchantId, order);
                         }

+ 81 - 1
AppStart/Helper/WeChatPayBackService.cs

@@ -180,12 +180,17 @@ namespace MySystem
                                 {
                                     string TradeNo = order.SeoTitle;
                                     string OrderNo = order.OrderNo;
+                                    decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent - 0.01M);
+                                    hdfee = decimal.Parse(hdfee.ToString("f2"));
+                                    decimal servicefee = 0.01M * order.PayMoney - hdfee;
+                                    servicefee = servicefee * 100;
+                                    int servicefeeNum = int.Parse(servicefee.ToString("f0"));
                                     List<ReceiverList> Receivers = new List<ReceiverList>();
                                     Receivers.Add(new ReceiverList()
                                     {
                                         type = "MERCHANT_ID",  //分账接收方类型
                                         account = WeChatFunction.Instance.MchId,  //分账接收方账号
-                                        amount = int.Parse(fee.ToString("f0")),  //分账金额
+                                        amount = servicefeeNum,  //分账金额
                                         description = "服务费",  //分账描述
                                     });
                                     LogHelper.Instance.WriteLog("TradeNo:" + TradeNo, "微信分账队列监听");
@@ -193,6 +198,8 @@ namespace MySystem
                                     LogHelper.Instance.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(Receivers), "微信分账队列监听");
                                     string ProfitShareResult = WeChatFunction.Instance.ProfitShare(merchantAdd.SubMchid, TradeNo, OrderNo, Receivers);
                                     LogHelper.Instance.WriteLog("分账结果:" + ProfitShareResult, "微信分账队列监听");
+                                    order.DivideLog = "请求分账日志:" + ProfitShareResult;
+                                    db.SaveChanges();
 
                                     //开始监听分账状态
                                     Dictionary<string, object> req = new Dictionary<string, object>();
@@ -220,5 +227,78 @@ namespace MySystem
                 Thread.Sleep(2000);
             }
         }
+
+
+        //触发分账接口
+        public void StartDivi()
+        {
+            Thread th = new Thread(ListenDivi);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void ListenDivi()
+        {
+            bool op = true;
+            while (op)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("AddWeChatDiviQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        int id = int.Parse(function.CheckInt(content));
+                        WebCMSEntities db = new WebCMSEntities();
+                        ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == id);
+                        if (order != null)
+                        {
+                            MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
+                            MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
+                            if (order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
+                            {
+                                //发起分账
+                                decimal fee = order.PayMoney; //单位:分
+                                if(fee >= 1)
+                                {
+                                    string TradeNo = order.SeoTitle;
+                                    string OrderNo = order.OrderNo;
+                                    List<ReceiverList> Receivers = new List<ReceiverList>();
+                                    Receivers.Add(new ReceiverList()
+                                    {
+                                        type = "MERCHANT_ID",  //分账接收方类型
+                                        account = WeChatFunction.Instance.MchId,  //分账接收方账号
+                                        amount = int.Parse(fee.ToString("f0")),  //分账金额
+                                        description = "服务费",  //分账描述
+                                    });
+                                    LogHelper.Instance.WriteLog("TradeNo:" + TradeNo, "微信分账队列监听");
+                                    LogHelper.Instance.WriteLog("OrderNo:" + OrderNo, "微信分账队列监听");
+                                    LogHelper.Instance.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(Receivers), "微信分账队列监听");
+                                    string ProfitShareResult = WeChatFunction.Instance.ProfitShare(merchantAdd.SubMchid, TradeNo, OrderNo, Receivers);
+                                    LogHelper.Instance.WriteLog("分账结果:" + ProfitShareResult, "微信分账队列监听");
+                                    order.DivideLog = "请求分账日志:" + ProfitShareResult;
+                                    db.SaveChanges();
+
+                                    //开始监听分账状态
+                                    Dictionary<string, object> req = new Dictionary<string, object>();
+                                    req.Add("SubMchid", merchantAdd.SubMchid); //子商户号
+                                    req.Add("TradeNo", TradeNo); //微信订单号
+                                    req.Add("OrderNo", OrderNo); //商户订单号
+                                    RedisDbconn.Instance.AddList("ProfitShareQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
+                                }
+                            }
+                        }
+                        db.Dispose();
+                    }
+                    catch (Exception ex)
+                    {
+                        LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "补微信分账异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(2000);
+                }
+            }
+        }
     }
 }

+ 3 - 0
Models/ConsumerOrders.cs

@@ -29,5 +29,8 @@ namespace MySystem.Models
         public ulong IsAct { get; set; }
         public int UserId { get; set; }
         public decimal MerchantActualAmount { get; set; }
+        public string DivideLog { get; set; }
+        public int DivideFlag { get; set; }
+        public DateTime? DivideDate { get; set; }
     }
 }

+ 14 - 0
Models/WebCMSEntities.cs

@@ -2257,6 +2257,20 @@ namespace MySystem.Models
 
                 entity.Property(e => e.CurDivi).HasColumnType("decimal(18,2)");
 
+                entity.Property(e => e.DivideDate)
+                    .HasColumnType("datetime")
+                    .HasComment("提交分账时间");
+
+                entity.Property(e => e.DivideFlag)
+                    .HasColumnType("int(11)")
+                    .HasComment("分账标记");
+
+                entity.Property(e => e.DivideLog)
+                    .HasColumnType("mediumtext")
+                    .HasComment("分账结果日志")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
                 entity.Property(e => e.IsAct)
                     .HasColumnType("bit(1)")
                     .HasDefaultValueSql("b'0'");

+ 8 - 2
Startup.cs

@@ -172,6 +172,9 @@ namespace MySystem
             //必须打开的
             if(Library.ConfigurationManager.EnvironmentFlag == 1)
             {
+                MerchantStandardService.Instance.Start();
+                // MerchantStandardService.Instance.StartThree();
+                // MerchantStandardService.Instance.StartActive();
             }
             if(Library.ConfigurationManager.EnvironmentFlag == 2)
             {
@@ -187,6 +190,8 @@ namespace MySystem
                 ProfitHelper.Instance.StartListenWxTrade(); //微信返现队列
                 ProfitShareService.Instance.Start(); //分账状态监控队列,分账完成则提交返现(微信)
                 AlipayShareService.Instance.Start(); //分账状态监控队列,分账完成则提交返现(支付宝)
+                WeChatPayBackService.Instance.StartDivi(); //补分账
+                AlipayPayBackService.Instance.StartDivi(); //补分账
                 ProfitHelper.Instance.StartListenProfit(); //每月分润
 
                 AlipayPayBackFeeService.Instance.Start();
@@ -195,8 +200,9 @@ namespace MySystem
                 ActiveRewardService.Instance.StartLeaderReward();
                 ActiveRewardService.Instance.StartOperateReward();
 
-                // MerchantStandardService.Instance.Start(); //商户缴纳服务费次月活动交易额大于等于1W,奖励进件创客50元
-                // MerchantStandardService.Instance.StartThree(); //商户缴纳服务费次月起连续不间断三个月,每月活动交易额大于1W,奖励进件创客100元
+                MerchantStandardService.Instance.Start(); //商户缴纳服务费次月活动交易额大于等于1W,奖励进件创客50元
+                MerchantStandardService.Instance.StartThree(); //商户缴纳服务费次月起连续不间断三个月,每月活动交易额大于1W,奖励进件创客100元
+                MerchantStandardService.Instance.StartActive();
             }
             // HaoDaExtHelper.Instance.StartWeChat();
             // HaoDaExtHelper.Instance.StartAlipay();

+ 1 - 1
Views/Home/Index.cshtml

@@ -1 +1 @@
-<h2>客小爽MAIN</h2>
+<h2>来客吧main</h2>

+ 2 - 2
appsettings.json

@@ -20,8 +20,8 @@
     "SqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer;charset=utf8;",
     "SqlConnStr2": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer2;charset=utf8;",
     "SpSqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateSpServer;password=T2ZzxUq2fix0cTqa;database=QrCodePlateSpServer;charset=utf8;",
-    "KxsSqlConnStr": "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;",
-    "KxsStatSqlConnStr": "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsStatServer;charset=utf8;",
+    "KxsSqlConnStr": "server=rm-2vcs4j67tla603c9d5o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;",
+    "KxsStatSqlConnStr": "server=rm-2vcs4j67tla603c9d5o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsStatServer;charset=utf8;",
     "RedisConnStr": "8.137.99.48:6379,password=kxsmp@2023,DefaultDatabase=0,poolsize=500,preheat=50,asyncPipeline=true",
     "IOSAppVersion": "1.0.0",
     "AndroidAppVersion": "1.0.0",