fix(分润管理):优化二维码是否开启分润功能逻辑
This commit is contained in:
+30
-10
@@ -18,10 +18,7 @@ import com.central.order.feign.UserCenterService;
|
|||||||
import com.central.order.model.*;
|
import com.central.order.model.*;
|
||||||
import com.central.order.service.*;
|
import com.central.order.service.*;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
@@ -243,6 +240,12 @@ public class OrderController {
|
|||||||
return Result.failed("订单数据不存在");
|
return Result.failed("订单数据不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否需要开启分账
|
||||||
|
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||||
|
if (qrCode == null) {
|
||||||
|
return Result.failed("二维码不存在");
|
||||||
|
}
|
||||||
|
|
||||||
// 3. 创建支付请求
|
// 3. 创建支付请求
|
||||||
PrepayRequest request = new PrepayRequest();
|
PrepayRequest request = new PrepayRequest();
|
||||||
|
|
||||||
@@ -262,12 +265,17 @@ public class OrderController {
|
|||||||
request.setPayer(payer);
|
request.setPayer(payer);
|
||||||
|
|
||||||
// 设置分账信息
|
// 设置分账信息
|
||||||
// SettleInfo settleInfo = new SettleInfo();
|
SettleInfo settleInfo = new SettleInfo();
|
||||||
// settleInfo.setProfitSharing(true); // 直接设置分账标识为true
|
if (isEnableProfit(qrCode)) {
|
||||||
// request.setSettleInfo(settleInfo);
|
settleInfo.setProfitSharing(true);
|
||||||
//
|
request.setSettleInfo(settleInfo);
|
||||||
// // 4. 创建分账记录
|
|
||||||
// ProfitSharing profitSharing = profitSharingService.createProfitSharing(order);
|
// 创建分账记录
|
||||||
|
ProfitSharing profitSharing = profitSharingService.createProfitSharing(order,qrCode);
|
||||||
|
} else {
|
||||||
|
settleInfo.setProfitSharing(false);
|
||||||
|
request.setSettleInfo(settleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
// 5. 调用支付接口
|
// 5. 调用支付接口
|
||||||
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
|
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
|
||||||
@@ -280,6 +288,18 @@ public class OrderController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否开启分润
|
||||||
|
*/
|
||||||
|
private boolean isEnableProfit(QrCode qrCode) {
|
||||||
|
return qrCode != null &&
|
||||||
|
Integer.valueOf(1).equals(qrCode.getEnableProfit()) &&
|
||||||
|
qrCode.getPayeeStatus() != null &&
|
||||||
|
qrCode.getPayeeStatus() == 1 && // 确保分账账号已验证
|
||||||
|
qrCode.getPayeeAccount() != null && // 确保有收款账号
|
||||||
|
qrCode.getProfitRate() != null; // 确保有分润比例
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "获取排队总览信息")
|
@Operation(summary = "获取排队总览信息")
|
||||||
@GetMapping("/queue/info")
|
@GetMapping("/queue/info")
|
||||||
public Result<Map> getQueueInfo(@RequestParam String codeId) {
|
public Result<Map> getQueueInfo(@RequestParam String codeId) {
|
||||||
|
|||||||
+183
-107
@@ -5,8 +5,10 @@ import com.central.order.enums.OrderStatus;
|
|||||||
import com.central.order.enums.RefundState;
|
import com.central.order.enums.RefundState;
|
||||||
import com.central.order.model.Order;
|
import com.central.order.model.Order;
|
||||||
import com.central.order.model.ProfitSharing;
|
import com.central.order.model.ProfitSharing;
|
||||||
|
import com.central.order.model.QrCode;
|
||||||
import com.central.order.service.IOrderService;
|
import com.central.order.service.IOrderService;
|
||||||
import com.central.order.service.IProfitSharingService;
|
import com.central.order.service.IProfitSharingService;
|
||||||
|
import com.central.order.service.IQrCodeService;
|
||||||
import com.central.order.service.IRefundService;
|
import com.central.order.service.IRefundService;
|
||||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||||
@@ -21,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -38,18 +39,14 @@ public class WxPayController {
|
|||||||
private IOrderService orderService;
|
private IOrderService orderService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IRefundService refundService;
|
private IRefundService refundService;
|
||||||
|
@Autowired
|
||||||
|
private IQrCodeService qrCodeService;
|
||||||
|
@Autowired
|
||||||
|
private IProfitSharingService profitSharingService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private NotificationConfig config;
|
private NotificationConfig config;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IProfitSharingService profitSharingService;
|
|
||||||
/**
|
|
||||||
* 支付回调
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@PostMapping("/pay/notify")
|
@PostMapping("/pay/notify")
|
||||||
public String handleCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
public String handleCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
||||||
@RequestHeader("Wechatpay-Timestamp") String timestamp,
|
@RequestHeader("Wechatpay-Timestamp") String timestamp,
|
||||||
@@ -85,37 +82,88 @@ public class WxPayController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handlePaymentResult(Transaction transaction) {
|
private void handlePaymentResult(Transaction transaction) {
|
||||||
// 获取支付通知中的关键信息
|
|
||||||
String outTradeNo = transaction.getOutTradeNo();
|
String outTradeNo = transaction.getOutTradeNo();
|
||||||
String tradeState = transaction.getTradeState().toString();
|
String tradeState = transaction.getTradeState().toString();
|
||||||
|
|
||||||
// 2. 根据支付状态进行相应处理
|
try {
|
||||||
if ("SUCCESS".equals(tradeState)) {
|
if ("SUCCESS".equals(tradeState)) {
|
||||||
// 支付成功,更新订单状态等操作
|
// 1. 获取订单和二维码信息
|
||||||
System.out.println("支付成功,商户订单号:" + outTradeNo);
|
Order order = orderService.getOrderByNumber(outTradeNo);
|
||||||
|
if (order == null) {
|
||||||
|
log.error("订单不存在: {}", outTradeNo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 3. 更新订单状态
|
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||||
Order order = orderService.getOrderByNumber(transaction.getOutTradeNo());
|
if (qrCode == null) {
|
||||||
|
log.error("二维码不存在: {}", order.getCodeId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 更新订单状态
|
||||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||||
order.setPayTime(new Date());
|
order.setPayTime(new Date());
|
||||||
orderService.updateOrder(order);
|
orderService.updateOrder(order);
|
||||||
// 这里可以添加更新数据库订单状态的代码
|
|
||||||
|
|
||||||
// 4. 更新分账记录
|
// 3. 处理分账
|
||||||
// profitSharingService.updateTransactionId(
|
if (isEnableProfit(qrCode)) {
|
||||||
// transaction.getOutTradeNo(),
|
try {
|
||||||
// transaction.getTransactionId()
|
// 更新分账记录的微信支付订单号
|
||||||
// );
|
profitSharingService.updateTransactionId(
|
||||||
|
outTradeNo,
|
||||||
|
transaction.getTransactionId()
|
||||||
|
);
|
||||||
|
|
||||||
// 5. 发起分账请求
|
// 发起分账
|
||||||
// profitSharingService.executeProfitSharing(transaction.getOutTradeNo());
|
profitSharingService.executeProfitSharing(outTradeNo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理分账失败: orderNo={}", outTradeNo, e);
|
||||||
|
// 分账失败不影响支付结果,但需要记录并告警
|
||||||
|
sendProfitSharingAlert(order, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 其他支付状态,如支付中、失败等
|
log.info("支付未成功: orderNo={}, state={}", outTradeNo, tradeState);
|
||||||
System.out.println("支付状态:" + tradeState + ",商户订单号:" + outTradeNo);
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理支付结果异常: orderNo={}", outTradeNo, e);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否开启分润
|
||||||
|
*/
|
||||||
|
private boolean isEnableProfit(QrCode qrCode) {
|
||||||
|
return qrCode != null &&
|
||||||
|
Integer.valueOf(1).equals(qrCode.getEnableProfit()) &&
|
||||||
|
qrCode.getPayeeStatus() != null &&
|
||||||
|
qrCode.getPayeeStatus() == 1 && // 确保分账账号已验证
|
||||||
|
qrCode.getPayeeAccount() != null && // 确保有收款账号
|
||||||
|
qrCode.getProfitRate() != null; // 确保有分润比例
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送分账异常告警
|
||||||
|
*/
|
||||||
|
private void sendProfitSharingAlert(Order order, String errorMessage) {
|
||||||
|
try {
|
||||||
|
String alertMessage = String.format(
|
||||||
|
"分账处理异常告警\n" +
|
||||||
|
"订单号:%s\n" +
|
||||||
|
"异常信息:%s\n" +
|
||||||
|
"时间:%s",
|
||||||
|
order.getOrderNo(),
|
||||||
|
errorMessage,
|
||||||
|
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
|
||||||
|
);
|
||||||
|
|
||||||
|
log.error(alertMessage);
|
||||||
|
// TODO: 实现具体的告警通知逻辑
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送分账异常告警失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/refund/notify")
|
@PostMapping("/refund/notify")
|
||||||
public String refundCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
public String refundCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
||||||
@@ -206,81 +254,6 @@ public class WxPayController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理分账失败
|
|
||||||
*/
|
|
||||||
private void handleProfitSharingFailure(String orderNo, String failReason) {
|
|
||||||
try {
|
|
||||||
log.error("分账失败: orderNo={}, reason={}", orderNo, failReason);
|
|
||||||
|
|
||||||
// 1. 更新分账状态为失败
|
|
||||||
profitSharingService.updateProfitSharingStatus(
|
|
||||||
orderNo,
|
|
||||||
ProfitSharingConstants.Status.FAILED
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2. 获取分账记录
|
|
||||||
ProfitSharing profitSharing = profitSharingService.getByOrderNo(orderNo);
|
|
||||||
if (profitSharing == null) {
|
|
||||||
log.error("分账记录不存在: {}", orderNo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 更新失败原因
|
|
||||||
profitSharing.setFailReason(failReason);
|
|
||||||
profitSharing.setUpdateTime(new Date());
|
|
||||||
|
|
||||||
// 4. 判断是否需要重试
|
|
||||||
if (profitSharing.canRetry()) {
|
|
||||||
log.info("准备重试分账: orderNo={}, retryTimes={}",
|
|
||||||
orderNo, profitSharing.getRetryTimes());
|
|
||||||
profitSharingService.retryFailedProfitSharing(orderNo);
|
|
||||||
} else {
|
|
||||||
log.warn("分账失败且不再重试: orderNo={}, retryTimes={}",
|
|
||||||
orderNo, profitSharing.getRetryTimes());
|
|
||||||
// 可以在这里添加告警通知
|
|
||||||
sendFailureAlert(profitSharing);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理分账失败异常", e);
|
|
||||||
// 确保状态更新为失败
|
|
||||||
profitSharingService.updateProfitSharingStatus(
|
|
||||||
orderNo,
|
|
||||||
ProfitSharingConstants.Status.FAILED
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送失败告警
|
|
||||||
*/
|
|
||||||
private void sendFailureAlert(ProfitSharing profitSharing) {
|
|
||||||
try {
|
|
||||||
String alertMessage = String.format(
|
|
||||||
"分账失败告警\n" +
|
|
||||||
"订单号:%s\n" +
|
|
||||||
"交易号:%s\n" +
|
|
||||||
"失败原因:%s\n" +
|
|
||||||
"重试次数:%d\n" +
|
|
||||||
"分账金额:%d分\n" +
|
|
||||||
"失败时间:%s",
|
|
||||||
profitSharing.getOrderNo(),
|
|
||||||
profitSharing.getTransactionId(),
|
|
||||||
profitSharing.getFailReason(),
|
|
||||||
profitSharing.getRetryTimes(),
|
|
||||||
profitSharing.getQrCodeAmount(),
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
|
|
||||||
);
|
|
||||||
|
|
||||||
log.error(alertMessage);
|
|
||||||
// TODO: 实现具体的告警通知逻辑,如发送邮件、钉钉消息等
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("发送分账失败告警异常", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优化后的分账回调处理方法
|
* 优化后的分账回调处理方法
|
||||||
*/
|
*/
|
||||||
@@ -312,18 +285,121 @@ public class WxPayController {
|
|||||||
String orderNo = notification.getOutOrderNo();
|
String orderNo = notification.getOutOrderNo();
|
||||||
String state = notification.getState();
|
String state = notification.getState();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 1. 获取分账记录
|
||||||
|
ProfitSharing profitSharing = profitSharingService.getByOrderNo(orderNo);
|
||||||
|
if (profitSharing == null) {
|
||||||
|
log.error("分账记录不存在: {}", orderNo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 根据状态处理
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case "FINISHED":
|
case "FINISHED":
|
||||||
|
// 分账成功
|
||||||
|
handleProfitSharingSuccess(profitSharing, notification);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "FAILED":
|
||||||
|
// 分账失败
|
||||||
|
handleProfitSharingFailure(profitSharing, notification);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
log.warn("未知的分账状态: orderNo={}, state={}", orderNo, state);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理分账回调异常: orderNo={}", orderNo, e);
|
||||||
|
// 确保更新状态
|
||||||
profitSharingService.updateProfitSharingStatus(
|
profitSharingService.updateProfitSharingStatus(
|
||||||
orderNo,
|
orderNo,
|
||||||
ProfitSharingConstants.Status.SUCCESS
|
ProfitSharingConstants.Status.FAILED
|
||||||
);
|
);
|
||||||
break;
|
}
|
||||||
case "FAILED":
|
}
|
||||||
handleProfitSharingFailure(orderNo, notification.getFailReason());
|
|
||||||
break;
|
/**
|
||||||
default:
|
* 处理分账成功
|
||||||
log.warn("未知的分账状态: {}", state);
|
*/
|
||||||
|
private void handleProfitSharingSuccess(ProfitSharing profitSharing,
|
||||||
|
ProfitSharingNotification notification) {
|
||||||
|
// 1. 更新分账状态
|
||||||
|
profitSharing.setStatus(ProfitSharingConstants.Status.SUCCESS);
|
||||||
|
profitSharing.setFinishTime(new Date());
|
||||||
|
|
||||||
|
// 2. 如果有接收方信息,更新接收方结果
|
||||||
|
if (notification.getReceivers() != null && !notification.getReceivers().isEmpty()) {
|
||||||
|
ProfitSharingNotification.Receiver receiver = notification.getReceivers().get(0);
|
||||||
|
profitSharing.setReceiverAmount(receiver.getAmount());
|
||||||
|
profitSharing.setProfitSharingId(receiver.getDetailId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 保存更新
|
||||||
|
profitSharingService.updateById(profitSharing);
|
||||||
|
|
||||||
|
log.info("分账成功: orderNo={}", profitSharing.getOrderNo());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理分账失败
|
||||||
|
*/
|
||||||
|
private void handleProfitSharingFailure(ProfitSharing profitSharing,
|
||||||
|
ProfitSharingNotification notification) {
|
||||||
|
// 1. 更新分账状态和失败原因
|
||||||
|
profitSharing.setStatus(ProfitSharingConstants.Status.FAILED);
|
||||||
|
profitSharing.setFailReason(notification.getFailReason());
|
||||||
|
profitSharing.setUpdateTime(new Date());
|
||||||
|
|
||||||
|
// 2. 判断是否需要重试
|
||||||
|
if (profitSharing.canRetry()) {
|
||||||
|
log.info("准备重试分账: orderNo={}, retryTimes={}",
|
||||||
|
profitSharing.getOrderNo(), profitSharing.getRetryTimes());
|
||||||
|
|
||||||
|
// 更新重试信息
|
||||||
|
profitSharing.setRetryTimes(profitSharing.getRetryTimes() + 1);
|
||||||
|
profitSharing.setLastRetryTime(new Date());
|
||||||
|
profitSharingService.updateById(profitSharing);
|
||||||
|
|
||||||
|
// 发起重试
|
||||||
|
profitSharingService.retryFailedProfitSharing(profitSharing.getOrderNo());
|
||||||
|
} else {
|
||||||
|
log.warn("分账失败且不再重试: orderNo={}, retryTimes={}",
|
||||||
|
profitSharing.getOrderNo(), profitSharing.getRetryTimes());
|
||||||
|
|
||||||
|
// 发送告警
|
||||||
|
sendFailureAlert(profitSharing);
|
||||||
|
|
||||||
|
// 保存最终状态
|
||||||
|
profitSharingService.updateById(profitSharing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送失败告警
|
||||||
|
*/
|
||||||
|
private void sendFailureAlert(ProfitSharing profitSharing) {
|
||||||
|
try {
|
||||||
|
String alertMessage = String.format(
|
||||||
|
"分账失败告警\n" +
|
||||||
|
"订单号:%s\n" +
|
||||||
|
"交易号:%s\n" +
|
||||||
|
"失败原因:%s\n" +
|
||||||
|
"重试次数:%d\n" +
|
||||||
|
"分账金额:%d分\n" +
|
||||||
|
"失败时间:%s",
|
||||||
|
profitSharing.getOrderNo(),
|
||||||
|
profitSharing.getTransactionId(),
|
||||||
|
profitSharing.getFailReason(),
|
||||||
|
profitSharing.getRetryTimes(),
|
||||||
|
profitSharing.getQrCodeAmount(),
|
||||||
|
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
|
||||||
|
);
|
||||||
|
|
||||||
|
log.error(alertMessage);
|
||||||
|
// TODO: 实现具体的告警通知逻辑,如发送邮件、钉钉消息等
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送分账失败告警异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,4 +80,10 @@ public class QrCode extends SuperEntity {
|
|||||||
|
|
||||||
@Schema(description = "分账失败原因")
|
@Schema(description = "分账失败原因")
|
||||||
private String payeeFailReason;
|
private String payeeFailReason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启分润(0:否,1:是)
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否开启分润")
|
||||||
|
private Integer enableProfit;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ public interface IProfitSharingService extends ISuperService<ProfitSharing> {
|
|||||||
/**
|
/**
|
||||||
* 创建分账记录
|
* 创建分账记录
|
||||||
*/
|
*/
|
||||||
ProfitSharing createProfitSharing(Order order);
|
ProfitSharing createProfitSharing(Order order, QrCode qrCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新微信支付订单号
|
* 更新微信支付订单号
|
||||||
|
|||||||
+11
-7
@@ -66,19 +66,13 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ProfitSharing createProfitSharing(Order order) {
|
public ProfitSharing createProfitSharing(Order order, QrCode qrCode) {
|
||||||
try {
|
try {
|
||||||
// 1. 参数校验
|
// 1. 参数校验
|
||||||
if (order == null || order.getCodeId() == null) {
|
if (order == null || order.getCodeId() == null) {
|
||||||
throw new IllegalArgumentException("订单或二维码ID不能为空");
|
throw new IllegalArgumentException("订单或二维码ID不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 获取二维码信息
|
|
||||||
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
|
||||||
if (qrCode == null) {
|
|
||||||
throw new IllegalArgumentException("二维码信息不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 验证分账账号
|
// 3. 验证分账账号
|
||||||
validatePayeeAccount(qrCode);
|
validatePayeeAccount(qrCode);
|
||||||
|
|
||||||
@@ -761,4 +755,14 @@ public class ProfitSharingServiceImpl extends SuperServiceImpl<ProfitSharingMapp
|
|||||||
Object value = map.get(key);
|
Object value = map.get(key);
|
||||||
return value == null ? 0.0 : Double.valueOf(String.valueOf(value));
|
return value == null ? 0.0 : Double.valueOf(String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否开启分润
|
||||||
|
*/
|
||||||
|
private boolean isEnableProfit(QrCode qrCode) {
|
||||||
|
return qrCode != null &&
|
||||||
|
Integer.valueOf(1).equals(qrCode.getEnableProfit()) &&
|
||||||
|
qrCode.getPayeeStatus() != null &&
|
||||||
|
qrCode.getPayeeStatus() == 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user