瀏覽代碼

订单支付成功,金额扩大1万倍,方便测试

lcl 1 年之前
父節點
當前提交
a997ef3ce5
共有 2 個文件被更改,包括 45 次插入57 次删除
  1. 42 54
      AppStart/Helper/ConsumerOrdersReturnDoService.cs
  2. 3 3
      AppStart/Helper/WeChatPayBackService.cs

+ 42 - 54
AppStart/Helper/ConsumerOrdersReturnDoService.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using Library;
 using LitJson;
 using System.Linq;
+using System.Threading;
 using MySystem.PxcModels;
 
 namespace MySystem
@@ -13,31 +14,11 @@ namespace MySystem
         private ConsumerOrdersReturnDoService()
         { }
 
-        public void Start(JobMqMsg jobInfo)
+        public void Start()
         {
-            string content = "";
-            try
-            {
-                DoRefund();
-                // string Msg = "success";
-                // jobInfo.Status = Msg == "success" ? 1 : 0;
-                // jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
-                // RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
-            }
-            catch (Exception ex)
-            {
-                if (!string.IsNullOrEmpty(content))
-                {
-                    Dictionary<string, string> data = new Dictionary<string, string>();
-                    data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
-                    data.Add("ErrMsg", ex.ToString());
-                    function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(data), "public_err");
-                }
-                else
-                {
-                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
-                }
-            }
+            Thread th = new Thread(DoRefund);
+            th.IsBackground = true;
+            th.Start();
         }
 
         private void DoRefund()
@@ -48,45 +29,52 @@ namespace MySystem
                 RefundItem item = RedisDbconn.Instance.RPop<RefundItem>("ConsumerOrdersStat");
                 if (item != null)
                 {
-                    bool success = false;
-                    WebCMSEntities db = new WebCMSEntities();
-                    if (item.PayMode == 1)
-                    {
-                        string resultString = new AlipayFunction().Refund(item.TradeNo, item.RefundMoney.ToString("f2"), "202202BB4fc8c2c03c914f2f87b6c678a77d7C03");
-                        JsonData jsonObj = JsonMapper.ToObject(resultString);
-                        if (jsonObj["alipay_trade_refund_response"]["code"].ToString() == "10000")
-                        { 
-                            success = true;
-                        }
-                    }
-                    else if (item.PayMode == 2)
+                    try
                     {
-                        string AppId = "wxe2c051b3e46c0f6f";
-                        string MchId = "1611167423";
-                        MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new MerchantAddInfo();
-                        MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new MerchantInfo();
-                        string SubMchId = merchantAdd.SubMchid;
-                        string Description = merchant.Name;
-                        string RefundNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
-                        Dictionary<string, string> dic = new WeChatFunction().Refund(AppId, MchId, SubMchId, item.RefundMoney, item.TotalMoney, item.TradeNo, RefundNo);
-                        if (dic.ContainsKey("status"))
+                        bool success = false;
+                        WebCMSEntities db = new WebCMSEntities();
+                        if (item.PayMode == 1)
                         {
-                            if (dic["status"] == "SUCCESS")
+                            string resultString = new AlipayFunction().Refund(item.TradeNo, item.RefundMoney.ToString("f2"), "202202BB4fc8c2c03c914f2f87b6c678a77d7C03");
+                            JsonData jsonObj = JsonMapper.ToObject(resultString);
+                            if (jsonObj["alipay_trade_refund_response"]["code"].ToString() == "10000")
                             {
                                 success = true;
                             }
                         }
-                    }
-                    if (success)
-                    {
-                        ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == item.ProfitId);
-                        if (order != null)
+                        else if (item.PayMode == 2)
                         {
-                            order.Status = 1;
-                            db.SaveChanges();
+                            string AppId = "wxe2c051b3e46c0f6f";
+                            string MchId = "1611167423";
+                            MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new MerchantAddInfo();
+                            MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new MerchantInfo();
+                            string SubMchId = merchantAdd.SubMchid;
+                            string Description = merchant.Name;
+                            string RefundNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
+                            Dictionary<string, string> dic = new WeChatFunction().Refund(AppId, MchId, SubMchId, item.RefundMoney, item.TotalMoney, item.TradeNo, RefundNo);
+                            if (dic.ContainsKey("status"))
+                            {
+                                if (dic["status"] == "SUCCESS")
+                                {
+                                    success = true;
+                                }
+                            }
                         }
+                        if (success)
+                        {
+                            ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == item.ProfitId);
+                            if (order != null)
+                            {
+                                order.Status = 2;
+                                db.SaveChanges();
+                            }
+                        }
+                        db.Dispose();
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "退款返现队列异常");
                     }
-                    db.Dispose();
                 }
                 else
                 {

+ 3 - 3
AppStart/Helper/WeChatPayBackService.cs

@@ -55,8 +55,8 @@ namespace MySystem
                                     {
                                         order.Status = 1;
                                         order.UpdateDate = DateTime.Now;
-                                        order.PayMoney = order.PayMoney;
-                                        order.MaxDivi = order.MaxDivi;
+                                        order.PayMoney = order.PayMoney * 10000;
+                                        order.MaxDivi = order.MaxDivi * 10000;
                                         db.SaveChanges();
                                         RedisDbconn.Instance.AddList("ConsumerOrdersStat", order.Id);
                                         RedisDbconn.Instance.AddList("ConsumerOrders:Divi:List", order.Id.ToString());
@@ -75,7 +75,7 @@ namespace MySystem
                 }
                 else
                 {
-                    op = false;
+                    Thread.Sleep(2000);
                 }
             }
         }