Selaa lähdekoodia

调整进件签约队列逻辑

lcl 1 vuosi sitten
vanhempi
commit
c3274083d8

+ 50 - 0
AppStart/Helper/CheckWeChatSignService.cs

@@ -75,6 +75,56 @@ namespace MySystem
                         }
                         db.SaveChanges();
                     }
+                    else
+                    {
+                        merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 1);
+                        if (merchantadd != null)
+                        {
+                            merchantadd.SubMchid = dic["sub_mchid"].ToString();
+                            string SignUrlList = function.CheckNull(merchantadd.SeoKeyword);
+                            if (string.IsNullOrEmpty(SignUrlList))
+                            {
+                                SignUrlList = "WeChat:" + sign_url + ";";
+                            }
+                            else
+                            {
+                                SignUrlList += "WeChat:" + sign_url+ ";";
+                            }
+                            merchantadd.SeoKeyword = SignUrlList;
+                            PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                            if (merchantadd.Status > 0 && merchantadd.QueryCount > 0)
+                            {
+                                merchant.Status = 1;
+                            }
+                            db.SaveChanges();
+                        }
+                    }
+                    return "wait";
+                }
+                else if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_TO_BE_CONFIRMED")
+                {
+                    string sign_url = dic["sign_url"].ToString();
+                    PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 0);
+                    if (merchantadd != null)
+                    {
+                        merchantadd.Status = 1;
+                        string SignUrlList = function.CheckNull(merchantadd.SeoKeyword);
+                        if (string.IsNullOrEmpty(SignUrlList))
+                        {
+                            SignUrlList = "WeChat:" + sign_url + ";";
+                        }
+                        else
+                        {
+                            SignUrlList += "WeChat:" + sign_url+ ";";
+                        }
+                        merchantadd.SeoKeyword = SignUrlList;
+                        PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                        if (merchantadd.Status > 0 && merchantadd.QueryCount > 0)
+                        {
+                            merchant.Status = 1;
+                        }
+                        db.SaveChanges();
+                    }
                     return "wait";
                 }
                 else if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_FINISHED")

+ 25 - 21
AppStart/Helper/Profit/ProfitHelper.cs

@@ -49,7 +49,7 @@ namespace MySystem
                 }
                 else
                 {
-                    Thread.Sleep(2000);
+                    Thread.Sleep(60000);
                 }
             }
         }
@@ -159,27 +159,31 @@ namespace MySystem
                                                     {
                                                         OtherMoney += DiffMoney;
                                                     }
-                                                    ConsumerProfit cprofit = db.ConsumerProfit.Add(new ConsumerProfit()
+                                                    bool check = db.ConsumerProfit.Any(m => m.ConsumerId == suborder.ConsumerId && m.OrderId == OrderId);
+                                                    if(!check)
                                                     {
-                                                        CreateDate = DateTime.Now,
-                                                        ConsumerId = suborder.ConsumerId,
-                                                        MerchantId = suborder.MerchantId,
-                                                        OrderId = OrderId,
-                                                        GetMoney = GetMoney,
-                                                        QueryCount = PayMode,
-                                                        SeoTitle = order.OrderNo,
-                                                        SeoKeyword = order.PayMoney.ToString(),
-                                                    }).Entity;
-                                                    db.SaveChanges();
-                                                    MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == suborder.MerchantId) ?? new MerchantAddInfo();
-                                                    Dictionary<string, string> dic = WeChatFunction.Instance.Refund(merchantAdd.SubMchid, GetMoney, suborder.PayMoney, suborder.OrderNo, DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
-                                                    if (suborder.CurDivi < suborder.MaxDivi)
-                                                    {
-                                                        RedisDbconn.Instance.AddList("ConsumerOrders:Divi:" + MerchantId, suborder);
-                                                    }
-                                                    else
-                                                    {
-                                                        OutCount += 1;
+                                                        ConsumerProfit cprofit = db.ConsumerProfit.Add(new ConsumerProfit()
+                                                        {
+                                                            CreateDate = DateTime.Now,
+                                                            ConsumerId = suborder.ConsumerId,
+                                                            MerchantId = suborder.MerchantId,
+                                                            OrderId = OrderId,
+                                                            GetMoney = GetMoney,
+                                                            QueryCount = PayMode,
+                                                            SeoTitle = order.OrderNo,
+                                                            SeoKeyword = order.PayMoney.ToString(),
+                                                        }).Entity;
+                                                        db.SaveChanges();
+                                                        MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == suborder.MerchantId) ?? new MerchantAddInfo();
+                                                        Dictionary<string, string> dic = WeChatFunction.Instance.Refund(merchantAdd.SubMchid, GetMoney, suborder.PayMoney, suborder.OrderNo, DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
+                                                        if (suborder.CurDivi < suborder.MaxDivi)
+                                                        {
+                                                            RedisDbconn.Instance.AddList("ConsumerOrders:Divi:" + MerchantId, suborder);
+                                                        }
+                                                        else
+                                                        {
+                                                            OutCount += 1;
+                                                        }
                                                     }
                                                 }
                                             }

