feat(orders.manager):新增用户获取支付结果的功能
This commit is contained in:
parent
489513b766
commit
7e0b8840a4
@ -72,4 +72,13 @@ public class ConsumerOrdersController {
|
||||
@RequestBody OrdersPayReqDTO ordersPayReqDTO) {
|
||||
return ordersCreateService.payOrder(id, ordersPayReqDTO);
|
||||
}
|
||||
|
||||
@GetMapping("/pay/{id}/result")
|
||||
@ApiOperation("查询订单支付结果")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "订单id", required = true, dataTypeClass = Long.class)
|
||||
})
|
||||
public OrdersPayResDTO payResult(@PathVariable("id") Long id) {
|
||||
return ordersCreateService.getPayResult(id);
|
||||
}
|
||||
}
|
||||
@ -25,4 +25,9 @@ public interface IOrdersCreateService extends IService<Orders> {
|
||||
* @param id 订单id
|
||||
*/
|
||||
OrdersPayResDTO payOrder(Long id, OrdersPayReqDTO ordersPayReqDTO);
|
||||
|
||||
/**
|
||||
* 客户端获取支付状态
|
||||
*/
|
||||
OrdersPayResDTO getPayResult(Long id);
|
||||
}
|
||||
@ -4,9 +4,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
|
||||
import com.jzo2o.api.foundations.dto.response.ServeAggregationResDTO;
|
||||
import com.jzo2o.api.trade.NativePayApi;
|
||||
import com.jzo2o.api.trade.TradingApi;
|
||||
import com.jzo2o.api.trade.dto.request.NativePayReqDTO;
|
||||
import com.jzo2o.api.trade.dto.response.NativePayResDTO;
|
||||
import com.jzo2o.api.trade.dto.response.TradingResDTO;
|
||||
import com.jzo2o.api.trade.enums.PayChannelEnum;
|
||||
import com.jzo2o.api.trade.enums.TradingStateEnum;
|
||||
import com.jzo2o.common.expcetions.CommonException;
|
||||
import com.jzo2o.common.expcetions.ForbiddenOperationException;
|
||||
import com.jzo2o.common.utils.BeanUtils;
|
||||
@ -53,6 +56,8 @@ public class OrdersCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> i
|
||||
@Resource
|
||||
private NativePayApi nativePayApi;
|
||||
@Resource
|
||||
private TradingApi tradingApi;
|
||||
@Resource
|
||||
private TradeProperties tradeProperties;
|
||||
|
||||
private final String PRODUCT_APP_ID = "jzo2o.orders";
|
||||
@ -88,7 +93,7 @@ public class OrdersCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> i
|
||||
|
||||
// 组装订单信息插入数据库完成下单
|
||||
LocalDateTime serveStartTime = placeOrderReqDTO.getServeStartTime();
|
||||
Long sortColumn = DateUtils.toEpochMilli(serveStartTime) * 100000 + orderId % 100000;
|
||||
Long sortColumn = DateUtils.toEpochMilli(serveStartTime) + orderId % 100000;
|
||||
Orders orderToPay = Orders.builder()
|
||||
.id(orderId)
|
||||
.userId(UserContext.currentUserId())
|
||||
@ -175,4 +180,43 @@ public class OrdersCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> i
|
||||
ordersPayResDTO.setPayStatus(OrderPayStatusEnum.NO_PAY.getStatus());
|
||||
return ordersPayResDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrdersPayResDTO getPayResult(Long id) {
|
||||
Orders orders = baseMapper.selectById(id);
|
||||
if (ObjectUtils.isEmpty(orders)) {
|
||||
throw new CommonException("订单不存在");
|
||||
}
|
||||
|
||||
// 公共返回参数
|
||||
OrdersPayResDTO ordersPayResDTO = BeanUtils.toBean(orders, OrdersPayResDTO.class);
|
||||
ordersPayResDTO.setProductOrderNo(id);
|
||||
|
||||
// 未支付订单更新状态
|
||||
Long tradingOrderNo = orders.getTradingOrderNo();
|
||||
if (ObjectUtils.isNotEmpty(tradingOrderNo)
|
||||
&& orders.getPayStatus() == OrderPayStatusEnum.NO_PAY.getStatus()) {
|
||||
TradingResDTO tradingResDTO = tradingApi.findTradResultByTradingOrderNo(tradingOrderNo);
|
||||
|
||||
// 支付成功
|
||||
if (ObjectUtils.isNotEmpty(tradingResDTO)
|
||||
&& tradingResDTO.getTradingState() == TradingStateEnum.YJS) {
|
||||
lambdaUpdate()
|
||||
.eq(Orders::getId, id)
|
||||
.set(Orders::getPayTime, LocalDateTime.now())
|
||||
.set(Orders::getPayStatus, OrderPayStatusEnum.PAY_SUCCESS.getStatus())
|
||||
.set(Orders::getOrdersStatus, OrderStatusEnum.DISPATCHING.getStatus())
|
||||
.set(Orders::getTransactionId, tradingResDTO.getTransactionId())
|
||||
.update();
|
||||
|
||||
// 支付成功更新最终响应信息的状态
|
||||
ordersPayResDTO.setPayStatus(OrderPayStatusEnum.PAY_SUCCESS.getStatus());
|
||||
} else {
|
||||
// 未支付成功返回二维码
|
||||
ordersPayResDTO.setQrCode(tradingResDTO.getQrCode());
|
||||
}
|
||||
}
|
||||
|
||||
return ordersPayResDTO;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user