Commit 51dab96889dfd3b5a1a8e1617b090ac9cc717c5b
1 parent
50354462
支付订单错误码枚举类变量添加 PAY_ 前缀和交易订单区分开避免冲突
Showing
9 changed files
with
72 additions
and
65 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
| ... | ... | @@ -34,6 +34,9 @@ public interface ErrorCodeConstants { |
| 34 | 34 | ErrorCode ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000023, "交易订单发货失败,砍价未成功"); |
| 35 | 35 | ErrorCode ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS = new ErrorCode(1011000024, "交易订单发货失败,发货类型不是快递"); |
| 36 | 36 | ErrorCode ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID = new ErrorCode(1011000025, "交易订单取消失败,订单不是【待支付】状态"); |
| 37 | + ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1011000026, "支付订单调价失败,原因:支付订单已付款,不能调价"); | |
| 38 | + ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1011000027, "支付订单调价失败,原因:价格没有变化"); | |
| 39 | + ErrorCode ORDER_UPDATE_PRICE_FAIL_NOT_ITEM = new ErrorCode(1011000028, "支付订单调价失败,原因:订单项不存在"); | |
| 37 | 40 | |
| 38 | 41 | // ========== After Sale 模块 1011000100 ========== |
| 39 | 42 | ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); | ... | ... |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java
| ... | ... | @@ -21,19 +21,17 @@ public interface ErrorCodeConstants { |
| 21 | 21 | ErrorCode CHANNEL_EXIST_SAME_CHANNEL_ERROR = new ErrorCode(1007001004, "已存在相同的渠道"); |
| 22 | 22 | |
| 23 | 23 | // ========== ORDER 模块 1007002000 ========== |
| 24 | - ErrorCode ORDER_NOT_FOUND = new ErrorCode(1007002000, "支付订单不存在"); | |
| 25 | - ErrorCode ORDER_STATUS_IS_NOT_WAITING = new ErrorCode(1007002001, "支付订单不处于待支付"); | |
| 26 | - ErrorCode ORDER_STATUS_IS_SUCCESS = new ErrorCode(1007002002, "订单已支付,请刷新页面"); | |
| 27 | - ErrorCode ORDER_IS_EXPIRED = new ErrorCode(1007002003, "支付订单已经过期"); | |
| 28 | - ErrorCode ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1007002004, "发起支付报错,错误码:{},错误提示:{}"); | |
| 29 | - ErrorCode ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1007002005, "支付订单退款失败,原因:状态不是已支付或已退款"); | |
| 30 | - ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1007002006, "支付订单调价失败,原因:支付订单已付款,不能调价"); | |
| 31 | - ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1007002007, "支付订单调价失败,原因:价格没有变化"); | |
| 24 | + ErrorCode PAY_ORDER_NOT_FOUND = new ErrorCode(1007002000, "支付订单不存在"); | |
| 25 | + ErrorCode PAY_ORDER_STATUS_IS_NOT_WAITING = new ErrorCode(1007002001, "支付订单不处于待支付"); | |
| 26 | + ErrorCode PAY_ORDER_STATUS_IS_SUCCESS = new ErrorCode(1007002002, "订单已支付,请刷新页面"); | |
| 27 | + ErrorCode PAY_ORDER_IS_EXPIRED = new ErrorCode(1007002003, "支付订单已经过期"); | |
| 28 | + ErrorCode PAY_ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1007002004, "发起支付报错,错误码:{},错误提示:{}"); | |
| 29 | + ErrorCode PAY_ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1007002005, "支付订单退款失败,原因:状态不是已支付或已退款"); | |
| 32 | 30 | |
| 33 | 31 | // ========== ORDER 模块(拓展单) 1007003000 ========== |
| 34 | - ErrorCode ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1007003000, "支付交易拓展单不存在"); | |
| 35 | - ErrorCode ORDER_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(1007003001, "支付交易拓展单不处于待支付"); | |
| 36 | - ErrorCode ORDER_EXTENSION_IS_PAID = new ErrorCode(1007003002, "订单已支付,请等待支付结果"); | |
| 32 | + ErrorCode PAY_ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1007003000, "支付交易拓展单不存在"); | |
| 33 | + ErrorCode PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(1007003001, "支付交易拓展单不处于待支付"); | |
| 34 | + ErrorCode PAY_ORDER_EXTENSION_IS_PAID = new ErrorCode(1007003002, "订单已支付,请等待支付结果"); | |
| 37 | 35 | |
| 38 | 36 | // ========== 支付模块(退款) 1007006000 ========== |
| 39 | 37 | ErrorCode REFUND_PRICE_EXCEED = new ErrorCode(1007006000, "退款金额超过订单可退款金额"); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java
| ... | ... | @@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j; |
| 26 | 26 | import java.util.Map; |
| 27 | 27 | |
| 28 | 28 | import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; |
| 29 | -import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_EXTENSION_NOT_FOUND; | |
| 29 | +import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_ORDER_EXTENSION_NOT_FOUND; | |
| 30 | 30 | import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.REFUND_NOT_FOUND; |
| 31 | 31 | |
| 32 | 32 | /** |
| ... | ... | @@ -99,8 +99,8 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> { |
| 99 | 99 | PayOrderExtensionDO orderExtension = orderService.getOrderExtensionByNo(outTradeNo); |
| 100 | 100 | // 支付交易拓展单不存在, 返回关闭状态 |
| 101 | 101 | if (orderExtension == null) { |
| 102 | - return PayOrderRespDTO.closedOf(String.valueOf(ORDER_EXTENSION_NOT_FOUND.getCode()), | |
| 103 | - ORDER_EXTENSION_NOT_FOUND.getMsg(), outTradeNo, ""); | |
| 102 | + return PayOrderRespDTO.closedOf(String.valueOf(PAY_ORDER_EXTENSION_NOT_FOUND.getCode()), | |
| 103 | + PAY_ORDER_EXTENSION_NOT_FOUND.getMsg(), outTradeNo, ""); | |
| 104 | 104 | } |
| 105 | 105 | // 关闭状态 |
| 106 | 106 | if (PayOrderStatusEnum.isClosed(orderExtension.getStatus())) { | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/demo/PayDemoOrderServiceImpl.java
| ... | ... | @@ -25,7 +25,7 @@ import java.util.HashMap; |
| 25 | 25 | import java.util.Map; |
| 26 | 26 | import java.util.Objects; |
| 27 | 27 | |
| 28 | -import static cn.hutool.core.util.ObjectUtil.*; | |
| 28 | +import static cn.hutool.core.util.ObjectUtil.notEqual; | |
| 29 | 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 30 | 30 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime; |
| 31 | 31 | import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; |
| ... | ... | @@ -156,7 +156,7 @@ public class PayDemoOrderServiceImpl implements PayDemoOrderService { |
| 156 | 156 | PayOrderRespDTO payOrder = payOrderApi.getOrder(payOrderId); |
| 157 | 157 | if (payOrder == null) { |
| 158 | 158 | log.error("[validateDemoOrderCanPaid][order({}) payOrder({}) 不存在,请进行处理!]", id, payOrderId); |
| 159 | - throw exception(ORDER_NOT_FOUND); | |
| 159 | + throw exception(PAY_ORDER_NOT_FOUND); | |
| 160 | 160 | } |
| 161 | 161 | // 2.2 校验支付单已支付 |
| 162 | 162 | if (!PayOrderStatusEnum.isSuccess(payOrder.getStatus())) { | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java
| ... | ... | @@ -160,7 +160,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 160 | 160 | getSelf().notifyOrder(channel, unifiedOrderResp); |
| 161 | 161 | // 如有渠道错误码,则抛出业务异常,提示用户 |
| 162 | 162 | if (StrUtil.isNotEmpty(unifiedOrderResp.getChannelErrorCode())) { |
| 163 | - throw exception(ORDER_SUBMIT_CHANNEL_ERROR, unifiedOrderResp.getChannelErrorCode(), | |
| 163 | + throw exception(PAY_ORDER_SUBMIT_CHANNEL_ERROR, unifiedOrderResp.getChannelErrorCode(), | |
| 164 | 164 | unifiedOrderResp.getChannelErrorMsg()); |
| 165 | 165 | } |
| 166 | 166 | // 此处需要读取最新的状态 |
| ... | ... | @@ -172,16 +172,16 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 172 | 172 | private PayOrderDO validateOrderCanSubmit(Long id) { |
| 173 | 173 | PayOrderDO order = orderMapper.selectById(id); |
| 174 | 174 | if (order == null) { // 是否存在 |
| 175 | - throw exception(ORDER_NOT_FOUND); | |
| 175 | + throw exception(PAY_ORDER_NOT_FOUND); | |
| 176 | 176 | } |
| 177 | 177 | if (PayOrderStatusEnum.isSuccess(order.getStatus())) { // 校验状态,发现已支付 |
| 178 | - throw exception(ORDER_STATUS_IS_SUCCESS); | |
| 178 | + throw exception(PAY_ORDER_STATUS_IS_SUCCESS); | |
| 179 | 179 | } |
| 180 | 180 | if (!PayOrderStatusEnum.WAITING.getStatus().equals(order.getStatus())) { // 校验状态,必须是待支付 |
| 181 | - throw exception(ORDER_STATUS_IS_NOT_WAITING); | |
| 181 | + throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING); | |
| 182 | 182 | } |
| 183 | 183 | if (LocalDateTimeUtils.beforeNow(order.getExpireTime())) { // 校验是否过期 |
| 184 | - throw exception(ORDER_IS_EXPIRED); | |
| 184 | + throw exception(PAY_ORDER_IS_EXPIRED); | |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // 【重要】校验是否支付拓展单已支付,只是没有回调、或者数据不正常 |
| ... | ... | @@ -202,7 +202,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 202 | 202 | if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) { |
| 203 | 203 | log.warn("[validateOrderCanSubmit][order({}) 的 extension({}) 已支付,可能是数据不一致]", |
| 204 | 204 | id, orderExtension.getId()); |
| 205 | - throw exception(ORDER_EXTENSION_IS_PAID); | |
| 205 | + throw exception(PAY_ORDER_EXTENSION_IS_PAID); | |
| 206 | 206 | } |
| 207 | 207 | // 情况二:调用三方接口,查询支付单状态,是不是已支付 |
| 208 | 208 | PayClient payClient = payClientFactory.getPayClient(orderExtension.getChannelId()); |
| ... | ... | @@ -214,7 +214,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 214 | 214 | if (respDTO != null && PayOrderStatusRespEnum.isSuccess(respDTO.getStatus())) { |
| 215 | 215 | log.warn("[validateOrderCanSubmit][order({}) 的 PayOrderRespDTO({}) 已支付,可能是回调延迟]", |
| 216 | 216 | id, toJsonString(respDTO)); |
| 217 | - throw exception(ORDER_EXTENSION_IS_PAID); | |
| 217 | + throw exception(PAY_ORDER_EXTENSION_IS_PAID); | |
| 218 | 218 | } |
| 219 | 219 | }); |
| 220 | 220 | } |
| ... | ... | @@ -254,9 +254,10 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 254 | 254 | * 通知并更新订单的支付结果 |
| 255 | 255 | * |
| 256 | 256 | * @param channel 支付渠道 |
| 257 | - * @param notify 通知 | |
| 257 | + * @param notify 通知 | |
| 258 | 258 | */ |
| 259 | - @Transactional(rollbackFor = Exception.class) // 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效 | |
| 259 | + @Transactional(rollbackFor = Exception.class) | |
| 260 | + // 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效 | |
| 260 | 261 | public void notifyOrder(PayChannelDO channel, PayOrderRespDTO notify) { |
| 261 | 262 | // 情况一:支付成功的回调 |
| 262 | 263 | if (PayOrderStatusRespEnum.isSuccess(notify.getStatus())) { |
| ... | ... | @@ -295,21 +296,21 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 295 | 296 | // 1. 查询 PayOrderExtensionDO |
| 296 | 297 | PayOrderExtensionDO orderExtension = orderExtensionMapper.selectByNo(notify.getOutTradeNo()); |
| 297 | 298 | if (orderExtension == null) { |
| 298 | - throw exception(ORDER_EXTENSION_NOT_FOUND); | |
| 299 | + throw exception(PAY_ORDER_EXTENSION_NOT_FOUND); | |
| 299 | 300 | } |
| 300 | 301 | if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) { // 如果已经是成功,直接返回,不用重复更新 |
| 301 | 302 | log.info("[updateOrderExtensionSuccess][orderExtension({}) 已经是已支付,无需更新]", orderExtension.getId()); |
| 302 | 303 | return orderExtension; |
| 303 | 304 | } |
| 304 | 305 | if (ObjectUtil.notEqual(orderExtension.getStatus(), PayOrderStatusEnum.WAITING.getStatus())) { // 校验状态,必须是待支付 |
| 305 | - throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 306 | + throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 306 | 307 | } |
| 307 | 308 | |
| 308 | 309 | // 2. 更新 PayOrderExtensionDO |
| 309 | 310 | int updateCounts = orderExtensionMapper.updateByIdAndStatus(orderExtension.getId(), orderExtension.getStatus(), |
| 310 | 311 | PayOrderExtensionDO.builder().status(PayOrderStatusEnum.SUCCESS.getStatus()).channelNotifyData(toJsonString(notify)).build()); |
| 311 | 312 | if (updateCounts == 0) { // 校验状态,必须是待支付 |
| 312 | - throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 313 | + throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 313 | 314 | } |
| 314 | 315 | log.info("[updateOrderExtensionSuccess][orderExtension({}) 更新为已支付]", orderExtension.getId()); |
| 315 | 316 | return orderExtension; |
| ... | ... | @@ -318,17 +319,17 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 318 | 319 | /** |
| 319 | 320 | * 更新 PayOrderDO 支付成功 |
| 320 | 321 | * |
| 321 | - * @param channel 支付渠道 | |
| 322 | + * @param channel 支付渠道 | |
| 322 | 323 | * @param orderExtension 支付拓展单 |
| 323 | - * @param notify 通知回调 | |
| 324 | + * @param notify 通知回调 | |
| 324 | 325 | * @return 是否之前已经成功回调 |
| 325 | 326 | */ |
| 326 | 327 | private Boolean updateOrderSuccess(PayChannelDO channel, PayOrderExtensionDO orderExtension, |
| 327 | - PayOrderRespDTO notify) { | |
| 328 | + PayOrderRespDTO notify) { | |
| 328 | 329 | // 1. 判断 PayOrderDO 是否处于待支付 |
| 329 | 330 | PayOrderDO order = orderMapper.selectById(orderExtension.getOrderId()); |
| 330 | 331 | if (order == null) { |
| 331 | - throw exception(ORDER_NOT_FOUND); | |
| 332 | + throw exception(PAY_ORDER_NOT_FOUND); | |
| 332 | 333 | } |
| 333 | 334 | if (PayOrderStatusEnum.isSuccess(order.getStatus()) // 如果已经是成功,直接返回,不用重复更新 |
| 334 | 335 | && Objects.equals(order.getExtensionId(), orderExtension.getId())) { |
| ... | ... | @@ -336,7 +337,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 336 | 337 | return true; |
| 337 | 338 | } |
| 338 | 339 | if (!PayOrderStatusEnum.WAITING.getStatus().equals(order.getStatus())) { // 校验状态,必须是待支付 |
| 339 | - throw exception(ORDER_STATUS_IS_NOT_WAITING); | |
| 340 | + throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING); | |
| 340 | 341 | } |
| 341 | 342 | |
| 342 | 343 | // 2. 更新 PayOrderDO |
| ... | ... | @@ -346,10 +347,10 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 346 | 347 | .successTime(notify.getSuccessTime()).extensionId(orderExtension.getId()).no(orderExtension.getNo()) |
| 347 | 348 | .channelOrderNo(notify.getChannelOrderNo()).channelUserId(notify.getChannelUserId()) |
| 348 | 349 | .channelFeeRate(channel.getFeeRate()) |
| 349 | - .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate())) | |
| 350 | + .channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate())) | |
| 350 | 351 | .build()); |
| 351 | 352 | if (updateCounts == 0) { // 校验状态,必须是待支付 |
| 352 | - throw exception(ORDER_STATUS_IS_NOT_WAITING); | |
| 353 | + throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING); | |
| 353 | 354 | } |
| 354 | 355 | log.info("[updateOrderExtensionSuccess][order({}) 更新为已支付]", order.getId()); |
| 355 | 356 | return false; |
| ... | ... | @@ -363,7 +364,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 363 | 364 | // 1. 查询 PayOrderExtensionDO |
| 364 | 365 | PayOrderExtensionDO orderExtension = orderExtensionMapper.selectByNo(notify.getOutTradeNo()); |
| 365 | 366 | if (orderExtension == null) { |
| 366 | - throw exception(ORDER_EXTENSION_NOT_FOUND); | |
| 367 | + throw exception(PAY_ORDER_EXTENSION_NOT_FOUND); | |
| 367 | 368 | } |
| 368 | 369 | if (PayOrderStatusEnum.isClosed(orderExtension.getStatus())) { // 如果已经是关闭,直接返回,不用重复更新 |
| 369 | 370 | log.info("[updateOrderExtensionClosed][orderExtension({}) 已经是支付关闭,无需更新]", orderExtension.getId()); |
| ... | ... | @@ -375,7 +376,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 375 | 376 | return; |
| 376 | 377 | } |
| 377 | 378 | if (ObjectUtil.notEqual(orderExtension.getStatus(), PayOrderStatusEnum.WAITING.getStatus())) { // 校验状态,必须是待支付 |
| 378 | - throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 379 | + throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 379 | 380 | } |
| 380 | 381 | |
| 381 | 382 | // 2. 更新 PayOrderExtensionDO |
| ... | ... | @@ -383,7 +384,7 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 383 | 384 | PayOrderExtensionDO.builder().status(PayOrderStatusEnum.CLOSED.getStatus()).channelNotifyData(toJsonString(notify)) |
| 384 | 385 | .channelErrorCode(notify.getChannelErrorCode()).channelErrorMsg(notify.getChannelErrorMsg()).build()); |
| 385 | 386 | if (updateCounts == 0) { // 校验状态,必须是待支付 |
| 386 | - throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 387 | + throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 387 | 388 | } |
| 388 | 389 | log.info("[updateOrderExtensionClosed][orderExtension({}) 更新为支付关闭]", orderExtension.getId()); |
| 389 | 390 | } |
| ... | ... | @@ -392,10 +393,10 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 392 | 393 | public void updateOrderRefundPrice(Long id, Integer incrRefundPrice) { |
| 393 | 394 | PayOrderDO order = orderMapper.selectById(id); |
| 394 | 395 | if (order == null) { |
| 395 | - throw exception(ORDER_NOT_FOUND); | |
| 396 | + throw exception(PAY_ORDER_NOT_FOUND); | |
| 396 | 397 | } |
| 397 | 398 | if (!PayOrderStatusEnum.isSuccessOrRefund(order.getStatus())) { |
| 398 | - throw exception(ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 399 | + throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 399 | 400 | } |
| 400 | 401 | if (order.getRefundPrice() + incrRefundPrice > order.getPrice()) { |
| 401 | 402 | throw exception(REFUND_PRICE_EXCEED); |
| ... | ... | @@ -407,16 +408,21 @@ public class PayOrderServiceImpl implements PayOrderService { |
| 407 | 408 | .setStatus(PayOrderStatusEnum.REFUND.getStatus()); |
| 408 | 409 | int updateCount = orderMapper.updateByIdAndStatus(id, order.getStatus(), updateObj); |
| 409 | 410 | if (updateCount == 0) { |
| 410 | - throw exception(ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 411 | + throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 411 | 412 | } |
| 412 | 413 | } |
| 413 | 414 | |
| 414 | 415 | @Override |
| 415 | - public void updatePayOrderPriceById(Long payOrderId, Integer payPrice) { | |
| 416 | - // TODO @puhui999:不能直接这样修改哈;应该只有未支付状态的订单才可以改;另外,如果价格如果没变,可以直接 return 哈; | |
| 417 | - PayOrderDO order = orderMapper.selectById(payOrderId); | |
| 416 | + public void updatePayOrderPrice(Long id, Integer payPrice) { | |
| 417 | + PayOrderDO order = orderMapper.selectById(id); | |
| 418 | 418 | if (order == null) { |
| 419 | - throw exception(ORDER_NOT_FOUND); | |
| 419 | + throw exception(PAY_ORDER_NOT_FOUND); | |
| 420 | + } | |
| 421 | + if (ObjectUtil.notEqual(PayOrderStatusEnum.WAITING.getStatus(), order.getStatus())) { | |
| 422 | + throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING); | |
| 423 | + } | |
| 424 | + if (ObjectUtil.equal(order.getPrice(), payPrice)) { | |
| 425 | + return; | |
| 420 | 426 | } |
| 421 | 427 | |
| 422 | 428 | order.setPrice(payPrice); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java
| ... | ... | @@ -160,11 +160,11 @@ public class PayRefundServiceImpl implements PayRefundService { |
| 160 | 160 | private PayOrderDO validatePayOrderCanRefund(PayRefundCreateReqDTO reqDTO) { |
| 161 | 161 | PayOrderDO order = orderService.getOrder(reqDTO.getAppId(), reqDTO.getMerchantOrderId()); |
| 162 | 162 | if (order == null) { |
| 163 | - throw exception(ORDER_NOT_FOUND); | |
| 163 | + throw exception(PAY_ORDER_NOT_FOUND); | |
| 164 | 164 | } |
| 165 | 165 | // 校验状态,必须是已支付、或者已退款 |
| 166 | 166 | if (!PayOrderStatusEnum.isSuccessOrRefund(order.getStatus())) { |
| 167 | - throw exception(ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 167 | + throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // 校验金额,退款金额不能大于原定的金额 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
| ... | ... | @@ -74,7 +74,7 @@ public class PayWalletServiceImpl implements PayWalletService { |
| 74 | 74 | // 1. 判断支付交易拓展单是否存 |
| 75 | 75 | PayOrderExtensionDO orderExtension = orderService.getOrderExtensionByNo(outTradeNo); |
| 76 | 76 | if (orderExtension == null) { |
| 77 | - throw exception(ORDER_EXTENSION_NOT_FOUND); | |
| 77 | + throw exception(PAY_ORDER_EXTENSION_NOT_FOUND); | |
| 78 | 78 | } |
| 79 | 79 | // 2. 扣减余额 |
| 80 | 80 | return reduceWalletBalance(userId, userType, orderExtension.getOrderId(), PAYMENT, price); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/test/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceTest.java
| ... | ... | @@ -261,7 +261,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 261 | 261 | String userIp = randomString(); |
| 262 | 262 | |
| 263 | 263 | // 调用, 并断言异常 |
| 264 | - assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_NOT_FOUND); | |
| 264 | + assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_NOT_FOUND); | |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | @Test |
| ... | ... | @@ -274,7 +274,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 274 | 274 | String userIp = randomString(); |
| 275 | 275 | |
| 276 | 276 | // 调用, 并断言异常 |
| 277 | - assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_STATUS_IS_NOT_WAITING); | |
| 277 | + assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_STATUS_IS_NOT_WAITING); | |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | @Test |
| ... | ... | @@ -287,7 +287,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 287 | 287 | String userIp = randomString(); |
| 288 | 288 | |
| 289 | 289 | // 调用, 并断言异常 |
| 290 | - assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_STATUS_IS_SUCCESS); | |
| 290 | + assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_STATUS_IS_SUCCESS); | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | @Test |
| ... | ... | @@ -301,7 +301,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 301 | 301 | String userIp = randomString(); |
| 302 | 302 | |
| 303 | 303 | // 调用, 并断言异常 |
| 304 | - assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_IS_EXPIRED); | |
| 304 | + assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_IS_EXPIRED); | |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | @Test |
| ... | ... | @@ -366,7 +366,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 366 | 366 | |
| 367 | 367 | // 调用,并断言异常 |
| 368 | 368 | assertServiceException(() -> orderService.submitOrder(reqVO, userIp), |
| 369 | - ORDER_SUBMIT_CHANNEL_ERROR, "001", "模拟异常"); | |
| 369 | + PAY_ORDER_SUBMIT_CHANNEL_ERROR, "001", "模拟异常"); | |
| 370 | 370 | // 断言,数据记录(PayOrderExtensionDO) |
| 371 | 371 | PayOrderExtensionDO orderExtension = orderExtensionMapper.selectOne(null); |
| 372 | 372 | assertNotNull(orderExtension); |
| ... | ... | @@ -450,7 +450,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 450 | 450 | |
| 451 | 451 | // 调用,并断言异常 |
| 452 | 452 | assertServiceException(() -> orderService.validateOrderActuallyPaid(id), |
| 453 | - ORDER_EXTENSION_IS_PAID); | |
| 453 | + PAY_ORDER_EXTENSION_IS_PAID); | |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | @Test |
| ... | ... | @@ -469,7 +469,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 469 | 469 | |
| 470 | 470 | // 调用,并断言异常 |
| 471 | 471 | assertServiceException(() -> orderService.validateOrderActuallyPaid(id), |
| 472 | - ORDER_EXTENSION_IS_PAID); | |
| 472 | + PAY_ORDER_EXTENSION_IS_PAID); | |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | @Test |
| ... | ... | @@ -519,7 +519,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 519 | 519 | |
| 520 | 520 | // 调用,并断言异常 |
| 521 | 521 | assertServiceException(() -> orderService.notifyOrder(channel, notify), |
| 522 | - ORDER_EXTENSION_NOT_FOUND); | |
| 522 | + PAY_ORDER_EXTENSION_NOT_FOUND); | |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | @Test |
| ... | ... | @@ -537,7 +537,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 537 | 537 | |
| 538 | 538 | // 调用,并断言异常 |
| 539 | 539 | assertServiceException(() -> orderService.notifyOrder(channel, notify), |
| 540 | - ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 540 | + PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | @Test |
| ... | ... | @@ -555,7 +555,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 555 | 555 | |
| 556 | 556 | // 调用,并断言异常 |
| 557 | 557 | assertServiceException(() -> orderService.notifyOrder(channel, notify), |
| 558 | - ORDER_NOT_FOUND); | |
| 558 | + PAY_ORDER_NOT_FOUND); | |
| 559 | 559 | // 断言 PayOrderExtensionDO :数据更新被回滚 |
| 560 | 560 | assertPojoEquals(orderExtension, orderExtensionMapper.selectOne(null)); |
| 561 | 561 | } |
| ... | ... | @@ -588,7 +588,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 588 | 588 | |
| 589 | 589 | // 调用,并断言异常 |
| 590 | 590 | assertServiceException(() -> orderService.notifyOrder(channel, notify), |
| 591 | - ORDER_STATUS_IS_NOT_WAITING); | |
| 591 | + PAY_ORDER_STATUS_IS_NOT_WAITING); | |
| 592 | 592 | // 断言 PayOrderExtensionDO :数据未更新,因为它是 SUCCESS |
| 593 | 593 | assertPojoEquals(orderExtension, orderExtensionMapper.selectOne(null)); |
| 594 | 594 | } |
| ... | ... | @@ -673,7 +673,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 673 | 673 | |
| 674 | 674 | // 调用,并断言异常 |
| 675 | 675 | assertServiceException(() -> orderService.notifyOrder(channel, notify), |
| 676 | - ORDER_EXTENSION_NOT_FOUND); | |
| 676 | + PAY_ORDER_EXTENSION_NOT_FOUND); | |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | @Test |
| ... | ... | @@ -729,7 +729,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 729 | 729 | |
| 730 | 730 | // 调用,并断言异常 |
| 731 | 731 | assertServiceException(() -> orderService.notifyOrder(channel, notify), |
| 732 | - ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 732 | + PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING); | |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | @Test |
| ... | ... | @@ -762,7 +762,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 762 | 762 | |
| 763 | 763 | // 调用,并断言异常 |
| 764 | 764 | assertServiceException(() -> orderService.updateOrderRefundPrice(id, incrRefundPrice), |
| 765 | - ORDER_NOT_FOUND); | |
| 765 | + PAY_ORDER_NOT_FOUND); | |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | @Test |
| ... | ... | @@ -786,7 +786,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 786 | 786 | |
| 787 | 787 | // 调用,并断言异常 |
| 788 | 788 | assertServiceException(() -> orderService.updateOrderRefundPrice(id, incrRefundPrice), |
| 789 | - ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 789 | + PAY_ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | @Test | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/test/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceTest.java
| ... | ... | @@ -219,7 +219,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { |
| 219 | 219 | |
| 220 | 220 | // 调用,并断言异常 |
| 221 | 221 | assertServiceException(() -> refundService.createPayRefund(reqDTO), |
| 222 | - ORDER_NOT_FOUND); | |
| 222 | + PAY_ORDER_NOT_FOUND); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | @Test |
| ... | ... | @@ -245,7 +245,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { |
| 245 | 245 | |
| 246 | 246 | // 调用,并断言异常 |
| 247 | 247 | assertServiceException(() -> refundService.createPayRefund(reqDTO), |
| 248 | - ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 248 | + PAY_ORDER_REFUND_FAIL_STATUS_ERROR); | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | @Test | ... | ... |