From 3a77cc239b2efdc7a3ad1eeaff627b028adb5497 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 24 Oct 2021 00:34:40 +0800 Subject: [PATCH] =?UTF-8?q?yudao-user-server=20=E6=8E=A5=E5=85=A5=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/order/PayOrderCoreService.java | 9 +++ .../order/dto/PayOrderSubmitReqDTO.java | 5 +- .../order/impl/PayOrderCoreServiceImpl.java | 5 ++ .../controller/order/PayOrderController.java | 53 ++++++++++++++++++ .../order/vo/PayOrderSubmitReqVO.java | 28 ++++++++++ .../order/vo/PayOrderSubmitRespVO.java | 23 ++++++++ .../modules/pay/controller/package-info.java | 1 + .../userserver/modules/pay/package-info.java | 7 +++ .../shop/controller/ShopOrderController.java | 55 +++++++++++++++++++ .../controller/vo/ShopOrderCreateRespVO.java | 21 +++++++ .../userserver/modules/shop/package-info.java | 8 +++ 11 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/PayOrderController.java create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitReqVO.java create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitRespVO.java create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/package-info.java create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/package-info.java create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/ShopOrderController.java create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/vo/ShopOrderCreateRespVO.java create mode 100644 yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/package-info.java diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/PayOrderCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/PayOrderCoreService.java index 40adf4ed2..7a6271ad3 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/PayOrderCoreService.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/PayOrderCoreService.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.coreservice.modules.pay.service.order; +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO; import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO; import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO; @@ -13,6 +14,14 @@ import javax.validation.Valid; */ public interface PayOrderCoreService { + /** + * 获得支付单 + * + * @param id 支付单编号 + * @return 支付单 + */ + PayOrderDO getPayOrder(Long id); + /** * 创建支付单 * diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/dto/PayOrderSubmitReqDTO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/dto/PayOrderSubmitReqDTO.java index 007523678..eb08fbb3e 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/dto/PayOrderSubmitReqDTO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/dto/PayOrderSubmitReqDTO.java @@ -1,7 +1,5 @@ package cn.iocoder.yudao.coreservice.modules.pay.service.order.dto; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import lombok.experimental.Accessors; @@ -32,7 +30,7 @@ public class PayOrderSubmitReqDTO implements Serializable { /** * 支付渠道 */ - @NotNull(message = "支付渠道") + @NotEmpty(message = "支付渠道不能为空") private String channelCode; /** @@ -44,7 +42,6 @@ public class PayOrderSubmitReqDTO implements Serializable { /** * 支付渠道的额外参数 */ - @TableField(typeHandler = JacksonTypeHandler.class) private Map channelExtras; } diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/impl/PayOrderCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/impl/PayOrderCoreServiceImpl.java index 344229c5a..7edbeacbb 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/impl/PayOrderCoreServiceImpl.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/impl/PayOrderCoreServiceImpl.java @@ -56,6 +56,11 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService { @Resource private PayOrderExtensionCoreMapper payOrderExtensionCoreMapper; + @Override + public PayOrderDO getPayOrder(Long id) { + return payOrderCoreMapper.selectById(id); + } + @Override public Long createPayOrder(PayOrderCreateReqDTO reqDTO) { // 校验 App diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/PayOrderController.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/PayOrderController.java new file mode 100644 index 000000000..2b298e4c2 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/PayOrderController.java @@ -0,0 +1,53 @@ +package cn.iocoder.yudao.userserver.modules.pay.controller.order; + +import cn.hutool.core.bean.BeanUtil; +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO; +import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayOrderCoreService; +import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO; +import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitReqVO; +import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitRespVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; + +@Api(tags = "支付订单") +@RestController +@RequestMapping("/pay/order") +@Validated +@Slf4j +public class PayOrderController { + + @Resource + private PayOrderCoreService payOrderCoreService; + + @PostMapping("/submit") + @ApiOperation("提交支付订单") +// @PreAuthenticated // TODO 暂时不加登陆验证,前端暂时没做好 + public CommonResult submit(@RequestBody PayOrderSubmitReqVO reqVO) { + // 获得订单 + PayOrderDO payOrder = payOrderCoreService.getPayOrder(reqVO.getId()); + + // 提交支付 + PayOrderSubmitReqDTO reqDTO = new PayOrderSubmitReqDTO(); + BeanUtil.copyProperties(reqVO, reqDTO, false); + reqDTO.setUserIp(getClientIP()); + reqDTO.setAppId(payOrder.getAppId()); + PayOrderSubmitRespDTO respDTO = payOrderCoreService.submitPayOrder(reqDTO); + + // 拼接返回 + return success(PayOrderSubmitRespVO.builder().invokeResponse(respDTO.getInvokeResponse()).build()); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitReqVO.java new file mode 100644 index 000000000..407edb171 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitReqVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.userserver.modules.pay.controller.order.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.Map; + +@ApiModel("支付订单提交 Request VO") +@Data +@Accessors(chain = true) +public class PayOrderSubmitReqVO { + + @ApiModelProperty(value = "支付单编号", required = true, example = "1024") + @NotNull(message = "支付单编号不能为空") + private Long id; + + @ApiModelProperty(value = "支付渠道", required = true, example = "wx_pub") + @NotEmpty(message = "支付渠道不能为空") + private String channelCode; + + @ApiModelProperty(value = "支付渠道的额外参数", notes = "例如说,微信公众号需要传递 openid 参数") + private Map channelExtras; + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitRespVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitRespVO.java new file mode 100644 index 000000000..cddc79c98 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitRespVO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.userserver.modules.pay.controller.order.vo; + +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@ApiModel("支付订单提交 Response VO") +@Data +@Accessors(chain = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PayOrderSubmitRespVO { + + /** + * 调用支付渠道的响应结果 + */ + private String invokeResponse; + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/package-info.java new file mode 100644 index 000000000..739bfdd5a --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.userserver.modules.pay.controller; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/package-info.java new file mode 100644 index 000000000..1aa11cdd2 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/package-info.java @@ -0,0 +1,7 @@ +/** + * pay 包下,我们放支付业务,提供业务的支付能力。 + * 例如说:商户、应用、支付、退款等等 + * + * 缩写:pay + */ +package cn.iocoder.yudao.userserver.modules.pay; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/ShopOrderController.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/ShopOrderController.java new file mode 100644 index 000000000..8075aba5e --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/ShopOrderController.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.userserver.modules.shop.controller; + +import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayOrderCoreService; +import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderCreateReqDTO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import cn.iocoder.yudao.userserver.modules.shop.controller.vo.ShopOrderCreateRespVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.time.Duration; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; + +@Api(tags = "商城订单") +@RestController +@RequestMapping("/shop/order") +@Validated +@Slf4j +public class ShopOrderController { + + @Resource + private PayOrderCoreService payOrderCoreService; + + @PostMapping("/create") + @ApiOperation("创建商城订单") +// @PreAuthenticated // TODO 暂时不加登陆验证,前端暂时没做好 + public CommonResult create() { + // 假装创建商城订单 + Long shopOrderId = System.currentTimeMillis(); + + // 创建对应的支付订单 + PayOrderCreateReqDTO reqDTO = new PayOrderCreateReqDTO(); + reqDTO.setAppId(6L); + reqDTO.setUserIp(getClientIP()); + reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis())); + reqDTO.setSubject("标题:" + shopOrderId); + reqDTO.setBody("内容:" + shopOrderId); + reqDTO.setAmount(100); + reqDTO.setExpireTime(DateUtils.addTime(Duration.ofDays(1))); + Long payOrderId = payOrderCoreService.createPayOrder(reqDTO); + + // 拼接返回 + return success(ShopOrderCreateRespVO.builder().id(shopOrderId) + .payOrderId(payOrderId).build()); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/vo/ShopOrderCreateRespVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/vo/ShopOrderCreateRespVO.java new file mode 100644 index 000000000..682afc4e9 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/vo/ShopOrderCreateRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.userserver.modules.shop.controller.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; + +@ApiModel("商城订单创建 Response VO") +@Data +@Builder +@AllArgsConstructor +public class ShopOrderCreateRespVO { + + @ApiModelProperty(value = "商城订单编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "支付订单编号", required = true, example = "2048") + private Long payOrderId; + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/package-info.java new file mode 100644 index 000000000..c592130af --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/package-info.java @@ -0,0 +1,8 @@ +/** + * shop 包下,我们放商城业务 + * 例如说:商品、订单等等 + * 注意,目前仅仅作为 demo 演示,对接 pay 支付系统 + * + * 缩写:shop + */ +package cn.iocoder.yudao.userserver.modules.shop;