新增交易订单

This commit is contained in:
khy 2024-10-25 16:14:01 +08:00
parent 6beabe3478
commit f8de72bc6a
7 changed files with 52 additions and 5 deletions

View File

@ -109,4 +109,6 @@ public class PaidMemberUserPageReqVO extends PageParam {
@Schema(description = "会员类型") @Schema(description = "会员类型")
private String payMemberType; private String payMemberType;
@Schema(description = "商户订单编号")
private String merchantOrderId;
} }

View File

@ -127,4 +127,7 @@ public class PaidMemberUserRespVO {
@Schema(description = "会员类型") @Schema(description = "会员类型")
private String payMemberType; private String payMemberType;
@Schema(description = "商户订单编号")
private String merchantOrderId;
} }

View File

@ -106,4 +106,7 @@ public class PaidMemberUserSaveReqVO {
@Schema(description = "会员类型", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "会员类型", requiredMode = Schema.RequiredMode.REQUIRED)
private String payMemberType; private String payMemberType;
@Schema(description = "商户订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
private String merchantOrderId;
} }

View File

@ -156,5 +156,12 @@ public class PaidMemberUserDO extends TenantBaseDO {
*/ */
private String payMemberType; private String payMemberType;
/**
* 商户订单编号
*
* 例如说内部系统 A 的订单号需要保证每个 PayAppDO 唯一
*/
private String merchantOrderId;
} }

View File

@ -92,4 +92,5 @@ public interface PaidMemberUserService {
*/ */
public Long buildTradeOrder(PaidMemberUserDO updateReqVO); public Long buildTradeOrder(PaidMemberUserDO updateReqVO);
void updateTradeOrderId(Long merchantOrderId, Long payOrderId);
} }

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.module.member.service.user; 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.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 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.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService; import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
@ -58,6 +61,9 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
@Resource @Resource
private TradeOrderMapper tradeOrderMapper; private TradeOrderMapper tradeOrderMapper;
@Resource
private MemberAddressApi addressApi;
@Override @Override
public Long createMemberUser(PaidMemberUserSaveReqVO createReqVO) { public Long createMemberUser(PaidMemberUserSaveReqVO createReqVO) {
@ -212,19 +218,38 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
@Override @Override
public Long buildTradeOrder(PaidMemberUserDO updateReqVO) { public Long buildTradeOrder(PaidMemberUserDO updateReqVO) {
TradeOrderDO orderDO = new TradeOrderDO(); TradeOrderDO orderDO = new TradeOrderDO();
orderDO.setUserId(updateReqVO.getUid());
orderDO.setType(TradeOrderTypeEnum.NORMAL.getType()); orderDO.setType(TradeOrderTypeEnum.NORMAL.getType());
orderDO.setNo(updateReqVO.getOrderNo()); orderDO.setNo(updateReqVO.getOrderNo());
orderDO.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); orderDO.setStatus(TradeOrderStatusEnum.UNPAID.getStatus());
orderDO.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); orderDO.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
orderDO.setProductCount(1); orderDO.setProductCount(1);
orderDO.setUserIp(getClientIP()).setTerminal(getTerminal()); orderDO.setUserIp(getClientIP()).setTerminal(getTerminal());
orderDO.setPayOrderId(updateReqVO.getPayOrderId());
orderDO.setPayChannelCode(updateReqVO.getPayChannel());
orderDO.setDeliveryType(DeliveryTypeEnum.EXPRESS.getType()); orderDO.setDeliveryType(DeliveryTypeEnum.EXPRESS.getType());
//获取用户地址
// MemberAddressRespDTO address = addressApi.getDefaultAddress(updateReqVO.getUid());
// orderDO.setReceiverName(address.getName()).setReceiverMobile(address.getMobile())
// .setReceiverAreaId(address.getAreaId()).setReceiverDetailAddress(address.getDetailAddress());
//插入新增交易订单
tradeOrderMapper.insert(orderDO); tradeOrderMapper.insert(orderDO);
// orderDO = tradeOrderMapper.s //查询最新的交易订单数据
List<TradeOrderDO> list = tradeOrderMapper.selectList(new LambdaQueryWrapperX<TradeOrderDO>()
.eqIfPresent(TradeOrderDO::getUserId,updateReqVO.getUid())
.orderByDesc(TradeOrderDO::getId));
if(list.isEmpty()){
return null;
}
orderDO = CollUtil.getFirst(list);
return orderDO.getId(); return orderDO.getId();
} }
@Override
public void updateTradeOrderId(Long merchantOrderId, Long payOrderId) {
TradeOrderDO orderDO = tradeOrderMapper.selectOne(new LambdaQueryWrapperX<TradeOrderDO>()
.eqIfPresent(TradeOrderDO::getId,merchantOrderId));
orderDO.setPayOrderId(payOrderId);
tradeOrderMapper.updateById(orderDO);
}
} }

View File

@ -95,6 +95,7 @@ public class AppPaidMembeController {
//初始化支付金额,单位为分 //初始化支付金额,单位为分
int price = 0; int price = 0;
Long payOrderId = null; Long payOrderId = null;
Long merchantOrderId = null;
if(reqVO.getCardName().equals("试用")){ if(reqVO.getCardName().equals("试用")){
BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO); BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO);
paidMemberUserSaveReqVO.setPayMemberType(reqVO.getCardName()); paidMemberUserSaveReqVO.setPayMemberType(reqVO.getCardName());
@ -139,14 +140,19 @@ public class AppPaidMembeController {
Long id = paidMemberUserService.createMemberUser(paidMemberUserSaveReqVO); Long id = paidMemberUserService.createMemberUser(paidMemberUserSaveReqVO);
//查询新增的会员订单记录 //查询新增的会员订单记录
paidMemberUserDO = paidMemberUserService.getMemberUser(id); paidMemberUserDO = paidMemberUserService.getMemberUser(id);
//创建交易订单号
merchantOrderId = paidMemberUserService.buildTradeOrder(paidMemberUserDO);
paidMemberUserDO.setMerchantOrderId(String.valueOf(merchantOrderId));
//创建支付订单号 //创建支付订单号
payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO() payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO()
.setAppId(1L).setUserIp(getClientIP()) .setAppId(1L).setUserIp(getClientIP())
.setMerchantOrderId(""+paidMemberUserDO.getId()) .setMerchantOrderId(""+paidMemberUserDO.getMerchantOrderId())
.setSubject(PAID_MEMBER_USER_SUBJECT).setBody("") .setSubject(PAID_MEMBER_USER_SUBJECT).setBody("")
.setPrice(paidMemberUserDO.getPrice()) .setPrice(paidMemberUserDO.getPrice())
.setExpireTime(addTime(Duration.ofHours(2L)))); // TODO @芋艿支付超时时间 .setExpireTime(addTime(Duration.ofHours(2L)))); // TODO @芋艿支付超时时间
paidMemberUserDO.setPayOrderId(payOrderId); paidMemberUserDO.setPayOrderId(payOrderId);
//将支付订单号更新到交易订单中
paidMemberUserService.updateTradeOrderId(merchantOrderId,payOrderId);
//跟新支付订单号进付费会员表里 //跟新支付订单号进付费会员表里
paidMemberUserService.update(paidMemberUserDO); paidMemberUserService.update(paidMemberUserDO);
} }