|
@@ -12,16 +12,10 @@ import com.microsvc.toolkit.common.webportal.exception.BizException;
|
|
import com.microsvc.toolkit.config.jwt.utils.JwtUserInfo;
|
|
import com.microsvc.toolkit.config.jwt.utils.JwtUserInfo;
|
|
import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
|
|
import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
|
|
import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
|
|
import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
|
|
-import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentClose;
|
|
|
|
-import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentOrder;
|
|
|
|
-import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentReq;
|
|
|
|
-import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentResp;
|
|
|
|
|
|
+import com.microsvc.toolkit.middleware.payment.common.api.entity.*;
|
|
import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
|
|
import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
|
|
import com.yonge.cooleshow.biz.dal.entity.*;
|
|
import com.yonge.cooleshow.biz.dal.entity.*;
|
|
-import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.GoodTypeEnum;
|
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
|
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
|
|
|
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.*;
|
|
import com.yonge.cooleshow.biz.dal.enums.coupon.CouponCategoryEnum;
|
|
import com.yonge.cooleshow.biz.dal.enums.coupon.CouponCategoryEnum;
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
@@ -32,6 +26,7 @@ import com.yonge.cooleshow.common.enums.*;
|
|
import com.yonge.cooleshow.common.enums.payment.EPaymentChannel;
|
|
import com.yonge.cooleshow.common.enums.payment.EPaymentChannel;
|
|
import com.yonge.cooleshow.common.enums.payment.EPaymentStatus;
|
|
import com.yonge.cooleshow.common.enums.payment.EPaymentStatus;
|
|
import com.yonge.cooleshow.common.enums.payment.EPaymentType;
|
|
import com.yonge.cooleshow.common.enums.payment.EPaymentType;
|
|
|
|
+import com.yonge.toolset.payment.base.enums.TradeStatusEnum;
|
|
import com.yonge.toolset.payment.util.DistributedLock;
|
|
import com.yonge.toolset.payment.util.DistributedLock;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
@@ -124,6 +119,14 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
|
|
@Autowired
|
|
@Autowired
|
|
private PaymentMerchantConfigService paymentMerchantConfigService;
|
|
private PaymentMerchantConfigService paymentMerchantConfigService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserOrderRefundService userOrderRefundService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserOrderRefundBillService userOrderRefundBillService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
// 订单商品参数校验,获取订单支付金额
|
|
// 订单商品参数校验,获取订单支付金额
|
|
private static final Map<GoodTypeEnum, Consumer<UserPaymentOrderWrapper.OrderGoodsInfo>> orderGoodsCreate = Maps.newHashMap();
|
|
private static final Map<GoodTypeEnum, Consumer<UserPaymentOrderWrapper.OrderGoodsInfo>> orderGoodsCreate = Maps.newHashMap();
|
|
@@ -209,7 +212,7 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
|
|
DistributedLock.of(redissonClient).runIfLockCanGet(lockName, () -> {
|
|
DistributedLock.of(redissonClient).runIfLockCanGet(lockName, () -> {
|
|
|
|
|
|
// 获取订单信息
|
|
// 获取订单信息
|
|
- UserPaymentOrderWrapper.UserPaymentOrder paymentOrder = userPaymentOrderService.getUserPaymentOrderByOrderNo(paymentResp.getTransNo(), paymentResp.getMerOrderNo());
|
|
|
|
|
|
+ UserPaymentOrderWrapper.UserPaymentOrder paymentOrder = userPaymentOrderService.getUserPaymentOrderByOrderNo( paymentResp.getMerOrderNo());
|
|
if (Objects.isNull(paymentOrder)) {
|
|
if (Objects.isNull(paymentOrder)) {
|
|
log.error("executePaymentCallback 无效的支付订单, paymentResp={}", JSON.toJSONString(paymentResp));
|
|
log.error("executePaymentCallback 无效的支付订单, paymentResp={}", JSON.toJSONString(paymentResp));
|
|
throw new BizException("无效的支付订单");
|
|
throw new BizException("无效的支付订单");
|
|
@@ -1017,6 +1020,48 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 退款回调
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void refundPaymentCallback(RefundResp refundResp) {
|
|
|
|
+
|
|
|
|
+ String lockName = redisCacheService.getPaymentCacheKey(refundResp.getMerOrderNo());
|
|
|
|
+ // 并发执行锁
|
|
|
|
+ DistributedLock.of(redissonClient).runIfLockCanGet(lockName, () -> {
|
|
|
|
+ // 退款订单确认
|
|
|
|
+ UserOrderRefundBill refundOrder = userOrderRefundBillService.getByTransNoOrOrderNo(refundResp.getTransNo(), refundResp.getMerOrderNo());
|
|
|
|
+ if (Objects.isNull(refundOrder)) {
|
|
|
|
+ throw new com.yonge.toolset.base.exception.BizException("退款订单不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ refundOrder.setUpdateTime(new Date());
|
|
|
|
+ refundOrder.setTransNo(refundResp.getTransNo());
|
|
|
|
+ // 退款申请失败
|
|
|
|
+ if (PaymentStatus.FAILED == refundResp.getPaymentStatus()) {
|
|
|
|
+
|
|
|
|
+ // 更新用户退款订单状态
|
|
|
|
+ refundOrder.setStatus(TradeStatusEnum.failed);
|
|
|
|
+ refundOrder.setPayFailMsg(refundResp.getMsg());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 退款处理已完成,本地订单状态未同步
|
|
|
|
+ if (PaymentStatus.SUCCESSED == refundResp.getPaymentStatus()) {
|
|
|
|
+
|
|
|
|
+ refundOrder.setBackRefundAmt(refundResp.getRefundAmount());
|
|
|
|
+ refundOrder.setStatus(TradeStatusEnum.succeeded);
|
|
|
|
+ }
|
|
|
|
+ userOrderRefundBillService.updateById(refundOrder);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }, 60L, TimeUnit.SECONDS);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ log.info("refundPaymentCallback refundResp={}", JSON.toJSONString(refundResp));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 定时更新订单状态
|
|
* 定时更新订单状态
|
|
* @param page IPage<UserPaymentOrderWrapper.UserPaymentOrder>
|
|
* @param page IPage<UserPaymentOrderWrapper.UserPaymentOrder>
|
|
* @param orderQuery UserPaymentOrderWrapper.UserPaymentOrderQuery
|
|
* @param orderQuery UserPaymentOrderWrapper.UserPaymentOrderQuery
|
|
@@ -1101,4 +1146,70 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
|
|
//log.info("scheduleUpdatePaymentOrderStatus PAYMENT_FINISH ------> ");
|
|
//log.info("scheduleUpdatePaymentOrderStatus PAYMENT_FINISH ------> ");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用户申请退款
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ @Override
|
|
|
|
+ public void refundPayment(String orderNo, String reason) {
|
|
|
|
+
|
|
|
|
+ // 查询订单信息,支付状态
|
|
|
|
+ UserPaymentOrderWrapper.UserPaymentOrder paymentOrder = userPaymentOrderService.getUserPaymentOrderByOrderNo(orderNo);
|
|
|
|
+ if (Objects.isNull(paymentOrder)) {
|
|
|
|
+ throw new BizException("订单信息不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!OrderStatusEnum.PAID.getCode().equals(paymentOrder.getStatus().getCode())) {
|
|
|
|
+ throw new BizException("订单状态异常");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 执行状态锁定
|
|
|
|
+ String lockName = redisCacheService.getExecuteOrderCacheKey(paymentOrder.getUserId().toString());
|
|
|
|
+ DistributedLock.of(redissonClient).runIfLockCanGet(lockName, () -> {
|
|
|
|
+ // 提交退款申请记录
|
|
|
|
+ UserOrderRefund userRefundOrder = new UserOrderRefund();
|
|
|
|
+ userRefundOrder.setUserId(paymentOrder.getId());
|
|
|
|
+ userRefundOrder.setOrderId(paymentOrder.getId());
|
|
|
|
+ userRefundOrder.setOrderNo(paymentOrder.getOrderNo());
|
|
|
|
+ userRefundOrder.setOredrDetilIds(paymentOrder.getTransNo());
|
|
|
|
+ userRefundOrder.setStatus(AuthStatusEnum.PASS);
|
|
|
|
+ userRefundOrder.setApplyAmount(paymentOrder.getPaymentCashAmount());
|
|
|
|
+ userRefundOrder.setActualAmount(paymentOrder.getPaymentCouponAmount());
|
|
|
|
+ userRefundOrder.setReason(reason);
|
|
|
|
+ userOrderRefundService.save(userRefundOrder);
|
|
|
|
+
|
|
|
|
+ //入退款单表
|
|
|
|
+ UserOrderRefundBill orderRefundBill = new UserOrderRefundBill();
|
|
|
|
+ orderRefundBill.setRefundId(userRefundOrder.getId());
|
|
|
|
+ orderRefundBill.setBillNo(IdWorker.getIdStr());
|
|
|
|
+ orderRefundBill.setRefundAmt(userRefundOrder.getActualAmount());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ RefundOrder refundOrder = new RefundOrder();
|
|
|
|
+ refundOrder.setUserId(paymentOrder.getUserId().toString());
|
|
|
|
+ refundOrder.setMerOrderNo(orderRefundBill.getBillNo());
|
|
|
|
+ refundOrder.setRefundAmount(orderRefundBill.getRefundAmt());
|
|
|
|
+ refundOrder.setOrderAmount(paymentOrder.getPaymentCashAmount());
|
|
|
|
+ refundOrder.setReason(reason);
|
|
|
|
+ refundOrder.setPaymentOrderNo(paymentOrder.getOrderNo());
|
|
|
|
+ RefundResp refundResp = paymentServiceContext.getPaymentService(paymentOrder.getPaymentVendor()).refund(refundOrder);
|
|
|
|
+ // 申请请求失败
|
|
|
|
+ if (PaymentStatus.FAILED == refundResp.getPaymentStatus()) {
|
|
|
|
+ orderRefundBill.setStatus(TradeStatusEnum.failed);
|
|
|
|
+ orderRefundBill.setPayFailMsg(refundResp.getMsg());
|
|
|
|
+ } else {
|
|
|
|
+ orderRefundBill.setTransNo(refundResp.getTransNo());
|
|
|
|
+ orderRefundBill.setStatus(TradeStatusEnum.pending);
|
|
|
|
+ }
|
|
|
|
+ userOrderRefundBillService.save(orderRefundBill);
|
|
|
|
+
|
|
|
|
+ //处理退款业务
|
|
|
|
+ userOrderRefundService.orderRefundSuccessBizHandle(userRefundOrder.getId());
|
|
|
|
+
|
|
|
|
+ }, 10L, TimeUnit.SECONDS);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|