lcl 1 vuosi sitten
vanhempi
commit
4fb89bd2c8
2 muutettua tiedostoa jossa 83 lisäystä ja 47 poistoa
  1. 80 45
      Controllers/HomeController.cs
  2. 3 2
      Startup.cs

+ 80 - 45
Controllers/HomeController.cs

@@ -96,52 +96,87 @@ namespace MySystem.Controllers
             // string content = AlipayFunction.Instance.QuerySettle("2023071214274372011988068", "2023071222001457121457238496", "202307BB6d61386d17104395831e3ea6309f0X57");
             // MerchantConfirmService.Instance.StartDo(68, 2);
             // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, "202307BB6d61386d17104395831e3ea6309f0X57");
-            // WebCMSEntities db = new WebCMSEntities();
-            // List<ConsumerOrders> orders = db.ConsumerOrders.Where(m => m.MerchantId == 70 && m.PayMode == 1 && m.Status > 0).OrderBy(m => m.Id).ToList();
-            // foreach(ConsumerOrders order in orders)
-            // {
-            //     MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
-            //     MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
-            //     if(order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
-            //     {
-            //         MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
-            //         //添加分账接收方
-            //         if(merchantAdd.Sort == 0)
-            //         {
-            //             string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, merchantAdd.AlipayAuthToken);
-            //             function.WriteLog(DateTime.Now.ToString() + "\n" + content, "支付宝添加分账方");
-            //             merchantAdd.Sort = 1;
-            //             db.SaveChanges();
-            //         }
-            //         //发起分账
-            //         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"),
-            //             });
-            //             AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
 
-            //             //开始监听分账状态
-            //             // 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));
-            //         }
-            //         else
-            //         {
-            //             RedisDbconn.Instance.AddList("ConsumerOrders:Divi:1:List", order.Id.ToString());
-            //             // RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:1:" + order.MerchantId, order);
-            //         }
-            //     }
-            // }
-            // db.Dispose();
+            List<string> ordernos = new List<string>();
+            ordernos.Add("2023083019332524572956227");
+            ordernos.Add("2023083019074537864707613");
+            ordernos.Add("2023083018462355777416530");
+            ordernos.Add("2023083117294078199622992");
+            ordernos.Add("2023083019084486627044747");
+            ordernos.Add("2023083018570978806149820");
+            ordernos.Add("2023083015062525323846663");
+            WebCMSEntities db = new WebCMSEntities();
+            List<ConsumerOrders> orders = db.ConsumerOrders.Where(m => ordernos.Contains(m.OrderNo)).OrderBy(m => m.Id).ToList();
+            foreach(ConsumerOrders order in orders)
+            {
+                MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
+                MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
+                if(order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
+                {
+                    MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
+                    // //添加分账接收方
+                    // if(merchantAdd.Sort == 0)
+                    // {
+                    //     string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, merchantAdd.AlipayAuthToken);
+                    //     function.WriteLog(DateTime.Now.ToString() + "\n" + content, "支付宝添加分账方");
+                    //     merchantAdd.Sort = 1;
+                    //     db.SaveChanges();
+                    // }
+                    // //发起分账
+                    // 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"),
+                    //     });
+                    //     AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
+
+                    //     //开始监听分账状态
+                    //     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));
+                    // }
+
+                    //添加分账接收方
+                    if(merchant.Version == 0)
+                    {
+                        WeChatFunction.Instance.AddReceive(merchantAdd.SubMchid, "MERCHANT_ID", WeChatFunction.Instance.MchId, WeChatFunction.Instance.MchName, "PARTNER");
+                        merchant.Version = 1;
+                        db.SaveChanges();
+                    }
+                    //发起分账
+                    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 = "服务费",  //分账描述
+                        });
+                        WeChatFunction.Instance.ProfitShare(merchantAdd.SubMchid, TradeNo, OrderNo, Receivers);
+
+                        //开始监听分账状态
+                        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();
             return "ok";
         }
 

+ 3 - 2
Startup.cs

@@ -117,14 +117,15 @@ namespace MySystem
             {
                 app.UseDeveloperExceptionPage();
                 // app.UseExceptionHandler("/Home/Error");
-                Library.ConfigurationManager.EnvironmentFlag = 1;
+                // Library.ConfigurationManager.EnvironmentFlag = 1;
             }
             else
             {
                 app.UseExceptionHandler("/Home/Error");
                 app.UseHsts();
-                Library.ConfigurationManager.EnvironmentFlag = 2;
+                // Library.ConfigurationManager.EnvironmentFlag = 2;
             }
+                Library.ConfigurationManager.EnvironmentFlag = 2;
             Library.function.WritePage("/", "WebRootPath.txt", env.WebRootPath);
             // app.UseStatusCodePagesWithReExecute("/public/errpage/pc/{0}.html");