From d9dd08e6d849cbc2b96843e30ac41333039f5be6 Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Thu, 18 Sep 2025 02:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=90=88=E5=8D=95=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E5=86=85=E9=83=A8=E9=85=8D=E9=80=81=E8=B4=B9=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/common/pojo/dto/LklSeparateDTO.java | 244 +++++++++++---- .../service/impl/LakalaPayServiceImpl.java | 4 +- .../service/impl/PayUserPayServiceImpl.java | 17 +- mall-pay/src/main/resources/bootstrap-dev.yml | 2 + .../src/main/resources/bootstrap-local.yml | 2 + .../src/main/resources/bootstrap-prod.yml | 2 + .../src/main/resources/bootstrap-test.yml | 2 + mall-pay/src/main/resources/bootstrap-uat.yml | 2 + .../service/impl/LakalaApiServiceImpl.java | 282 +++++++++++++++++- .../service/impl/ShopOrderLklServiceImpl.java | 12 +- 10 files changed, 487 insertions(+), 82 deletions(-) diff --git a/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java index 92919ef1..ea5c63ee 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java +++ b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java @@ -28,6 +28,8 @@ public class LklSeparateDTO implements java.io.Serializable { private static final long serialVersionUID = 1L; + // ================================ 基础金额属性 ================================ + @ApiModelProperty(value = "分账总金额(分)") private Integer totalSeparateAmount; @@ -40,6 +42,7 @@ public class LklSeparateDTO implements java.io.Serializable { @ApiModelProperty(value = "配送费(分)") private Integer shippingFee; + // ================================ 分账比例属性 ================================ @ApiModelProperty(value = "拉卡拉分账比例(如 0.0025=0.25%)") private BigDecimal lklRatio; @@ -56,6 +59,7 @@ public class LklSeparateDTO implements java.io.Serializable { @ApiModelProperty(value = "二级代理商分账比例(如 0.03=3%)") private BigDecimal agent2ndRatio; + // ================================ 分账金额结果属性 ================================ @ApiModelProperty(value = "拉卡拉分账金额(分)") private Integer lklAmount; @@ -72,6 +76,23 @@ public class LklSeparateDTO implements java.io.Serializable { @ApiModelProperty(value = "二级代理商分账金额(分)") private Integer agent2ndAmount; + // ================================ 内部状态属性 ================================ + + /** + * 分账计算方法类型 + * true表示基于总金额分账(calcOnTotalAmount方法被调用) + * false表示基于可分账金额分账(calcOnCanAmount方法被调用) + */ + private boolean isBasedOnTotalAmount = false; + + // ================================ 构造方法 ================================ + + public LklSeparateDTO() { + // 默认构造函数 + } + + // ================================ 公共方法 ================================ + /** * 测试方法 */ @@ -81,14 +102,15 @@ public class LklSeparateDTO implements java.io.Serializable { // 临界点测试用例2: 小金额测试 logger.info("\n临界点测试用例2 - 小金额测试:"); LklSeparateDTO dto2 = new LklSeparateDTO(); - dto2.setTotalSeparateAmount(2); + dto2.setTotalSeparateAmount(1); dto2.setShippingFee(0); dto2.setLklRatio(new BigDecimal("0.0025")); dto2.setMchRatio(new BigDecimal("0.96")); dto2.setPlatRatio(new BigDecimal("0.01")); - dto2.setAgent1stRatio(new BigDecimal("0.01")); - dto2.setAgent2ndRatio(new BigDecimal("0.04")); - dto2.setRefCanSeparateAmount(8079); // 设置参考可分账金额 + +// dto2.setAgent1stRatio(new BigDecimal("0.01")); +// dto2.setAgent2ndRatio(new BigDecimal("0.04")); +// dto2.setRefCanSeparateAmount(8079); // 设置参考可分账金额 logger.info("测试参数: 总分账金额={}分, 配送费={}分, 拉卡拉比例={}, 商户比例={}, 平台比例={}", dto2.getTotalSeparateAmount(), dto2.getShippingFee(), dto2.getLklRatio(), @@ -149,66 +171,6 @@ public class LklSeparateDTO implements java.io.Serializable { } } - /** - * 将对象转换为JSON字符串格式 - * - * @return 包含所有属性的JSON字符串 - */ - public String toJSON() { - StringBuilder json = new StringBuilder(); - json.append("{"); - - // 添加基本属性 - appendProperty(json, "totalSeparateAmount", totalSeparateAmount, true); - appendProperty(json, "canSeparateAmount", canSeparateAmount, false); - appendProperty(json, "refCanSeparateAmount", refCanSeparateAmount, false); - appendProperty(json, "shippingFee", shippingFee, false); - - // 添加比例属性 - appendProperty(json, "lklRatio", lklRatio, false); - appendProperty(json, "mchRatio", mchRatio, false); - appendProperty(json, "platRatio", platRatio, false); - appendProperty(json, "agent1stRatio", agent1stRatio, false); - appendProperty(json, "agent2ndRatio", agent2ndRatio, false); - - // 添加金额属性 - appendProperty(json, "lklAmount", lklAmount, false); - appendProperty(json, "mchAmount", mchAmount, false); - appendProperty(json, "platAmount", platAmount, false); - appendProperty(json, "agent1stAmount", agent1stAmount, false); - appendProperty(json, "agent2ndAmount", agent2ndAmount, false); - - // 移除最后的逗号并关闭JSON对象 - if (json.charAt(json.length() - 1) == ',') { - json.setLength(json.length() - 1); - } - json.append("}"); - - return json.toString(); - } - - /** - * 向JSON字符串中添加属性 - * - * @param json StringBuilder对象 - * @param key 属性名 - * @param value 属性值 - * @param first 是否为第一个属性 - */ - private void appendProperty(StringBuilder json, String key, Object value, boolean first) { - if (!first) { - json.append(","); - } - json.append("\"").append(key).append("\":"); - if (value == null) { - json.append("null"); - } else if (value instanceof String) { - json.append("\"").append(value).append("\""); - } else { - json.append(value); - } - } - /** * 基于可分账金额的分账计算方法(默认) *
@@ -223,6 +185,9 @@ public class LklSeparateDTO implements java.io.Serializable {
* @return 分账结果是否成功
*/
public boolean calcOnCanAmount() {
+ // 设置分账计算方法类型
+ isBasedOnTotalAmount = false;
+
// 检查前提条件
if (!validateInputs()) {
return false;
@@ -274,6 +239,9 @@ public class LklSeparateDTO implements java.io.Serializable {
* @return 分账结果是否成功
*/
public boolean calcOnTotalAmount() {
+ // 设置分账计算方法类型
+ isBasedOnTotalAmount = true;
+
// 检查前提条件
if (!validateInputsForTotalAmount()) {
return false;
@@ -311,6 +279,133 @@ public class LklSeparateDTO implements java.io.Serializable {
return true;
}
+ /**
+ * 输出具体的分账结果
+ *
+ * @return 分账结果字符串
+ */
+ @Override
+ public String toString() {
+ int canSeparateAmount = getCanSeparateAmount();
+ int totalSeparateAmount = getTotalSeparateAmount();
+
+ // 计算各分账方占总金额和可分账金额的百分比
+ double lklRatioOfTotal = 0.0;
+ double mchRatioOfTotal = 0.0;
+ double platRatioOfTotal = 0.0;
+ double agent1stRatioOfTotal = 0.0;
+ double agent2ndRatioOfTotal = 0.0;
+ double shippingFeeRatioOfTotal = 0.0;
+
+ double lklRatioOfAvailable = 0.0;
+ double mchRatioOfAvailable = 0.0;
+ double platRatioOfAvailable = 0.0;
+ double agent1stRatioOfAvailable = 0.0;
+ double agent2ndRatioOfAvailable = 0.0;
+ double shippingFeeRatioOfAvailable = 0.0;
+
+ if (totalSeparateAmount > 0) {
+ if (getLklAmount() != null) {
+ lklRatioOfTotal = (double) getLklAmount() / totalSeparateAmount * 100;
+ }
+ if (getMchAmount() != null) {
+ mchRatioOfTotal = (double) getMchAmount() / totalSeparateAmount * 100;
+ }
+ if (getPlatAmount() != null) {
+ platRatioOfTotal = (double) getPlatAmount() / totalSeparateAmount * 100;
+ }
+ if (getAgent1stAmount() != null) {
+ agent1stRatioOfTotal = (double) getAgent1stAmount() / totalSeparateAmount * 100;
+ }
+ if (getAgent2ndAmount() != null) {
+ agent2ndRatioOfTotal = (double) getAgent2ndAmount() / totalSeparateAmount * 100;
+ }
+ if (getShippingFee() != null) {
+ shippingFeeRatioOfTotal = (double) getShippingFee() / totalSeparateAmount * 100;
+ }
+ }
+
+ if (canSeparateAmount > 0) {
+ if (getLklAmount() != null) {
+ lklRatioOfAvailable = (double) getLklAmount() / canSeparateAmount * 100;
+ }
+ if (getMchAmount() != null) {
+ mchRatioOfAvailable = (double) getMchAmount() / canSeparateAmount * 100;
+ }
+ if (getPlatAmount() != null) {
+ platRatioOfAvailable = (double) getPlatAmount() / canSeparateAmount * 100;
+ }
+ if (getAgent1stAmount() != null) {
+ agent1stRatioOfAvailable = (double) getAgent1stAmount() / canSeparateAmount * 100;
+ }
+ if (getAgent2ndAmount() != null) {
+ agent2ndRatioOfAvailable = (double) getAgent2ndAmount() / canSeparateAmount * 100;
+ }
+ if (getShippingFee() != null) {
+ shippingFeeRatioOfAvailable = (double) getShippingFee() / canSeparateAmount * 100;
+ }
+ }
+
+ String calculationMethod = isBasedOnTotalAmount ? "基于总交易额方式计算" : "基于可分账额方式计算";
+
+ return String.format("分账结果%s,总交易额=%d分, 可分账额=%d分, 拉卡拉手续费=%d分(%.2f%%/%.2f%%), 配送费=%d分(%.2f%%/%.2f%%), 商户=%d分(%.2f%%/%.2f%%), 平台=%d分(%.2f%%/%.2f%%), 一级代理商=%d分(%.2f%%/%.2f%%), 二级代理商=%d分(%.2f%%/%.2f%%)",
+ calculationMethod,
+ totalSeparateAmount,
+ canSeparateAmount,
+ getLklAmount() != null ? getLklAmount() : 0,
+ lklRatioOfTotal, lklRatioOfAvailable,
+ getShippingFee() != null ? getShippingFee() : 0,
+ shippingFeeRatioOfTotal, shippingFeeRatioOfAvailable,
+ getMchAmount() != null ? getMchAmount() : 0,
+ mchRatioOfTotal, mchRatioOfAvailable,
+ getPlatAmount() != null ? getPlatAmount() : 0,
+ platRatioOfTotal, platRatioOfAvailable,
+ getAgent1stAmount() != null ? getAgent1stAmount() : 0,
+ agent1stRatioOfTotal, agent1stRatioOfAvailable,
+ getAgent2ndAmount() != null ? getAgent2ndAmount() : 0,
+ agent2ndRatioOfTotal, agent2ndRatioOfAvailable);
+ }
+
+ /**
+ * 将对象转换为JSON字符串格式
+ *
+ * @return 包含所有属性的JSON字符串
+ */
+ public String toJSON() {
+ StringBuilder json = new StringBuilder();
+ json.append("{");
+
+ // 添加基本属性
+ appendProperty(json, "totalSeparateAmount", totalSeparateAmount, true);
+ appendProperty(json, "canSeparateAmount", canSeparateAmount, false);
+ appendProperty(json, "refCanSeparateAmount", refCanSeparateAmount, false);
+ appendProperty(json, "shippingFee", shippingFee, false);
+
+ // 添加比例属性
+ appendProperty(json, "lklRatio", lklRatio, false);
+ appendProperty(json, "mchRatio", mchRatio, false);
+ appendProperty(json, "platRatio", platRatio, false);
+ appendProperty(json, "agent1stRatio", agent1stRatio, false);
+ appendProperty(json, "agent2ndRatio", agent2ndRatio, false);
+
+ // 添加金额属性
+ appendProperty(json, "lklAmount", lklAmount, false);
+ appendProperty(json, "mchAmount", mchAmount, false);
+ appendProperty(json, "platAmount", platAmount, false);
+ appendProperty(json, "agent1stAmount", agent1stAmount, false);
+ appendProperty(json, "agent2ndAmount", agent2ndAmount, false);
+
+ // 移除最后的逗号并关闭JSON对象
+ if (json.charAt(json.length() - 1) == ',') {
+ json.setLength(json.length() - 1);
+ }
+ json.append("}");
+
+ return json.toString();
+ }
+
+ // ================================ 私有方法 ================================
+
/**
* 验证基于可分账金额分账的输入参数
*/
@@ -724,4 +819,25 @@ public class LklSeparateDTO implements java.io.Serializable {
}
}
+ /**
+ * 向JSON字符串中添加属性
+ *
+ * @param json StringBuilder对象
+ * @param key 属性名
+ * @param value 属性值
+ * @param first 是否为第一个属性
+ */
+ private void appendProperty(StringBuilder json, String key, Object value, boolean first) {
+ if (!first) {
+ json.append(",");
+ }
+ json.append("\"").append(key).append("\":");
+ if (value == null) {
+ json.append("null");
+ } else if (value instanceof String) {
+ json.append("\"").append(value).append("\"");
+ } else {
+ json.append(value);
+ }
+ }
}
\ No newline at end of file
diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java
index bbc342af..1b662ccf 100644
--- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java
+++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java
@@ -476,9 +476,11 @@ public class LakalaPayServiceImpl implements LakalaPayService {
return new JSONObject().set("code", "BBS00001").set("msg", "拉卡拉合单交易失败:" + respBody.getStr("msg")).set("resp_data", null);
}
- log.info("[拉卡拉合单预下单] 支付成功,准备保存订单记录, orderId={}", orderId);
+ log.info("[拉卡拉合单预下单] 支付成功,准备保存订单记录, orderId={} shopping_fee_inner={}", orderId, agentAmountInt);
// 新增一个拉卡拉订单记录 shop_order_lkl 表
JSONObject lklPayReqAndRespJson = new JSONObject();
+ reqData.set("shopping_fee_inner", agentAmountInt); // 内部配送费
+
lklPayReqAndRespJson.put("req", reqData);
lklPayReqAndRespJson.put("resp", respBody); // 返回原始响应数据
diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java
index 894cc5ea..76ac9e18 100644
--- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java
+++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java
@@ -130,6 +130,10 @@ public class PayUserPayServiceImpl extends BaseServiceImpl
- * 分账操作流程:
- * 1. 参数校验和订单查询
- * 2. 检查订单状态(是否已确认收货)
- * 3. 检查是否已分账,避免重复处理
- * 4. 计算分账金额
- * 5. 构建分账请求并发送至拉卡拉
- * 6. 保存分账结果
- *
diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java
index b9efdbaa..4703d762 100644
--- a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java
+++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java
@@ -135,7 +135,7 @@ public class ShopOrderLklServiceImpl extends BaseServiceImpl