浏览代码

调整返现逻辑

lcl 1 年之前
父节点
当前提交
aaaf469067
共有 3 个文件被更改,包括 40 次插入19 次删除
  1. 2 2
      AppStart/Alipay/AlipayFunction.cs
  2. 24 17
      AppStart/Helper/Profit/ProfitHelper.cs
  3. 14 0
      AppStart/RedisDbconn.cs

+ 2 - 2
AppStart/Alipay/AlipayFunction.cs

@@ -360,14 +360,14 @@ namespace MySystem
 
         #region 退款
 
-        public string Refund(string TradeNo, string Amount, string Reason, string MerToken)
+        public string Refund(string TradeNo, string RefundNo, string Amount, string Reason, string MerToken)
         {
             IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
             AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
             request.BizContent = "{" +
             "\"trade_no\":\"" + TradeNo + "\"," +
             "\"refund_amount\":" + Amount + "," +
-            "\"out_request_no\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\"," +
+            "\"out_request_no\":\"" + RefundNo + "\"," +
             "\"refund_reason\":\"" + Reason + "\"" +
             // "\"refund_royalty_parameters\":[{" +
             // "\"royalty_type\":\"transfer\"," +

+ 24 - 17
AppStart/Helper/Profit/ProfitHelper.cs

@@ -244,7 +244,7 @@ namespace MySystem
                                     List<int> orderids = new List<int>();
                                     while (CurDiviPersons > 0)
                                     {
-                                        ConsumerOrders suborder = RedisDbconn.Instance.RPop<ConsumerOrders>("ConsumerOrders:Divi:" + PayMode + ":" + MerchantId);
+                                        ConsumerOrders suborder = RedisDbconn.Instance.RPopLPush<ConsumerOrders>("ConsumerOrders:Divi:" + PayMode + ":" + MerchantId, "ConsumerOrders:Divi:" + PayMode + ":" + MerchantId);
                                         if (suborder != null)
                                         {
                                             MerchantParamSet subset = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
@@ -270,29 +270,35 @@ namespace MySystem
                                                     {
                                                         OtherMoney += DiffMoney;
                                                     }
-                                                    ConsumerProfit cprofit = db.ConsumerProfit.Add(new ConsumerProfit()
-                                                    {
-                                                        CreateDate = DateTime.Now,
-                                                        ConsumerId = suborder.ConsumerId,
-                                                        MerchantId = suborder.MerchantId,
-                                                        OrderId = suborder.Id,
-                                                        GetMoney = Math.Round(GetMoney, 2),
-                                                        QueryCount = PayMode,
-                                                        Sort = OrderId,
-                                                        SeoTitle = suborder.OrderNo,
-                                                        SeoKeyword = suborder.PayMoney.ToString(),
-                                                    }).Entity;
-                                                    db.SaveChanges();
                                                     MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == suborder.MerchantId) ?? new MerchantAddInfo();
                                                     if(!orderids.Contains(suborder.Id))
                                                     {
+                                                        string RefundNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
+                                                        int Status = 0;
                                                         if(order.PayMode == 1)
                                                         {
-                                                            AlipayFunction.Instance.Refund(suborder.SeoTitle, Math.Round(GetMoney, 2).ToString(), "门店消费补贴", merchantAdd.AlipayAuthToken);
+                                                            string result = AlipayFunction.Instance.Refund(suborder.SeoTitle, RefundNo, Math.Round(GetMoney, 2).ToString(), "门店消费补贴", merchantAdd.AlipayAuthToken);
                                                         }
                                                         else
                                                         {
-                                                            Dictionary<string, string> dic = WeChatFunction.Instance.Refund(merchantAdd.SubMchid, Math.Round(GetMoney, 2), suborder.PayMoney, suborder.OrderNo, DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), "门店消费补贴");
+                                                            Dictionary<string, string> dic = WeChatFunction.Instance.Refund(merchantAdd.SubMchid, Math.Round(GetMoney, 2), suborder.PayMoney, suborder.OrderNo, RefundNo, "门店消费补贴");
+                                                        }
+                                                        if(Status == 1)
+                                                        {
+                                                            db.ConsumerProfit.Add(new ConsumerProfit()
+                                                            {
+                                                                CreateDate = DateTime.Now,
+                                                                ConsumerId = suborder.ConsumerId,
+                                                                MerchantId = suborder.MerchantId,
+                                                                OrderId = suborder.Id,
+                                                                GetMoney = Math.Round(GetMoney, 2),
+                                                                QueryCount = PayMode,
+                                                                Sort = OrderId,
+                                                                SeoTitle = suborder.OrderNo,
+                                                                SeoKeyword = suborder.PayMoney.ToString(),
+                                                                SeoDescription = RefundNo,
+                                                            });
+                                                            db.SaveChanges();
                                                         }
                                                         orderids.Add(suborder.Id);
                                                     }
@@ -301,10 +307,11 @@ namespace MySystem
 
                                                     if (suborder.CurDivi < suborder.MaxDivi)
                                                     {
-                                                        RedisDbconn.Instance.AddList("ConsumerOrders:Divi:" + PayMode + ":" + MerchantId, suborder);
+                                                        // RedisDbconn.Instance.AddList("ConsumerOrders:Divi:" + PayMode + ":" + MerchantId, suborder);
                                                     }
                                                     else
                                                     {
+                                                        RedisDbconn.Instance.DelFromList("ConsumerOrders:Divi:" + PayMode + ":" + MerchantId, suborder);
                                                         OutCount += 1;
                                                     }
                                                     RedisDbconn.Instance.AddList("ConsumerOrdersSetDivi", "{\"OrderId\":\"" + suborder.Id + "\",\"DiviAmt\":\"" + suborder.CurDivi + "\"}");

+ 14 - 0
AppStart/RedisDbconn.cs

@@ -103,6 +103,13 @@ namespace MySystem
         }
         #endregion
 
+        #region 移动列表元素位置
+        public T RPopLPush<T>(string key, string tokey)
+        {
+            return RedisHelper.RPopLPush<T>(key, tokey);
+        }
+        #endregion
+
         #region 添加集合对象
         public long SAdd(string key, object value)
         {
@@ -142,6 +149,13 @@ namespace MySystem
         }
         #endregion
 
+        #region 移除列表对象
+        public long DelFromList(string key, object value, int count = 1)
+        {
+            return RedisHelper.LRem(key, count, value);
+        }
+        #endregion
+
         #region 删除列表元素
         public void DelList<T>(string key, T item)
         {