mirror of
https://gitee.com/zhijiantianya/yudao-cloud.git
synced 2025-12-30 09:22:27 +00:00
feat(pay,mall-trade): 小程序商品订单详情path配置支持
- 在 PayOrderApi 中新增 getMerchantOrderIdByPayOrderNo 方法 - 在 PayOrderApiImpl 中实现该方法,调用 service 层逻辑 - 在 PayOrderMapper 中增加 selectByNo 查询方法 - 在 PayOrderService 中定义 getMerchantOrderIdByNo 接口 - 在 PayOrderServiceImpl 中实现 getMerchantOrderIdByNo 业务逻辑 - 支持通过支付订单编号查询对应的商户订单编号feat(trade): 新增通过支付订单编号查询交易订单详情功能 - 在 AppTradeOrderController 中新增 getOrderDetailByOutTradeNo 接口 - 支持微信小程序订单中心跳转到订单详情页面 - 在 TradeOrderQueryService 中定义 getOrderByOutTradeNo 方法 - 在 TradeOrderQueryServiceImpl 中实现该方法 - 通过 PayOrderApi 调用获取商户订单编号 - 根据商户订单编号查询对应的交易订单信息
This commit is contained in:
@@ -105,7 +105,7 @@ public class AppTradeOrderController {
|
|||||||
&& TradeOrderStatusEnum.isUnpaid(order.getStatus()) && !order.getPayStatus()) {
|
&& TradeOrderStatusEnum.isUnpaid(order.getStatus()) && !order.getPayStatus()) {
|
||||||
tradeOrderUpdateService.syncOrderPayStatusQuietly(order.getId(), order.getPayOrderId());
|
tradeOrderUpdateService.syncOrderPayStatusQuietly(order.getId(), order.getPayOrderId());
|
||||||
// 重新查询,因为同步后,可能会有变化
|
// 重新查询,因为同步后,可能会有变化
|
||||||
order = tradeOrderQueryService.getOrder(id);
|
order = tradeOrderQueryService.getOrder(order.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.1 查询订单项
|
// 2.1 查询订单项
|
||||||
@@ -117,6 +117,40 @@ public class AppTradeOrderController {
|
|||||||
return success(TradeOrderConvert.INSTANCE.convert02(order, orderItems, tradeOrderProperties, express));
|
return success(TradeOrderConvert.INSTANCE.convert02(order, orderItems, tradeOrderProperties, express));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-detailByOutTradeNo")
|
||||||
|
@Operation(summary = "获得交易订单")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "id", description = "PATH需包含「${商品订单号} 」,微信将把你在支付预下单接口填入的 out_trade_no 替换此内容"),
|
||||||
|
@Parameter(name = "sync", description = "是否同步支付状态", example = "true")
|
||||||
|
})
|
||||||
|
public CommonResult<AppTradeOrderDetailRespVO> getOrderDetailByOutTradeNo(@RequestParam("id") String id,
|
||||||
|
@RequestParam(value = "sync", required = false) Boolean sync) {
|
||||||
|
// PATH需包含「${商品订单号} 」,微信将把你在支付预下单接口填入的 out_trade_no 替换此内容,如「index/orderDetail?id=${商品订单号}&channel=1」。PATH最多输入1条。
|
||||||
|
// https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order_center/order_center.html
|
||||||
|
// 小程序商品订单详情path配置为:pages/order/detail?id=${商品订单号}&comein_type=wechat
|
||||||
|
// 通过 rpc payOrderNo -> tradeOrderId
|
||||||
|
// 1.1 查询订单
|
||||||
|
TradeOrderDO order = tradeOrderQueryService.getOrderByOutTradeNo(getLoginUserId(), id);
|
||||||
|
if (order == null) {
|
||||||
|
return success(null);
|
||||||
|
}
|
||||||
|
// 1.2 sync 仅在等待支付
|
||||||
|
if (Boolean.TRUE.equals(sync)
|
||||||
|
&& TradeOrderStatusEnum.isUnpaid(order.getStatus()) && !order.getPayStatus()) {
|
||||||
|
tradeOrderUpdateService.syncOrderPayStatusQuietly(order.getId(), order.getPayOrderId());
|
||||||
|
// 重新查询,因为同步后,可能会有变化
|
||||||
|
order = tradeOrderQueryService.getOrder(order.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.1 查询订单项
|
||||||
|
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(order.getId());
|
||||||
|
// 2.2 查询物流公司
|
||||||
|
DeliveryExpressDO express = order.getLogisticsId() != null && order.getLogisticsId() > 0 ?
|
||||||
|
deliveryExpressService.getDeliveryExpress(order.getLogisticsId()) : null;
|
||||||
|
// 2.3 最终组合
|
||||||
|
return success(TradeOrderConvert.INSTANCE.convert02(order, orderItems, tradeOrderProperties, express));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/get-express-track-list")
|
@GetMapping("/get-express-track-list")
|
||||||
@Operation(summary = "获得交易订单的物流轨迹")
|
@Operation(summary = "获得交易订单的物流轨迹")
|
||||||
@Parameter(name = "id", description = "交易订单编号")
|
@Parameter(name = "id", description = "交易订单编号")
|
||||||
|
|||||||
@@ -39,7 +39,15 @@ public interface TradeOrderQueryService {
|
|||||||
* @return 交易订单
|
* @return 交易订单
|
||||||
*/
|
*/
|
||||||
TradeOrderDO getOrder(Long userId, Long id);
|
TradeOrderDO getOrder(Long userId, Long id);
|
||||||
|
/**
|
||||||
|
* 获得指定用户,指定的交易订单
|
||||||
|
* PATH需包含「${商品订单号} 」,微信将把你在支付预下单接口填入的 out_trade_no 替换此内容,如「index/orderDetail?id=${商品订单号}&channel=1」。PATH最多输入1条。
|
||||||
|
* https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order_center/order_center.html
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @param outTradeNo 支付订单no
|
||||||
|
* @return 交易订单
|
||||||
|
*/
|
||||||
|
TradeOrderDO getOrderByOutTradeNo(Long userId, String outTradeNo);
|
||||||
/**
|
/**
|
||||||
* 获得指定用户,指定活动,指定状态的交易订单
|
* 获得指定用户,指定活动,指定状态的交易订单
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
package cn.iocoder.yudao.module.trade.service.order;
|
package cn.iocoder.yudao.module.trade.service.order;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
||||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||||
|
import cn.iocoder.yudao.module.pay.api.order.PayOrderApi;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderSummaryRespVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderSummaryRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
|
||||||
@@ -57,6 +60,8 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
|
|||||||
@Resource
|
@Resource
|
||||||
private MemberUserApi memberUserApi;
|
private MemberUserApi memberUserApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PayOrderApi payOrderApi;
|
||||||
// =================== Order ===================
|
// =================== Order ===================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,6 +78,19 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
|
|||||||
}
|
}
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public TradeOrderDO getOrderByOutTradeNo(Long userId, String outTradeNo) {
|
||||||
|
// PATH需包含「${商品订单号} 」,微信将把你在支付预下单接口填入的 out_trade_no 替换此内容,如「index/orderDetail?id=${商品订单号}&channel=1」。PATH最多输入1条。
|
||||||
|
// https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order_center/order_center.html
|
||||||
|
// 小程序商品订单详情path配置为:pages/order/detail?id=${商品订单号}&comein_type=wechat
|
||||||
|
// 通过 rpc payOrderNo -> tradeOrderId
|
||||||
|
String id = outTradeNo;
|
||||||
|
String merchantOrderId = payOrderApi.getMerchantOrderIdByPayOrderNo(outTradeNo).getCheckedData();
|
||||||
|
if(CharSequenceUtil.isNotEmpty(merchantOrderId)){
|
||||||
|
id = merchantOrderId;
|
||||||
|
}
|
||||||
|
return getSelf().getOrder(userId, Convert.toLong(id));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TradeOrderDO getOrderByUserIdAndStatusAndCombination(Long userId, Long combinationActivityId, Integer status) {
|
public TradeOrderDO getOrderByUserIdAndStatusAndCombination(Long userId, Long combinationActivityId, Integer status) {
|
||||||
|
|||||||
@@ -39,4 +39,8 @@ public interface PayOrderApi {
|
|||||||
CommonResult<Boolean> updatePayOrderPrice(@RequestParam("id") Long id,
|
CommonResult<Boolean> updatePayOrderPrice(@RequestParam("id") Long id,
|
||||||
@RequestParam("payPrice") Integer payPrice);
|
@RequestParam("payPrice") Integer payPrice);
|
||||||
|
|
||||||
|
@PostMapping(PREFIX + "/getMerchantOrderIdByNo")
|
||||||
|
@Operation(summary = "根据支付订单编号获取商户订单编号")
|
||||||
|
@Parameter(name = "no", description = "支付单编号", example = "Pxxxx", required = true)
|
||||||
|
CommonResult<String> getMerchantOrderIdByPayOrderNo(@RequestParam("no") String no);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,8 @@ public class PayOrderApiImpl implements PayOrderApi {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<String> getMerchantOrderIdByPayOrderNo(String no) {
|
||||||
|
return success(payOrderService.getMerchantOrderIdByNo(no));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ public interface PayOrderMapper extends BaseMapperX<PayOrderDO> {
|
|||||||
PayOrderDO::getMerchantOrderId, merchantOrderId);
|
PayOrderDO::getMerchantOrderId, merchantOrderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default PayOrderDO selectByNo(String no) {
|
||||||
|
return selectOne(PayOrderDO::getNo, no);
|
||||||
|
}
|
||||||
|
|
||||||
default int updateByIdAndStatus(Long id, Integer status, PayOrderDO update) {
|
default int updateByIdAndStatus(Long id, Integer status, PayOrderDO update) {
|
||||||
return update(update, new LambdaQueryWrapper<PayOrderDO>()
|
return update(update, new LambdaQueryWrapper<PayOrderDO>()
|
||||||
.eq(PayOrderDO::getId, id).eq(PayOrderDO::getStatus, status));
|
.eq(PayOrderDO::getId, id).eq(PayOrderDO::getStatus, status));
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ public interface PayOrderService {
|
|||||||
*/
|
*/
|
||||||
PayOrderDO getOrder(Long appId, String merchantOrderId);
|
PayOrderDO getOrder(Long appId, String merchantOrderId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得商户订单编号
|
||||||
|
*
|
||||||
|
* @param no 编号
|
||||||
|
* @return merchantOrderId
|
||||||
|
*/
|
||||||
|
String getMerchantOrderIdByNo(String no);
|
||||||
/**
|
/**
|
||||||
* 获得支付订单列表
|
* 获得支付订单列表
|
||||||
*
|
*
|
||||||
@@ -155,5 +162,4 @@ public interface PayOrderService {
|
|||||||
* @return 过期的订单数量
|
* @return 过期的订单数量
|
||||||
*/
|
*/
|
||||||
int expireOrder();
|
int expireOrder();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,17 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
return orderMapper.selectByAppIdAndMerchantOrderId(appId, merchantOrderId);
|
return orderMapper.selectByAppIdAndMerchantOrderId(appId, merchantOrderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMerchantOrderIdByNo(String no) {
|
||||||
|
if(no.contains(payProperties.getOrderNoPrefix())){
|
||||||
|
PayOrderDO order = orderMapper.selectByNo(no);
|
||||||
|
if(ObjectUtil.isNotNull(order)){
|
||||||
|
return order.getMerchantOrderId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PayOrderDO> getOrderList(Collection<Long> ids) {
|
public List<PayOrderDO> getOrderList(Collection<Long> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user