diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserPageReqVO.java index f835b38..7be96b3 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserPageReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserPageReqVO.java @@ -109,4 +109,6 @@ public class PaidMemberUserPageReqVO extends PageParam { @Schema(description = "会员类型") private String payMemberType; + @Schema(description = "商户订单编号") + private String merchantOrderId; } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserRespVO.java index be206c3..7f4bdc2 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserRespVO.java @@ -127,4 +127,7 @@ public class PaidMemberUserRespVO { @Schema(description = "会员类型") private String payMemberType; + @Schema(description = "商户订单编号") + private String merchantOrderId; + } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java index 9f09793..21be83c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java @@ -106,4 +106,7 @@ public class PaidMemberUserSaveReqVO { @Schema(description = "会员类型", requiredMode = Schema.RequiredMode.REQUIRED) private String payMemberType; + + @Schema(description = "商户订单编号", requiredMode = Schema.RequiredMode.REQUIRED) + private String merchantOrderId; } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java index bbdd0f9..f21bfbb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java @@ -156,5 +156,12 @@ public class PaidMemberUserDO extends TenantBaseDO { */ private String payMemberType; + /** + * 商户订单编号 + * + * 例如说,内部系统 A 的订单号,需要保证每个 PayAppDO 唯一 + */ + private String merchantOrderId; + } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java index 8cf0fac..67d498d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java @@ -92,4 +92,5 @@ public interface PaidMemberUserService { */ public Long buildTradeOrder(PaidMemberUserDO updateReqVO); + void updateTradeOrderId(Long merchantOrderId, Long payOrderId); } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java index 8d28e1e..ca6765a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java @@ -1,9 +1,12 @@ package cn.iocoder.yudao.module.member.service.user; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.member.api.address.MemberAddressApi; +import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -58,6 +61,9 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService { @Resource private TradeOrderMapper tradeOrderMapper; + @Resource + private MemberAddressApi addressApi; + @Override public Long createMemberUser(PaidMemberUserSaveReqVO createReqVO) { @@ -212,19 +218,38 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService { @Override public Long buildTradeOrder(PaidMemberUserDO updateReqVO) { TradeOrderDO orderDO = new TradeOrderDO(); + orderDO.setUserId(updateReqVO.getUid()); orderDO.setType(TradeOrderTypeEnum.NORMAL.getType()); orderDO.setNo(updateReqVO.getOrderNo()); orderDO.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); orderDO.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); orderDO.setProductCount(1); orderDO.setUserIp(getClientIP()).setTerminal(getTerminal()); - orderDO.setPayOrderId(updateReqVO.getPayOrderId()); - orderDO.setPayChannelCode(updateReqVO.getPayChannel()); orderDO.setDeliveryType(DeliveryTypeEnum.EXPRESS.getType()); - tradeOrderMapper.insert(orderDO); -// orderDO = tradeOrderMapper.s + //获取用户地址 +// MemberAddressRespDTO address = addressApi.getDefaultAddress(updateReqVO.getUid()); +// orderDO.setReceiverName(address.getName()).setReceiverMobile(address.getMobile()) +// .setReceiverAreaId(address.getAreaId()).setReceiverDetailAddress(address.getDetailAddress()); + //插入新增交易订单 + tradeOrderMapper.insert(orderDO); + //查询最新的交易订单数据 + List list = tradeOrderMapper.selectList(new LambdaQueryWrapperX() + .eqIfPresent(TradeOrderDO::getUserId,updateReqVO.getUid()) + .orderByDesc(TradeOrderDO::getId)); + if(list.isEmpty()){ + return null; + } + orderDO = CollUtil.getFirst(list); return orderDO.getId(); } + @Override + public void updateTradeOrderId(Long merchantOrderId, Long payOrderId) { + TradeOrderDO orderDO = tradeOrderMapper.selectOne(new LambdaQueryWrapperX() + .eqIfPresent(TradeOrderDO::getId,merchantOrderId)); + orderDO.setPayOrderId(payOrderId); + tradeOrderMapper.updateById(orderDO); + } + } \ No newline at end of file diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java index 75d1636..2033e02 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java @@ -95,6 +95,7 @@ public class AppPaidMembeController { //初始化支付金额,单位为分 int price = 0; Long payOrderId = null; + Long merchantOrderId = null; if(reqVO.getCardName().equals("试用")){ BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO); paidMemberUserSaveReqVO.setPayMemberType(reqVO.getCardName()); @@ -139,14 +140,19 @@ public class AppPaidMembeController { Long id = paidMemberUserService.createMemberUser(paidMemberUserSaveReqVO); //查询新增的会员订单记录 paidMemberUserDO = paidMemberUserService.getMemberUser(id); + //创建交易订单号 + merchantOrderId = paidMemberUserService.buildTradeOrder(paidMemberUserDO); + paidMemberUserDO.setMerchantOrderId(String.valueOf(merchantOrderId)); //创建支付订单号 payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO() .setAppId(1L).setUserIp(getClientIP()) - .setMerchantOrderId(""+paidMemberUserDO.getId()) + .setMerchantOrderId(""+paidMemberUserDO.getMerchantOrderId()) .setSubject(PAID_MEMBER_USER_SUBJECT).setBody("") .setPrice(paidMemberUserDO.getPrice()) .setExpireTime(addTime(Duration.ofHours(2L)))); // TODO @芋艿:支付超时时间 paidMemberUserDO.setPayOrderId(payOrderId); + //将支付订单号更新到交易订单中 + paidMemberUserService.updateTradeOrderId(merchantOrderId,payOrderId); //跟新支付订单号进付费会员表里 paidMemberUserService.update(paidMemberUserDO); }