Browse Source

调整补分账程序

lcl 6 months ago
parent
commit
85fe4df05d
1 changed files with 43 additions and 40 deletions
  1. 43 40
      Controllers/HomeController.cs

+ 43 - 40
Controllers/HomeController.cs

@@ -53,50 +53,53 @@ namespace MySystem.Controllers
                         MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
                         MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
                         
                         
                         //获取结算金额
                         //获取结算金额
-                        string settleString = HaoDaHelper.Instance.QueryOrderDivideDetail(merchantAdd.OutMchtNo, order.SeoTitle);
-                        JsonData jsonData = JsonMapper.ToObject(settleString);
-                        if(jsonData["resultCode"].ToString() == "1")
+                        if(order.SettleAmount == 0)
                         {
                         {
-                            string settleAmountString = jsonData["data"]["settleAmount"].ToString();
-                            order.SettleAmount = int.Parse(settleAmountString);
-
-                            //发起分账
-                            decimal fee = order.PayMoney;
-                            if (fee >= 1)
+                            string settleString = HaoDaHelper.Instance.QueryOrderDivideDetail(merchantAdd.OutMchtNo, order.SeoTitle);
+                            JsonData jsonData = JsonMapper.ToObject(settleString);
+                            if(jsonData["resultCode"].ToString() == "1")
                             {
                             {
-                                string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
-                                string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
-                                string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
-                                string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
-                                string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
-                                string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
+                                string settleAmountString = jsonData["data"]["settleAmount"].ToString();
+                                order.SettleAmount = int.Parse(settleAmountString);
+                            }
+                        }
+
+                        //发起分账
+                        decimal fee = order.PayMoney;
+                        if (fee >= 1 && order.SettleAmount > 0)
+                        {
+                            string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
+                            string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
+                            string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
+                            string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
+                            string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
+                            string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
 
 
-                                decimal settleAmount = (decimal)order.SettleAmount / 100M;
-                                decimal divideAmt = (1 - 0.0038M) * order.PayMoney;
-                                divideAmt = decimal.Parse(divideAmt.ToString("f2"));
-                                decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent / 100 - 0.01M);
-                                hdfee = decimal.Parse(hdfee.ToString("f2"));
-                                decimal servicefee = 0.01M * order.PayMoney - hdfee;
-                                servicefee = decimal.Parse(servicefee.ToString("f2"));
-                                decimal amount = order.PayMoney * (1 - 0.0038M) - servicefee;
-                                amount = decimal.Parse(amount.ToString("f2"));
-                                decimal otherAmt = settleAmount - servicefee - amount;
-                                if (otherAmt != 0)
-                                {
-                                    amount += otherAmt;
-                                }
+                            decimal settleAmount = (decimal)order.SettleAmount / 100M;
+                            decimal divideAmt = (1 - 0.0038M) * order.PayMoney;
+                            divideAmt = decimal.Parse(divideAmt.ToString("f2"));
+                            decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent / 100 - 0.01M);
+                            hdfee = decimal.Parse(hdfee.ToString("f2"));
+                            decimal servicefee = 0.01M * order.PayMoney - hdfee;
+                            servicefee = decimal.Parse(servicefee.ToString("f2"));
+                            decimal amount = order.PayMoney * (1 - 0.0038M) - servicefee;
+                            amount = decimal.Parse(amount.ToString("f2"));
+                            decimal otherAmt = settleAmount - servicefee - amount;
+                            if (otherAmt != 0)
+                            {
+                                amount += otherAmt;
+                            }
 
 
-                                amount = amount * 100; //金额(分)
-                                servicefee = servicefee * 100;
-                                string seviceAmount = servicefee.ToString("f0"); //服务费
-                                string amountAmount = amount.ToString("f0");
-                                string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, amountAmount, seviceAmount), merchantAdd.BrandId);
-                                order.DivideLog = "请求分账日志:" + result;
-                                order.TradePayNo = applyNo;
-                                if (result.Contains("\"resultCode\":\"0\"") && (result.Contains("分账金额不足") || result.Contains("不存在")))
-                                {
-                                    Status = 1;
-                                }
+                            amount = amount * 100; //金额(分)
+                            servicefee = servicefee * 100;
+                            string seviceAmount = servicefee.ToString("f0"); //服务费
+                            string amountAmount = amount.ToString("f0");
+                            string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, amountAmount, seviceAmount), merchantAdd.BrandId);
+                            order.DivideLog = "请求分账日志:" + result;
+                            order.TradePayNo = applyNo;
+                            if (result.Contains("\"resultCode\":\"0\"") && (result.Contains("分账金额不足") || result.Contains("不存在")))
+                            {
+                                Status = 1;
                             }
                             }
                         }
                         }
                     }
                     }