ソースを参照

活动必须限制最小活动金额

lcl 1 年間 前
コミット
dc735d48e6
2 ファイル変更68 行追加62 行削除
  1. 67 61
      AppStart/Helper/WeChatPayBackService.cs
  2. 1 1
      Controllers/HomeController.cs

+ 67 - 61
AppStart/Helper/WeChatPayBackService.cs

@@ -20,12 +20,12 @@ namespace MySystem
 
         public void Start()
         {
-            Thread th = new Thread(dosomething);
+            Thread th = new Thread(Listen);
             th.IsBackground = true;
             th.Start();
         }
 
-        public void dosomething()
+        public void Listen()
         {
             bool op = true;
             while (op)
@@ -35,65 +35,7 @@ namespace MySystem
                 {
                     try
                     {
-                        JsonData jsonObj = JsonMapper.ToObject(content);
-                        if (jsonObj.Count > 0)
-                        {
-                            if (jsonObj["event_type"].ToString() == "TRANSACTION.SUCCESS")
-                            {
-                                JsonData resource = jsonObj["resource"];
-                                //开始解密
-                                string WxPayResourceDecryptModel = AesGcmDecrypt(resource["associated_data"].ToString(), resource["nonce"].ToString(), resource["ciphertext"].ToString());
-                                // {\"sp_mchid\":\"1611167423\",\"sub_mchid\":\"1622024882\",\"sp_appid\":\"wxe2c051b3e46c0f6f\",\"out_trade_no\":\"2022022621562926396898863\",\"transaction_id\":\"4200001412202202267619496496\",\"trade_type\":\"JSAPI\",\"trade_state\":\"SUCCESS\",\"trade_state_desc\":\"支付成功\",\"bank_type\":\"OTHERS\",\"attach\":\"\",\"success_time\":\"2022-02-26T21:56:42+08:00\",\"payer\":{\"sp_openid\":\"omawy5W6jb0pgPfuKUVs6K3bEhzk\",\"sub_openid\":\"\"},\"amount\":{\"total\":1,\"payer_total\":1,\"currency\":\"CNY\",\"payer_currency\":\"CNY\"}}
-                                JsonData orderObj = JsonMapper.ToObject(WxPayResourceDecryptModel);
-                                string OrderNo = orderObj["out_trade_no"].ToString();
-                                string TradeNo = orderObj["transaction_id"].ToString();
-                                WebCMSEntities db = new WebCMSEntities();
-                                ConsumerOrderForNo forNo = db.ConsumerOrderForNo.FirstOrDefault(m => m.OrderNo == OrderNo);
-                                if (forNo != null)
-                                {
-                                    ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == forNo.OrderIds && m.Status == 0);
-                                    if (order != null)
-                                    {
-                                        order.Status = 1;
-                                        order.UpdateDate = DateTime.Now;
-                                        order.PayMoney = order.PayMoney;
-                                        order.MaxDivi = order.MaxDivi;
-                                        order.SeoTitle = TradeNo;
-                                        MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
-                                        order.UserId = merchant.UserId;
-                                        db.SaveChanges();
-                                        if(order.IsAct == 1)
-                                        {
-                                            MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
-                                            //添加分账接收方
-                                            if(merchant.Version == 0)
-                                            {
-                                                WeChatFunction.Instance.AddReceive(merchantAdd.SubMchid, "MERCHANT_ID", WeChatFunction.Instance.MchId, "四川客小爽科技有限公司", "PARTNER");
-                                                merchantAdd.Version = 1;
-                                                db.SaveChanges();
-                                            }
-                                            //发起分账
-                                            decimal fee = order.PayMoney * 0.62M; //单位:分
-                                            if(fee >= 1)
-                                            {
-                                                List<ReceiverList> Receivers = new List<ReceiverList>();
-                                                Receivers.Add(new ReceiverList()
-                                                {
-                                                    type = "MERCHANT_ID",  //分账接收方类型
-                                                    account = WeChatFunction.Instance.MchId,  //分账接收方账号
-                                                    amount = int.Parse(fee.ToString("f2")),  //分账金额
-                                                    description = "服务费",  //分账描述
-                                                });
-                                                WeChatFunction.Instance.ProfitShare(merchantAdd.SubMchid, TradeNo, OrderNo, Receivers);
-                                            }
-                                            RedisDbconn.Instance.AddList("ConsumerOrders:Divi:List", order.Id.ToString());
-                                            RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:" + order.MerchantId, order);
-                                        }
-                                    }
-                                }
-                                db.Dispose();
-                            }
-                        }
+                        dosomething(content);
                     }
                     catch (Exception ex)
                     {
@@ -107,6 +49,70 @@ namespace MySystem
             }
         }
 