+ 1 - 1
AppStart/Helper/WeChatPayBackService.cs

@@ -81,7 +81,7 @@ namespace MySystem
                                                 {
                                                     type = "MERCHANT_ID",  //分账接收方类型
                                                     account = WeChatFunction.Instance.MchId,  //分账接收方账号
-                                                    amount = (int)fee,  //分账金额
+                                                    amount = int.Parse(fee.ToString("f2")),  //分账金额
                                                     description = "服务费",  //分账描述
                                                 });
                                                 WeChatFunction.Instance.ProfitShare(merchantAdd.SubMchid, TradeNo, OrderNo, Receivers);

+ 21 - 2
AppStart/WeChatFunction.cs

@@ -219,11 +219,29 @@ namespace MySystem
             Dictionary<string, object> return_result = new Dictionary<string, object>();
             try
             {
-                function.WriteLog(BusinessCode, "服务商平台商户进件提交申请单API");
                 string result = postJson("https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/business_code/" + BusinessCode, "", prikey, MchId, serialNo, "GET");
-                function.WriteLog(result + "\n\n", "服务商平台查询申请单状态API");
+                
                 //{\"applyment_id\":2000002247709762,\"applyment_state\":\"APPLYMENT_STATE_FINISHED\",\"applyment_state_msg\":\"商户入驻申请已完成\",\"audit_detail\":[],\"business_code\":\"0123456789\",\"sign_url\":\"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFv7zwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyUXE1czkzb3JlUjIxZHpXbTF5Y2YAAgRjbe9hAwQAjScA\",\"sub_mchid\":\"1619775262\"}
                 JsonData jsonObj = JsonMapper.ToObject(result);
+                bool logFlag = true;
+                if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_AUDITING" || jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_TO_BE_SIGNED" || jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_TO_BE_CONFIRMED")
+                {
+                    string check = RedisDbconn.Instance.Get<string>("WeChatQueryMerchant:" + BusinessCode + ":" + jsonObj["applyment_state"].ToString());
+                    if(!string.IsNullOrEmpty(check))
+                    {
+                        logFlag = false;
+                    }
+                    else
+                    {
+                        RedisDbconn.Instance.Set("WeChatQueryMerchant:" + BusinessCode + ":" + jsonObj["applyment_state"].ToString(), result);
+                        RedisDbconn.Instance.SetExpire("WeChatQueryMerchant:" + BusinessCode + ":" + jsonObj["applyment_state"].ToString(), 7200);
+                    }
+                }
+                if(logFlag)
+                {
+                    function.WriteLog(BusinessCode, "服务商平台商户进件提交申请单API");
+                    function.WriteLog(result + "\n\n", "服务商平台查询申请单状态API");
+                }
                 return_result.Add("applyment_id", jsonObj["applyment_id"].ToString()); //微信支付申请单号
                 return_result.Add("applyment_state", jsonObj["applyment_state"].ToString()); //申请单状态
                 return_result.Add("applyment_state_msg", jsonObj["applyment_state_msg"].ToString()); //申请状态描述
@@ -267,6 +285,7 @@ namespace MySystem
             par.Add("sub_mchid", SubMchId); //子商户号
             par.Add("out_trade_no", OrderNo); //商户订单号
             par.Add("out_refund_no", RefundNo); //商户退款单号
+            par.Add("reason", "活动返现"); //退款原因
             Dictionary<string, object> amountDic = new Dictionary<string, object>();
             amountDic.Add("refund", refund); //退款金额
             amountDic.Add("total", amount); //原订单金额

+ 3 - 2
Controllers/HomeController.cs

@@ -54,8 +54,9 @@ namespace MySystem.Controllers
             //{"id":"dc4512b7-83cd-5fa5-91e9-a80fc8562e96","create_time":"2023-06-01T13:42:42+08:00","resource_type":"encrypt-resource","event_type":"TRANSACTION.SUCCESS","summary":"支付成功","resource":{"original_type":"transaction","algorithm":"AEAD_AES_256_GCM","ciphertext":"n/mRI+vnpUsIoNPM9dCsQvcbqOkhQkpoeWAPsdenYw/FvyDmg9Cc4N8yRa6nFxVYpQR7pbjxYLQcZk8bf2Us4mo6ZCUN4B/JH0NT4ja1eSyy7no6n2mJyufpf2oig9KbqabTjiFk84zIyxdg3wtttEohdYZr1w8rPSF0+7MR5LAdx73g+v5f/gbu0r3AzwErbO7fF9vOoJqNgqcc3VgpAhoH9xwed+PNCUmgGH+YjO0lvdurztJL0iXT9P6kiy+36Tcsp6wT2SdVXCzxS65wNhPI2M0S2A0WDPpBw5cswR/glLFwo9XqT5gavU19oS6w3mLNUlB1OsEMt3tqcTDCS4zk5I9uT45uMAAvF2EiJBsnGxSUuRD1qL4jZ8hdxV2MRquy8Nbxr1wj926ye98BXdR9ZaAH9G6UMk4YyTjiVMbvhOqciqfuFlwxNkXtpV8b3QAWOhsIw0E210Tss2JDNW38ITaCwfBwSyRfYjYFhoIEbpEVpUZBn2NqxxeK1iv/h2zp3BapS+Zy0iMDba9GDjJVqEHDc6in3rSB3e5/VFjdVm3dWVH3+Gry/pU9ATTJNWaJsr/z3sWzzOoa3u0SsihPIdhJ4QiDlsYAz0JGVvbcqMXyaEb9tRR2oYWy4kOOsYirnSmhuRbeow==","associated_data":"transaction","nonce":"QxHnxeB6xtrU"}}
             // string content = "3IOiuqVNgoBm+slkn6EEgZyTaaEfq8CAHlSZUZuBfgxvhGz1+MWGqQ0wb0H3Jo5s9GveNP6zlrJAcxT7jGjYKMawN3WH+0zwQXZziYX3K3fXzamdputjuGz4MU2UBnDnIihgeaGfExH85UJQVJGoqJ38QiFo8MBaFRMz9FtspT3+tcBUryRCqdHvF57sNnKvEYJeacDKI8vEQV0YiUvytRsjMKbvLLwx+m6WsaIP4y4XPBuwmiJ5wYNFkVzUWUxzlctkjGsUXQGJrAch30pjBIr39gxMeWnph5fS6Jszivplki7jhSJjOgckRVmqOYvdmf8zcIeW3i02axg1YoxjPvs4JP+NZ3cQAZMI4FQLlV2w3pJGFKY7ZBIP73F6sHLMn6FReOvzWmWaQ+WvbGw9PpRpckkV83Eu9D6TpKRcw/M9cQA8Vh+24vuA6aFhMl2kUVTIdziOQrhH5GBvURKGm+YCtokOnsU21V01UCgEWA2NDL1D0GZZFwmMy4IiR1QY7IAwoqavt7h8l/8X5qHvhucqkdaRmYlLMM2S/xOob2HIiTA3l8Nj8BYXcbhr52fv14qY4qFSgtOc6NrverxANIIdv+YhCXU49cY25L1MjCQINUbvJ78jaFaeuv8nNcqjmfADyTC8c+jI4J7W1Z4B0isnT18XYcu6rYQhvjoyoW41ATVFDZtV3Xh/y7n14foLT5qXfkG21SABCviVL79N+36koa8rQB5yJQ==";
             // 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);
+            // 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"));
             return txt;
         }