|
@@ -160,7 +160,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
getSelf().notifyOrder(channel, unifiedOrderResp);
|
|
|
// 如有渠道错误码,则抛出业务异常,提示用户
|
|
|
if (StrUtil.isNotEmpty(unifiedOrderResp.getChannelErrorCode())) {
|
|
|
- throw exception(ORDER_SUBMIT_CHANNEL_ERROR, unifiedOrderResp.getChannelErrorCode(),
|
|
|
+ throw exception(PAY_ORDER_SUBMIT_CHANNEL_ERROR, unifiedOrderResp.getChannelErrorCode(),
|
|
|
unifiedOrderResp.getChannelErrorMsg());
|
|
|
}
|
|
|
// 此处需要读取最新的状态
|
|
@@ -172,16 +172,16 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
private PayOrderDO validateOrderCanSubmit(Long id) {
|
|
|
PayOrderDO order = orderMapper.selectById(id);
|
|
|
if (order == null) { // 是否存在
|
|
|
- throw exception(ORDER_NOT_FOUND);
|
|
|
+ throw exception(PAY_ORDER_NOT_FOUND);
|
|
|
}
|
|
|
if (PayOrderStatusEnum.isSuccess(order.getStatus())) { // 校验状态,发现已支付
|
|
|
- throw exception(ORDER_STATUS_IS_SUCCESS);
|
|
|
+ throw exception(PAY_ORDER_STATUS_IS_SUCCESS);
|
|
|
}
|
|
|
if (!PayOrderStatusEnum.WAITING.getStatus().equals(order.getStatus())) { // 校验状态,必须是待支付
|
|
|
- throw exception(ORDER_STATUS_IS_NOT_WAITING);
|
|
|
+ throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
|
|
|
}
|
|
|
if (LocalDateTimeUtils.beforeNow(order.getExpireTime())) { // 校验是否过期
|
|
|
- throw exception(ORDER_IS_EXPIRED);
|
|
|
+ throw exception(PAY_ORDER_IS_EXPIRED);
|
|
|
}
|
|
|
|
|
|
// 【重要】校验是否支付拓展单已支付,只是没有回调、或者数据不正常
|
|
@@ -202,7 +202,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) {
|
|
|
log.warn("[validateOrderCanSubmit][order({}) 的 extension({}) 已支付,可能是数据不一致]",
|
|
|
id, orderExtension.getId());
|
|
|
- throw exception(ORDER_EXTENSION_IS_PAID);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_IS_PAID);
|
|
|
}
|
|
|
// 情况二:调用三方接口,查询支付单状态,是不是已支付
|
|
|
PayClient payClient = payClientFactory.getPayClient(orderExtension.getChannelId());
|
|
@@ -214,7 +214,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
if (respDTO != null && PayOrderStatusRespEnum.isSuccess(respDTO.getStatus())) {
|
|
|
log.warn("[validateOrderCanSubmit][order({}) 的 PayOrderRespDTO({}) 已支付,可能是回调延迟]",
|
|
|
id, toJsonString(respDTO));
|
|
|
- throw exception(ORDER_EXTENSION_IS_PAID);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_IS_PAID);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -254,9 +254,10 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
* 通知并更新订单的支付结果
|
|
|
*
|
|
|
* @param channel 支付渠道
|
|
|
- * @param notify 通知
|
|
|
+ * @param notify 通知
|
|
|
*/
|
|
|
- @Transactional(rollbackFor = Exception.class) // 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ // 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效
|
|
|
public void notifyOrder(PayChannelDO channel, PayOrderRespDTO notify) {
|
|
|
// 情况一:支付成功的回调
|
|
|
if (PayOrderStatusRespEnum.isSuccess(notify.getStatus())) {
|
|
@@ -295,21 +296,21 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
// 1. 查询 PayOrderExtensionDO
|
|
|
PayOrderExtensionDO orderExtension = orderExtensionMapper.selectByNo(notify.getOutTradeNo());
|
|
|
if (orderExtension == null) {
|
|
|
- throw exception(ORDER_EXTENSION_NOT_FOUND);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_NOT_FOUND);
|
|
|
}
|
|
|
if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) { // 如果已经是成功,直接返回,不用重复更新
|
|
|
log.info("[updateOrderExtensionSuccess][orderExtension({}) 已经是已支付,无需更新]", orderExtension.getId());
|
|
|
return orderExtension;
|
|
|
}
|
|
|
if (ObjectUtil.notEqual(orderExtension.getStatus(), PayOrderStatusEnum.WAITING.getStatus())) { // 校验状态,必须是待支付
|
|
|
- throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
}
|
|
|
|
|
|
// 2. 更新 PayOrderExtensionDO
|
|
|
int updateCounts = orderExtensionMapper.updateByIdAndStatus(orderExtension.getId(), orderExtension.getStatus(),
|
|
|
PayOrderExtensionDO.builder().status(PayOrderStatusEnum.SUCCESS.getStatus()).channelNotifyData(toJsonString(notify)).build());
|
|
|
if (updateCounts == 0) { // 校验状态,必须是待支付
|
|
|
- throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
}
|
|
|
log.info("[updateOrderExtensionSuccess][orderExtension({}) 更新为已支付]", orderExtension.getId());
|
|
|
return orderExtension;
|
|
@@ -318,17 +319,17 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
/**
|
|
|
* 更新 PayOrderDO 支付成功
|
|
|
*
|
|
|
- * @param channel 支付渠道
|
|
|
+ * @param channel 支付渠道
|
|
|
* @param orderExtension 支付拓展单
|
|
|
- * @param notify 通知回调
|
|
|
+ * @param notify 通知回调
|
|
|
* @return 是否之前已经成功回调
|
|
|
*/
|
|
|
private Boolean updateOrderSuccess(PayChannelDO channel, PayOrderExtensionDO orderExtension,
|
|
|
- PayOrderRespDTO notify) {
|
|
|
+ PayOrderRespDTO notify) {
|
|
|
// 1. 判断 PayOrderDO 是否处于待支付
|
|
|
PayOrderDO order = orderMapper.selectById(orderExtension.getOrderId());
|
|
|
if (order == null) {
|
|
|
- throw exception(ORDER_NOT_FOUND);
|
|
|
+ throw exception(PAY_ORDER_NOT_FOUND);
|
|
|
}
|
|
|
if (PayOrderStatusEnum.isSuccess(order.getStatus()) // 如果已经是成功,直接返回,不用重复更新
|
|
|
&& Objects.equals(order.getExtensionId(), orderExtension.getId())) {
|
|
@@ -336,7 +337,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
return true;
|
|
|
}
|
|
|
if (!PayOrderStatusEnum.WAITING.getStatus().equals(order.getStatus())) { // 校验状态,必须是待支付
|
|
|
- throw exception(ORDER_STATUS_IS_NOT_WAITING);
|
|
|
+ throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
|
|
|
}
|
|
|
|
|
|
// 2. 更新 PayOrderDO
|
|
@@ -346,10 +347,10 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
.successTime(notify.getSuccessTime()).extensionId(orderExtension.getId()).no(orderExtension.getNo())
|
|
|
.channelOrderNo(notify.getChannelOrderNo()).channelUserId(notify.getChannelUserId())
|
|
|
.channelFeeRate(channel.getFeeRate())
|
|
|
- .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate()))
|
|
|
+ .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate()))
|
|
|
.build());
|
|
|
if (updateCounts == 0) { // 校验状态,必须是待支付
|
|
|
- throw exception(ORDER_STATUS_IS_NOT_WAITING);
|
|
|
+ throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
|
|
|
}
|
|
|
log.info("[updateOrderExtensionSuccess][order({}) 更新为已支付]", order.getId());
|
|
|
return false;
|
|
@@ -363,7 +364,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
// 1. 查询 PayOrderExtensionDO
|
|
|
PayOrderExtensionDO orderExtension = orderExtensionMapper.selectByNo(notify.getOutTradeNo());
|
|
|
if (orderExtension == null) {
|
|
|
- throw exception(ORDER_EXTENSION_NOT_FOUND);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_NOT_FOUND);
|
|
|
}
|
|
|
if (PayOrderStatusEnum.isClosed(orderExtension.getStatus())) { // 如果已经是关闭,直接返回,不用重复更新
|
|
|
log.info("[updateOrderExtensionClosed][orderExtension({}) 已经是支付关闭,无需更新]", orderExtension.getId());
|
|
@@ -375,7 +376,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
return;
|
|
|
}
|
|
|
if (ObjectUtil.notEqual(orderExtension.getStatus(), PayOrderStatusEnum.WAITING.getStatus())) { // 校验状态,必须是待支付
|
|
|
- throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
}
|
|
|
|
|
|
// 2. 更新 PayOrderExtensionDO
|
|
@@ -383,7 +384,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
PayOrderExtensionDO.builder().status(PayOrderStatusEnum.CLOSED.getStatus()).channelNotifyData(toJsonString(notify))
|
|
|
.channelErrorCode(notify.getChannelErrorCode()).channelErrorMsg(notify.getChannelErrorMsg()).build());
|
|
|
if (updateCounts == 0) { // 校验状态,必须是待支付
|
|
|
- throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
+ throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
|
|
|
}
|
|
|
log.info("[updateOrderExtensionClosed][orderExtension({}) 更新为支付关闭]", orderExtension.getId());
|
|
|
}
|
|
@@ -392,10 +393,10 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
public void updateOrderRefundPrice(Long id, Integer incrRefundPrice) {
|
|
|
PayOrderDO order = orderMapper.selectById(id);
|
|
|
if (order == null) {
|
|
|
- throw exception(ORDER_NOT_FOUND);
|
|
|
+ throw exception(PAY_ORDER_NOT_FOUND);
|
|
|
}
|
|
|
if (!PayOrderStatusEnum.isSuccessOrRefund(order.getStatus())) {
|
|
|
- throw exception(ORDER_REFUND_FAIL_STATUS_ERROR);
|
|
|
+ throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR);
|
|
|
}
|
|
|
if (order.getRefundPrice() + incrRefundPrice > order.getPrice()) {
|
|
|
throw exception(REFUND_PRICE_EXCEED);
|
|
@@ -407,16 +408,21 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
.setStatus(PayOrderStatusEnum.REFUND.getStatus());
|
|
|
int updateCount = orderMapper.updateByIdAndStatus(id, order.getStatus(), updateObj);
|
|
|
if (updateCount == 0) {
|
|
|
- throw exception(ORDER_REFUND_FAIL_STATUS_ERROR);
|
|
|
+ throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updatePayOrderPriceById(Long payOrderId, Integer payPrice) {
|
|
|
- // TODO @puhui999:不能直接这样修改哈;应该只有未支付状态的订单才可以改;另外,如果价格如果没变,可以直接 return 哈;
|
|
|
- PayOrderDO order = orderMapper.selectById(payOrderId);
|
|
|
+ public void updatePayOrderPrice(Long id, Integer payPrice) {
|
|
|
+ PayOrderDO order = orderMapper.selectById(id);
|
|
|
if (order == null) {
|
|
|
- throw exception(ORDER_NOT_FOUND);
|
|
|
+ throw exception(PAY_ORDER_NOT_FOUND);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.notEqual(PayOrderStatusEnum.WAITING.getStatus(), order.getStatus())) {
|
|
|
+ throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equal(order.getPrice(), payPrice)) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
order.setPrice(payPrice);
|