+        public void dosomething(string content)
+        {
+            JsonData jsonObj = JsonMapper.ToObject(content);
+            if (jsonObj.Count > 0)
+            {
+                if (jsonObj["event_type"].ToString() == "TRANSACTION.SUCCESS")
+                {
+                    JsonData resource = jsonObj["resource"];
+                    //开始解密
+                    string WxPayResourceDecryptModel = AesGcmDecrypt(resource["associated_data"].ToString(), resource["nonce"].ToString(), resource["ciphertext"].ToString());
+                    // {\"sp_mchid\":\"1611167423\",\"sub_mchid\":\"1622024882\",\"sp_appid\":\"wxe2c051b3e46c0f6f\",\"out_trade_no\":\"2022022621562926396898863\",\"transaction_id\":\"4200001412202202267619496496\",\"trade_type\":\"JSAPI\",\"trade_state\":\"SUCCESS\",\"trade_state_desc\":\"支付成功\",\"bank_type\":\"OTHERS\",\"attach\":\"\",\"success_time\":\"2022-02-26T21:56:42+08:00\",\"payer\":{\"sp_openid\":\"omawy5W6jb0pgPfuKUVs6K3bEhzk\",\"sub_openid\":\"\"},\"amount\":{\"total\":1,\"payer_total\":1,\"currency\":\"CNY\",\"payer_currency\":\"CNY\"}}
+                    JsonData orderObj = JsonMapper.ToObject(WxPayResourceDecryptModel);
+                    string OrderNo = orderObj["out_trade_no"].ToString();
+                    string TradeNo = orderObj["transaction_id"].ToString();
+                    WebCMSEntities db = new WebCMSEntities();
+                    ConsumerOrderForNo forNo = db.ConsumerOrderForNo.FirstOrDefault(m => m.OrderNo == OrderNo);
+                    if (forNo != null)
+                    {
+                        ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == forNo.OrderIds && m.Status == 0);
+                        if (order != null)
+                        {
+                            order.Status = 1;
+                            order.UpdateDate = DateTime.Now;
+                            order.PayMoney = order.PayMoney;
+                            order.MaxDivi = order.MaxDivi;
+                            order.SeoTitle = TradeNo;
+                            MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
+                            order.UserId = merchant.UserId;
+                            db.SaveChanges();
+                            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(merchant.Version == 0)
+                                {
+                                    WeChatFunction.Instance.AddReceive(merchantAdd.SubMchid, "MERCHANT_ID", WeChatFunction.Instance.MchId, "四川客小爽科技有限公司", "PARTNER");
+                                    merchantAdd.Version = 1;
+                                    db.SaveChanges();
+                                }
+                                //发起分账
+                                decimal fee = order.PayMoney; //单位:分
+                                if(fee >= 1)
+                                {
+                                    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);
+                                }
+                                RedisDbconn.Instance.AddList("ConsumerOrders:Divi:List", order.Id.ToString());
+                                RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:" + order.MerchantId, order);
+                            }
+                        }
+                    }
+                    db.Dispose();
+                }
+            }
+        }
+
         private string ALGORITHM = "AES/GCM/NoPadding";
         private int TAG_LENGTH_BIT = 128;
         private int NONCE_LENGTH_BYTE = 12;

+ 1 - 1
Controllers/HomeController.cs

@@ -56,7 +56,7 @@ namespace MySystem.Controllers
             // string txt = WeChatFunction.Instance.AesGcmDecrypt("transaction", "ACgp5LfxJ2Pl", content);
             // Dictionary<string, string> result = WeChatFunction.Instance.Refund("1645266943", 0.01M, 0.1M, "2023060214014405449699901", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
             // txt = Newtonsoft.Json.JsonConvert.SerializeObject(result);
-            txt = Newtonsoft.Json.JsonConvert.SerializeObject(WeChatFunction.Instance.QueryMerchant("KXS2023060213554647660112"));
+            // txt = Newtonsoft.Json.JsonConvert.SerializeObject(WeChatFunction.Instance.QueryMerchant("KXS2023060213554647660112"));
             return txt;
         }