refactor: 订单重构

This commit is contained in:
Ray.Hao 2024-06-06 22:53:17 +08:00
parent d55c09343b
commit e00eb8acdc
66 changed files with 416 additions and 518 deletions

View File

@ -53,6 +53,11 @@
<artifactId>weixin-java-pay</artifactId>
</dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>ums-api</artifactId>
</dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>product-api</artifactId>

View File

@ -1,94 +0,0 @@
package com.youlai.mall.oms.config.property;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* wxpay pay properties.
* 示例配置
* <pre>
* # 微信支付配置
* wx:
* pay:
* # 微信支付商户号
* mchId: 12345678
* # 微信支付商户密钥
* mchKey: abcdefghijklmn
* # path除了classpath也可以用url
* keyPath: classpath:wxcert/apiclient_cert.p12
* privateKeyPath: classpath:wxcert/apiclient_key.pem
* privateCertPath: classpath:wxcert/apiclient_cert.pem
* apiV3Key: abcdefghijklmn
* certSerialNo: abcdefghijklmn
* sandboxEnabled: false
* payNotifyUrl: https://exmaple.com/callback-api/v1/wx-pay/notify-order-v3
* refundNotifyUrl: https://example.com/callback-api/v1/wx-pay/notify-refund-v3
* </pre>
*
* @author Gadfly
*/
@Data
@ConfigurationProperties(prefix = "wx.pay")
public class WechatPayProperties {
/**
* 微信支付商户号
*/
private String mchId;
/**
* 微信支付商户密钥
*/
private String mchKey;
/**
* 服务商模式下的子商户公众账号ID普通模式请不要配置请在配置文件中将对应项删除
*/
private String subAppId;
/**
* 服务商模式下的子商户号普通模式请不要配置最好是请在配置文件中将对应项删除
*/
private String subMchId;
/**
* apiclient_cert.p12文件的绝对路径或者如果放在项目中请以classpath:开头指定
*/
private String keyPath;
/**
* apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径.
*/
private String privateKeyPath;
/**
* apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径.
*/
private String privateCertPath;
/**
* apiV3 秘钥值.
*/
private String apiV3Key;
/**
* apiV3 证书序列号值
*/
private String certSerialNo;
/**
* 是否为沙盒环境
*/
private Boolean sandboxEnabled;
/**
* 支付通知url
*/
private String payNotifyUrl;
/**
* 退款通知url
*/
private String refundNotifyUrl;
}

View File

@ -1,73 +0,0 @@
package com.youlai.mall.oms.controller.app;
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.youlai.mall.oms.model.vo.WxPayResponseVO;
import com.youlai.mall.oms.service.app.OrderService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 微信回调接口
*
* @author Gadfly
* @since 2021-05-27 14:24
*/
@Tag(name = "App-微信支付回调接口")
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/callback-api/v1/wx-pay")
public class WxPayCallbackController {
private final OrderService orderService;
/**
* 微信下单支付结果回调
*
* @param notifyData 加密数据
* @param headers 请求头
* @return {"code": "SUCCESS", "message": "成功"}
*/
@PostMapping("/notify-order-v3")
public WxPayResponseVO wxPayOrderNotify(@RequestBody String notifyData,
@RequestHeader HttpHeaders headers) throws WxPayException {
SignatureHeader signatureHeader = getSignatureHeaderByHttpHeaders(headers);
orderService.handleWxPayOrderNotify(signatureHeader, notifyData);
return new WxPayResponseVO()
.setCode(WxPayConstants.ResultCode.SUCCESS)
.setMessage("成功");
}
/**
* 微信退款结果回调
*
* @param notifyData 加密数据
* @param headers 请求头
* @return {"code": "SUCCESS", "message": "成功"}
*/
@PostMapping("/notify-refund-v3")
public WxPayResponseVO wxPayRefundNotify(@RequestBody String notifyData,
@RequestHeader HttpHeaders headers) throws WxPayException {
SignatureHeader signatureHeader = getSignatureHeaderByHttpHeaders(headers);
orderService.handleWxPayRefundNotify(signatureHeader, notifyData);
return new WxPayResponseVO()
.setCode(WxPayConstants.ResultCode.SUCCESS)
.setMessage("成功");
}
private SignatureHeader getSignatureHeaderByHttpHeaders(HttpHeaders headers) {
SignatureHeader signatureHeader = new SignatureHeader();
signatureHeader.setSignature(headers.getFirst("Wechatpay-Signature"));
signatureHeader.setSerial(headers.getFirst("Wechatpay-Serial"));
signatureHeader.setTimeStamp(headers.getFirst("Wechatpay-Timestamp"));
signatureHeader.setNonce(headers.getFirst("Wechatpay-Nonce"));
return signatureHeader;
}
}

View File

@ -1,82 +0,0 @@
package com.youlai.mall.oms.listener;
import com.rabbitmq.client.Channel;
import com.youlai.common.rabbitmq.constant.RabbitMqConstants;
import com.youlai.mall.oms.service.app.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import java.io.IOException;
/**
* 订单超时未支付取消
*
* @author haoxr
* @since 2.0.0
*/
//@Component // 注解绑定死信队列无效暂不使用
@RequiredArgsConstructor
@Slf4j
public class OmsCloseListener {
private final OrderService orderService;
/**
* 延迟队列
* <p>
* 超过 x-message-ttl 设定时间未被消费转发到死信交换机
*/
@RabbitListener(bindings =
{
@QueueBinding(
value = @Queue(value = RabbitMqConstants.ORDER_CLOSE_DELAY_QUEUE,
arguments =
{
@Argument(name = "x-dead-letter-exchange", value = RabbitMqConstants.ORDER_DLX_EXCHANGE),
@Argument(name = "x-dead-letter-routing-key", value = RabbitMqConstants.ORDER_ClOSE_ROUTING_KEY),
@Argument(name = "x-message-ttl", value = "10000", type = "java.lang.Long") // 超时10s
}),
exchange = @Exchange(value = RabbitMqConstants.ORDER_EXCHANGE),
key = { RabbitMqConstants.ORDER_CLOSE_DELAY_ROUTING_KEY}
)
}, ackMode = "MANUAL" // 手动ACK
)
public void handleOrderCloseDelay(String orderSn, Message message, Channel channel) throws IOException {
log.info("订单({})延时队列10s内如果未支付将路由到关单队列", orderSn);
long deliveryTag = message.getMessageProperties().getDeliveryTag();
/**
* @param deliveryTag 消息序号
* @param multiple 是否批量处理true:批量拒绝所有小于deliveryTag的消息false:只处理当前消息
* @param requeue 拒绝是否重新入队列 true:消息重新入队false:禁止消息重新入队
*/
//channel.basicReject(deliveryTag, false); // 等于 channel.basicReject(deliveryTag, false);
}
/**
* 关单队列
*/
@RabbitListener(bindings = {
@QueueBinding(
value = @Queue(value = RabbitMqConstants.ORDER_ClOSE_QUEUE, durable = "true"),
exchange = @Exchange(value = RabbitMqConstants.ORDER_DLX_EXCHANGE),
key = { RabbitMqConstants.ORDER_ClOSE_ROUTING_KEY}
)
}, ackMode = "MANUAL" // 手动ACK
)
@RabbitListener(queues = RabbitMqConstants.ORDER_ClOSE_QUEUE)
public void handleOrderClose(String orderSn, Message message, Channel channel) throws IOException {
long deliveryTag = message.getMessageProperties().getDeliveryTag(); // 消息序号
log.info("订单({})超时未支付,系统自动关闭订单", orderSn);
try {
orderService.closeOrder(orderSn);
channel.basicAck(deliveryTag, false);
} catch (Exception e) {
// TODO 关单失败入定时任务表
channel.basicReject(deliveryTag, false);
}
}
}

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms;
package com.youlai.mall.order;
import com.youlai.mall.product.api.SkuFeignClient;
import com.youlai.mall.ums.api.MemberFeignClient;
@ -10,10 +10,10 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { MemberFeignClient.class, SkuFeignClient.class})
public class OmsApplication {
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OmsApplication.class, args);
SpringApplication.run(OrderApplication.class, args);
}
}

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.config;
package com.youlai.mall.order.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.config;
package com.youlai.mall.order.config;
import com.youlai.common.factory.NamedThreadFactory;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,9 +1,8 @@
package com.youlai.mall.oms.config;
package com.youlai.mall.order.config;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.youlai.mall.oms.config.property.WechatPayProperties;
import com.youlai.mall.order.config.property.WxPayProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
@ -15,39 +14,40 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 微信支付配置
* 微信支付自动装配类
*
* @author Gadfly
*/
@Slf4j
@Configuration
@ConditionalOnClass(WxPayService.class)
@EnableConfigurationProperties(WechatPayProperties.class)
@EnableConfigurationProperties(WxPayProperties.class)
@RequiredArgsConstructor
@Slf4j
public class WxPayConfiguration {
private final WechatPayProperties properties;
private final WxPayProperties properties;
@Bean
@ConditionalOnMissingBean
public WxPayService wxPayService() {
if (StringUtils.isBlank(properties.getMchId())) {
log.error("微信商户号配置无效,请检查!");
return new WxPayServiceImpl();
throw new IllegalArgumentException("微信商户号配置无效");
}
WxPayService wxPayService = new WxPayServiceImpl();
WxPayConfig payConfig = new WxPayConfig();
payConfig.setMchId(StringUtils.trimToNull(properties.getMchId()));
payConfig.setMchKey(StringUtils.trimToNull(properties.getMchKey()));
payConfig.setSubAppId(StringUtils.trimToNull(properties.getSubAppId()));
payConfig.setSubMchId(StringUtils.trimToNull(properties.getSubMchId()));
payConfig.setKeyPath(StringUtils.trimToNull(properties.getKeyPath()));
payConfig.setApiV3Key(StringUtils.trimToNull(properties.getApiV3Key()));
payConfig.setCertSerialNo(StringUtils.trimToNull(properties.getCertSerialNo()));
payConfig.setPrivateKeyPath(StringUtils.trimToNull(properties.getPrivateKeyPath()));
payConfig.setPrivateCertPath(StringUtils.trimToNull(properties.getPrivateCertPath()));
// 可以指定是否使用沙箱环境
payConfig.setUseSandboxEnv(BooleanUtils.toBoolean(properties.getSandboxEnabled()));
com.github.binarywang.wxpay.config.WxPayConfig payConfig = new com.github.binarywang.wxpay.config.WxPayConfig();
payConfig.setAppId(StringUtils.trimToNull(properties.getAppId())); // 小程序或公众号appid
payConfig.setMchId(StringUtils.trimToNull(properties.getMchId())); // 商户号
payConfig.setMchKey(StringUtils.trimToNull(properties.getMchKey())); // 商户密钥
payConfig.setApiV3Key(StringUtils.trimToNull(properties.getApiV3Key())); // 微信支付apiV3密钥
payConfig.setPrivateKeyPath(StringUtils.trimToNull(properties.getPrivateKeyPath())); // 微信支付私钥路径
payConfig.setPrivateCertPath(StringUtils.trimToNull(properties.getPrivateCertPath())); // 微信支付证书路径
payConfig.setNotifyUrl(StringUtils.trimToNull(properties.getNotifyUrl())); // 微信支付异步通知地址
payConfig.setUseSandboxEnv(BooleanUtils.toBoolean(properties.getSandboxEnabled())); // 是否使用沙箱环境
log.debug("WxPayConfig created: {}", payConfig);
wxPayService.setConfig(payConfig);
return wxPayService;
}

View File

@ -0,0 +1,57 @@
package com.youlai.mall.order.config.property;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* 微信支付配置属性
*
* @author Gadfly
* @see com.github.binarywang.wxpay.config.WxPayConfig
*/
@Data
@ConfigurationProperties(prefix = "wx.pay")
public class WxPayProperties {
/**
* 微信公众号或者小程序等的appid
*/
private String appId;
/**
* 微信支付商户号
*/
private String mchId;
/**
* 微信支付商户密钥
*/
private String mchKey;
/**
* 商户私钥文件 apiclient_key.pem的绝对路径或者以classpath:开头的类路径
*/
private String privateKeyPath;
/**
* 商户公钥文件 apiclient_cert.pem的绝对路径或者以classpath:开头的类路径
*/
private String privateCertPath;
/**
* apiV3 秘钥值.
*/
private String apiV3Key;
/**
* 微信支付异步回掉地址
*/
private String notifyUrl;
/**
* 是否为沙盒环境
*/
private Boolean sandboxEnabled;
}

View File

@ -1,14 +1,14 @@
package com.youlai.mall.oms.controller.app;
package com.youlai.mall.order.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import com.youlai.mall.oms.model.form.OrderPaymentForm;
import com.youlai.mall.oms.model.form.OrderSubmitForm;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OrderConfirmVO;
import com.youlai.mall.oms.model.vo.OrderPageVO;
import com.youlai.mall.oms.service.app.OrderService;
import com.youlai.mall.order.model.form.OrderPayForm;
import com.youlai.mall.order.model.form.OrderSubmitForm;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OrderConfirmVO;
import com.youlai.mall.order.model.vo.OrderPageVO;
import com.youlai.mall.order.service.app.OrderService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -26,13 +26,13 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/app-api/v1/orders")
@RequiredArgsConstructor
public class AppOrderController {
public class OrderController {
private final OrderService orderService;
@Operation(summary ="订单分页列表")
@GetMapping
public PageResult<OrderPageVO> getOrderPage(OrderPageQuery queryParams) {
public PageResult<OrderPageVO> listPagedOrders(OrderPageQuery queryParams) {
IPage<OrderPageVO> result = orderService.getOrderPage(queryParams);
return PageResult.success(result);
}
@ -54,8 +54,8 @@ public class AppOrderController {
}
@Operation(summary ="订单支付")
@PostMapping("/payment")
public Result payOrder(@Validated @RequestBody OrderPaymentForm paymentForm) {
@PostMapping("/pay")
public Result payOrder(@Validated @RequestBody OrderPayForm paymentForm) {
boolean result = orderService.payOrder(paymentForm);
return Result.judge(result);
}

View File

@ -0,0 +1,59 @@
package com.youlai.mall.order.controller;
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.youlai.mall.order.model.result.WxPayResult;
import com.youlai.mall.order.service.app.OrderService;
import com.youlai.mall.order.util.WxPayUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 微信支付 APIv3
*
* @author Gadfly
* @since 2021-05-27 14:24
*/
@Tag(name = "微信支付接口-APIv3")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v3/wx-pay")
@Validated
@Slf4j
public class WxPayController {
private final OrderService orderService;
@Operation(summary = "微信下单支付结果回调")
@PostMapping("/notify/order")
public WxPayResult wxPayOrderNotify(
@RequestBody String notifyData,
@RequestHeader HttpHeaders headers
) throws WxPayException {
SignatureHeader signatureHeader = WxPayUtils.getSignatureHeader(headers);
orderService.handleWxPayOrderNotify(signatureHeader, notifyData);
return new WxPayResult()
.setCode(WxPayConstants.ResultCode.SUCCESS)
.setMessage("成功");
}
@Operation(summary = "微信退款结果回调")
@PostMapping("/notify/refund")
public WxPayResult wxPayRefundNotify(
@Parameter(description = "加密数据") @RequestBody String notifyData,
@Parameter(description = "请求头") @RequestHeader HttpHeaders headers
) throws WxPayException {
SignatureHeader signatureHeader = WxPayUtils.getSignatureHeader(headers);
orderService.handleWxPayRefundNotify(signatureHeader, notifyData);
return new WxPayResult()
.setCode(WxPayConstants.ResultCode.SUCCESS)
.setMessage("成功");
}
}

View File

@ -1,16 +1,16 @@
package com.youlai.mall.oms.controller.admin;
package com.youlai.mall.order.controller.admin;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import com.youlai.mall.oms.model.dto.OrderDTO;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.entity.OmsOrderItem;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OmsOrderPageVO;
import com.youlai.mall.oms.service.admin.OmsOrderService;
import com.youlai.mall.oms.service.app.OrderItemService;
import com.youlai.mall.order.model.dto.OrderDTO;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.entity.OmsOrderItem;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OmsOrderPageVO;
import com.youlai.mall.order.service.admin.OmsOrderService;
import com.youlai.mall.order.service.app.OrderItemService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -34,7 +34,7 @@ import java.util.Optional;
@RestController
@RequestMapping("/api/v1/orders")
@RequiredArgsConstructor
public class OrderController {
public class AdminOrderController {
private final OmsOrderService orderService;

View File

@ -1,11 +1,11 @@
package com.youlai.mall.oms.converter;
package com.youlai.mall.order.converter;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.oms.model.bo.OrderBO;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.form.OrderSubmitForm;
import com.youlai.mall.oms.model.vo.OmsOrderPageVO;
import com.youlai.mall.oms.model.vo.OrderPageVO;
import com.youlai.mall.order.model.bo.OrderBO;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.form.OrderSubmitForm;
import com.youlai.mall.order.model.vo.OmsOrderPageVO;
import com.youlai.mall.order.model.vo.OrderPageVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
@ -33,15 +33,15 @@ public interface OrderConverter {
@Mappings({
@Mapping(
target = "paymentMethodLabel",
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getPaymentMethod(), com.youlai.mall.oms.enums.PaymentMethodEnum.class))"
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getPaymentMethod(), com.youlai.mall.order.enums.PaymentMethodEnum.class))"
),
@Mapping(
target = "sourceLabel",
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getSource(), com.youlai.mall.oms.enums.OrderSourceEnum.class))"
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getSource(), com.youlai.mall.order.enums.OrderSourceEnum.class))"
),
@Mapping(
target = "statusLabel",
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getStatus(), com.youlai.mall.oms.enums.OrderStatusEnum.class))"
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getStatus(), com.youlai.mall.order.enums.OrderStatusEnum.class))"
),
@Mapping(
target = "orderItems",
@ -58,15 +58,15 @@ public interface OrderConverter {
@Mappings({
@Mapping(
target = "paymentMethodLabel",
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getPaymentMethod(), com.youlai.mall.oms.enums.PaymentMethodEnum.class))"
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getPaymentMethod(), com.youlai.mall.order.enums.PaymentMethodEnum.class))"
),
@Mapping(
target = "sourceLabel",
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getSource(), com.youlai.mall.oms.enums.OrderSourceEnum.class))"
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getSource(), com.youlai.mall.order.enums.OrderSourceEnum.class))"
),
@Mapping(
target = "statusLabel",
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getStatus(), com.youlai.mall.oms.enums.OrderStatusEnum.class))"
expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(bo.getStatus(), com.youlai.mall.order.enums.OrderStatusEnum.class))"
),
@Mapping(
target = "orderItems",

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.enums;
package com.youlai.mall.order.enums;
import com.youlai.common.base.IBaseEnum;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.enums;
package com.youlai.mall.order.enums;
import com.youlai.common.base.IBaseEnum;
import lombok.Getter;
@ -6,11 +6,12 @@ import lombok.Getter;
/**
* 订单状态枚举
*
* @author haoxr
* @author Ray Hao
* @since 2.0.0
*/
@Getter
public enum OrderStatusEnum implements IBaseEnum<Integer> {
PENDING_PAYMENT(0, "待支付"),
PENDING_SHIPMENT(1, "待发货"),
PENDING_RECEIPT(2, "待收货"),

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.enums;
package com.youlai.mall.order.enums;
import com.youlai.common.base.IBaseEnum;

View File

@ -1,8 +1,8 @@
package com.youlai.mall.oms.listener;
package com.youlai.mall.order.listener;
import com.rabbitmq.client.Channel;
import com.youlai.common.rabbitmq.constant.RabbitMqConstants;
import com.youlai.mall.oms.service.app.OrderService;
import com.youlai.mall.order.service.app.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.mapper;
package com.youlai.mall.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.oms.model.entity.OmsOrderDelivery;
import com.youlai.mall.order.model.entity.OmsOrderDelivery;
import org.apache.ibatis.annotations.Mapper;
/**

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.mapper;
package com.youlai.mall.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.oms.model.entity.OmsOrderItem;
import com.youlai.mall.order.model.entity.OmsOrderItem;
import org.apache.ibatis.annotations.Mapper;
/**

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.mapper;
package com.youlai.mall.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.oms.model.entity.OmsOrderLog;
import com.youlai.mall.order.model.entity.OmsOrderLog;
import org.apache.ibatis.annotations.Mapper;
/**

View File

@ -1,10 +1,10 @@
package com.youlai.mall.oms.mapper;
package com.youlai.mall.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.oms.model.bo.OrderBO;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.order.model.bo.OrderBO;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.query.OrderPageQuery;
import org.apache.ibatis.annotations.Mapper;
/**

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.mapper;
package com.youlai.mall.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.oms.model.entity.OmsOrderPay;
import com.youlai.mall.order.model.entity.OmsOrderPay;
import org.apache.ibatis.annotations.Mapper;
/**

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.mapper;
package com.youlai.mall.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.oms.model.entity.OmsOrderSetting;
import com.youlai.mall.order.model.entity.OmsOrderSetting;
import org.apache.ibatis.annotations.Mapper;
/**

View File

@ -1,9 +1,9 @@
package com.youlai.mall.oms.model.bo;
package com.youlai.mall.order.model.bo;
import com.youlai.common.base.BaseEntity;
import com.youlai.mall.oms.enums.OrderSourceEnum;
import com.youlai.mall.oms.enums.OrderStatusEnum;
import com.youlai.mall.oms.enums.PaymentMethodEnum;
import com.youlai.mall.order.enums.OrderSourceEnum;
import com.youlai.mall.order.enums.OrderStatusEnum;
import com.youlai.mall.order.enums.PaymentMethodEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.model.dto;
package com.youlai.mall.order.model.dto;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.entity.OmsOrderItem;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.entity.OmsOrderItem;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.dto;
package com.youlai.mall.order.model.dto;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.entity;
package com.youlai.mall.order.model.entity;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.IdType;
@ -27,7 +27,7 @@ public class OmsOrder extends BaseEntity {
/**
* 订单号
*/
private String orderSn;
private String orderNo;
/**
* 订单总额
*/
@ -80,7 +80,7 @@ public class OmsOrder extends BaseEntity {
/**
* 商户订单号
*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String outTradeNo;
/**
* 微信支付订单号

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.entity;
package com.youlai.mall.order.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.entity;
package com.youlai.mall.order.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.entity;
package com.youlai.mall.order.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.entity;
package com.youlai.mall.order.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.entity;
package com.youlai.mall.order.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

View File

@ -1,8 +1,7 @@
package com.youlai.mall.oms.model.form;
package com.youlai.mall.order.model.form;
import com.youlai.mall.oms.enums.PaymentMethodEnum;
import com.youlai.mall.order.enums.PaymentMethodEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
@ -13,10 +12,10 @@ import lombok.Data;
*/
@Data
@Schema(description ="订单支付表单对象")
public class OrderPaymentForm {
public class OrderPayForm {
@Schema(description="订单编号")
private String orderSn;
private String orderNo;
@Schema(description="小程序 AppId")
String appId;

View File

@ -1,8 +1,7 @@
package com.youlai.mall.oms.model.form;
package com.youlai.mall.order.model.form;
import com.youlai.mall.oms.enums.OrderSourceEnum;
import com.youlai.mall.order.enums.OrderSourceEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;

View File

@ -1,8 +1,7 @@
package com.youlai.mall.oms.model.query;
package com.youlai.mall.order.model.query;
import com.youlai.common.base.BasePageQuery;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

View File

@ -1,15 +1,18 @@
package com.youlai.mall.oms.model.vo;
package com.youlai.mall.order.model.result;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author Gadfly
* @since 2021-06-04 15:18
*
*
* @author Ray Hao
* @since 2021-06-04
*/
@Data
@Accessors(chain = true)
public class WxPayResponseVO {
public class WxPayResult {
private String code;
private String message;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.model.vo;
package com.youlai.mall.order.model.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;

View File

@ -1,6 +1,6 @@
package com.youlai.mall.oms.model.vo;
package com.youlai.mall.order.model.vo;
import com.youlai.mall.oms.model.dto.OrderItemDTO;
import com.youlai.mall.order.model.dto.OrderItemDTO;
import com.youlai.mall.ums.dto.MemberAddressDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -1,8 +1,7 @@
package com.youlai.mall.oms.model.vo;
package com.youlai.mall.order.model.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;

View File

@ -1,10 +1,10 @@
package com.youlai.mall.oms.service.admin;
package com.youlai.mall.order.service.admin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OmsOrderPageVO;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OmsOrderPageVO;
/**
* Admin-订单业务接口

View File

@ -1,15 +1,15 @@
package com.youlai.mall.oms.service.admin.impl;
package com.youlai.mall.order.service.admin.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.oms.converter.OrderConverter;
import com.youlai.mall.oms.mapper.OrderMapper;
import com.youlai.mall.oms.model.bo.OrderBO;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OmsOrderPageVO;
import com.youlai.mall.oms.service.admin.OmsOrderService;
import com.youlai.mall.order.converter.OrderConverter;
import com.youlai.mall.order.mapper.OrderMapper;
import com.youlai.mall.order.model.bo.OrderBO;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OmsOrderPageVO;
import com.youlai.mall.order.service.admin.OmsOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.service.app;
package com.youlai.mall.order.service.app;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.oms.model.entity.OmsOrderDelivery;
import com.youlai.mall.order.model.entity.OmsOrderDelivery;
/**
* 订单物流记录表

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.service.app;
package com.youlai.mall.order.service.app;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.oms.model.entity.OmsOrderItem;
import com.youlai.mall.order.model.entity.OmsOrderItem;
/**

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.service.app;
package com.youlai.mall.order.service.app;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.oms.model.entity.OmsOrderLog;
import com.youlai.mall.order.model.entity.OmsOrderLog;
/**
* 订单操作历史记录

View File

@ -1,15 +1,15 @@
package com.youlai.mall.oms.service.app;
package com.youlai.mall.order.service.app;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.form.OrderPaymentForm;
import com.youlai.mall.oms.model.form.OrderSubmitForm;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OrderConfirmVO;
import com.youlai.mall.oms.model.vo.OrderPageVO;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.form.OrderPayForm;
import com.youlai.mall.order.model.form.OrderSubmitForm;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OrderConfirmVO;
import com.youlai.mall.order.model.vo.OrderPageVO;
/**
* 订单业务接口
@ -41,7 +41,7 @@ public interface OrderService extends IService<OmsOrder> {
/**
* 订单支付
*/
<T> T payOrder(OrderPaymentForm paymentForm);
<T> T payOrder(OrderPayForm paymentForm);
/**
* 系统关闭订单

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.service.app;
package com.youlai.mall.order.service.app;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.oms.model.entity.OmsOrderSetting;
import com.youlai.mall.order.model.entity.OmsOrderSetting;
/**
* 订单配置信息

View File

@ -1,9 +1,9 @@
package com.youlai.mall.oms.service.app.impl;
package com.youlai.mall.order.service.app.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.oms.mapper.OrderDeliveryMapper;
import com.youlai.mall.oms.model.entity.OmsOrderDelivery;
import com.youlai.mall.oms.service.app.OrderDeliveryService;
import com.youlai.mall.order.mapper.OrderDeliveryMapper;
import com.youlai.mall.order.model.entity.OmsOrderDelivery;
import com.youlai.mall.order.service.app.OrderDeliveryService;
import org.springframework.stereotype.Service;
@Service("orderDeliveryService")

View File

@ -1,9 +1,9 @@
package com.youlai.mall.oms.service.app.impl;
package com.youlai.mall.order.service.app.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.oms.mapper.OrderItemMapper;
import com.youlai.mall.oms.model.entity.OmsOrderItem;
import com.youlai.mall.oms.service.app.OrderItemService;
import com.youlai.mall.order.mapper.OrderItemMapper;
import com.youlai.mall.order.model.entity.OmsOrderItem;
import com.youlai.mall.order.service.app.OrderItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

View File

@ -1,10 +1,10 @@
package com.youlai.mall.oms.service.app.impl;
package com.youlai.mall.order.service.app.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.security.util.SecurityUtils;
import com.youlai.mall.oms.mapper.OrderLogMapper;
import com.youlai.mall.oms.model.entity.OmsOrderLog;
import com.youlai.mall.oms.service.app.OrderLogService;
import com.youlai.mall.order.mapper.OrderLogMapper;
import com.youlai.mall.order.model.entity.OmsOrderLog;
import com.youlai.mall.order.service.app.OrderLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.service.app.impl;
package com.youlai.mall.order.service.app.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
@ -24,22 +24,22 @@ import com.youlai.common.constant.RedisConstants;
import com.youlai.common.rabbitmq.constant.RabbitMqConstants;
import com.youlai.common.security.util.SecurityUtils;
import com.youlai.common.web.exception.BizException;
import com.youlai.mall.oms.config.property.WechatPayProperties;
import com.youlai.mall.oms.converter.OrderConverter;
import com.youlai.mall.oms.enums.OrderStatusEnum;
import com.youlai.mall.oms.enums.PaymentMethodEnum;
import com.youlai.mall.oms.mapper.OrderMapper;
import com.youlai.mall.oms.model.bo.OrderBO;
import com.youlai.mall.oms.model.dto.OrderItemDTO;
import com.youlai.mall.oms.model.entity.OmsOrder;
import com.youlai.mall.oms.model.entity.OmsOrderItem;
import com.youlai.mall.oms.model.form.OrderPaymentForm;
import com.youlai.mall.oms.model.form.OrderSubmitForm;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OrderConfirmVO;
import com.youlai.mall.oms.model.vo.OrderPageVO;
import com.youlai.mall.oms.service.app.OrderItemService;
import com.youlai.mall.oms.service.app.OrderService;
import com.youlai.mall.order.config.property.WxPayProperties;
import com.youlai.mall.order.converter.OrderConverter;
import com.youlai.mall.order.enums.OrderStatusEnum;
import com.youlai.mall.order.enums.PaymentMethodEnum;
import com.youlai.mall.order.mapper.OrderMapper;
import com.youlai.mall.order.model.bo.OrderBO;
import com.youlai.mall.order.model.dto.OrderItemDTO;
import com.youlai.mall.order.model.entity.OmsOrder;
import com.youlai.mall.order.model.entity.OmsOrderItem;
import com.youlai.mall.order.model.form.OrderPayForm;
import com.youlai.mall.order.model.form.OrderSubmitForm;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OrderConfirmVO;
import com.youlai.mall.order.model.vo.OrderPageVO;
import com.youlai.mall.order.service.app.OrderItemService;
import com.youlai.mall.order.service.app.OrderService;
import com.youlai.mall.product.api.SkuFeignClient;
import com.youlai.mall.product.model.dto.LockSkuDTO;
import com.youlai.mall.product.model.dto.SkuDTO;
@ -78,7 +78,7 @@ import java.util.stream.Collectors;
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> implements OrderService {
private final WechatPayProperties wechatPayProperties;
private final WxPayProperties wxPayProperties;
private final OrderItemService orderItemService;
private final RabbitTemplate rabbitTemplate;
private final StringRedisTemplate redisTemplate;
@ -255,21 +255,21 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
*/
@Override
@GlobalTransactional
public <T> T payOrder(OrderPaymentForm paymentForm) {
String orderSn = paymentForm.getOrderSn();
public <T> T payOrder(OrderPayForm paymentForm) {
String orderNo = paymentForm.getOrderNo();
OmsOrder order = this.getOne(new LambdaQueryWrapper<OmsOrder>()
.eq(OmsOrder::getOrderSn, orderSn)
.eq(OmsOrder::getOrderNo, orderNo)
);
Assert.isTrue(order != null && OrderStatusEnum.PENDING_PAYMENT.getValue().equals(order.getStatus()),
"订单不存在或已支付");
RLock lock = redissonClient.getLock(RedisConstants.ORDER_PAYMENT_LOCK_PREFIX + order.getOrderSn());
RLock lock = redissonClient.getLock(RedisConstants.ORDER_PAYMENT_LOCK_PREFIX + order.getOrderNo());
try {
lock.lock();
T result;
switch (paymentForm.getPaymentMethod()) {
case WX_JSAPI:
result = (T) wxJsapiPay(paymentForm.getAppId(), order.getOrderSn(), order.getPaymentAmount());
result = (T) wxJsapiPay(paymentForm.getAppId(), order.getOrderNo(), order.getPaymentAmount());
break;
default:
result = (T) balancePay(order);
@ -297,7 +297,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
Assert.isTrue(balanceDeducted, "订单支付失败:余额扣减失败!");
// 扣减库存
boolean stockDeducted = skuFeignClient.deductStock(order.getOrderSn());
boolean stockDeducted = skuFeignClient.deductStock(order.getOrderNo());
Assert.isTrue(stockDeducted, "订单支付失败:库存扣减失败!");
// 更新订单状态
@ -308,7 +308,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
if (result) {
// 支付成功删除购物车已勾选的商品
rabbitTemplate
.convertAndSend(RabbitMqConstants.CART_EXCHANGE, RabbitMqConstants.CART_REMOVE_ROUTING_KEY, order.getOrderSn());
.convertAndSend(RabbitMqConstants.CART_EXCHANGE, RabbitMqConstants.CART_REMOVE_ROUTING_KEY, order.getOrderNo());
}
return result;
}
@ -318,16 +318,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
* 微信支付调起
*
* @param appId 微信小程序ID
* @param orderSn 订单编号
* @param orderNo 订单编号
* @param paymentAmount 支付金额
* @return 微信支付调起参数
*/
private WxPayUnifiedOrderV3Result.JsapiResult wxJsapiPay(String appId, String orderSn, Long paymentAmount) {
private WxPayUnifiedOrderV3Result.JsapiResult wxJsapiPay(String appId, String orderNo, Long paymentAmount) {
Long memberId = SecurityUtils.getMemberId();
// 如果已经有outTradeNo了就先进行关单
if (StrUtil.isNotBlank(orderSn)) {
if (StrUtil.isNotBlank(orderNo)) {
try {
wxPayService.closeOrderV3(orderSn);
wxPayService.closeOrderV3(orderNo);
} catch (WxPayException e) {
log.error(e.getMessage(), e);
throw new BizException("微信关单异常");
@ -337,14 +337,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
// 更新订单状态
boolean result = this.update(new LambdaUpdateWrapper<OmsOrder>()
.set(OmsOrder::getPaymentMethod, PaymentMethodEnum.WX_JSAPI.getValue())
.eq(OmsOrder::getOrderSn, orderSn)
.eq(OmsOrder::getOrderNo, orderNo)
);
String openId = memberFeignClient.getMemberOpenId(memberId);
WxPayUnifiedOrderV3Request wxRequest = new WxPayUnifiedOrderV3Request()
.setAppid(appId)
.setOutTradeNo(orderSn)
.setOutTradeNo(orderNo)
.setAmount(new WxPayUnifiedOrderV3Request
.Amount()
.setTotal(Math.toIntExact(paymentAmount))
@ -353,8 +353,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
new WxPayUnifiedOrderV3Request.Payer()
.setOpenid(openId)
)
.setDescription("赅买-订单编号:" + orderSn)
.setNotifyUrl(wechatPayProperties.getPayNotifyUrl());
.setDescription("赅买-订单编号:" + orderNo)
.setNotifyUrl(wxPayProperties.getNotifyUrl());
WxPayUnifiedOrderV3Result.JsapiResult jsapiResult;
try {
jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxRequest);
@ -368,14 +368,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
/**
* 关闭订单
*
* @param orderSn 订单编号
* @param orderNo 订单编号
* @return 是否成功 true|false
*/
@Override
public boolean closeOrder(String orderSn) {
public boolean closeOrder(String orderNo) {
return this.update(new LambdaUpdateWrapper<OmsOrder>()
.eq(OmsOrder::getOrderSn, orderSn)
.eq(OmsOrder::getOrderNo, orderNo)
.eq(OmsOrder::getStatus, OrderStatusEnum.PENDING_PAYMENT.getValue())
.set(OmsOrder::getStatus, OrderStatusEnum.CANCELLED.getValue())
);
@ -406,24 +406,28 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
public void handleWxPayOrderNotify(SignatureHeader signatureHeader, String notifyData) throws WxPayException {
log.info("开始处理支付结果通知");
// 解密支付通知内容
final WxPayOrderNotifyV3Result.DecryptNotifyResult result = this.wxPayService.parseOrderNotifyV3Result(notifyData, signatureHeader).getResult();
log.debug("支付通知解密成功:[{}]", result.toString());
final WxPayOrderNotifyV3Result.DecryptNotifyResult result = this.wxPayService.parseOrderNotifyV3Result(
notifyData,
signatureHeader
).getResult();
log.debug("支付通知解密成功:{}", JSONUtil.toJsonStr(result));
// 根据商户订单号查询订单
OmsOrder orderDO = this.getOne(new LambdaQueryWrapper<OmsOrder>()
OmsOrder order = this.getOne(new LambdaQueryWrapper<OmsOrder>()
.eq(OmsOrder::getOutTradeNo, result.getOutTradeNo())
);
// 支付成功处理
if (WxPayConstants.WxpayTradeStatus.SUCCESS.equals(result.getTradeState())) {
orderDO.setStatus(OrderStatusEnum.PENDING_SHIPMENT.getValue());
orderDO.setTransactionId(result.getTransactionId());
orderDO.setPaymentTime(new Date());
this.updateById(orderDO);
order.setStatus(OrderStatusEnum.PENDING_SHIPMENT.getValue());
order.setTransactionId(result.getTransactionId());
order.setPaymentTime(new Date());
this.updateById(order);
}
log.info("账单更新成功");
// 支付成功删除购物车已勾选的商品
rabbitTemplate
.convertAndSend(RabbitMqConstants.CART_EXCHANGE, RabbitMqConstants.CART_REMOVE_ROUTING_KEY, orderDO.getOrderSn());
.convertAndSend(RabbitMqConstants.CART_EXCHANGE, RabbitMqConstants.CART_REMOVE_ROUTING_KEY, order.getOrderNo());
}
@Override
@ -477,12 +481,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
}
String skuSpecValue="";
String skuSpecValue = "";
return orderItems;
}
/**

View File

@ -1,9 +1,9 @@
package com.youlai.mall.oms.service.app.impl;
package com.youlai.mall.order.service.app.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.oms.mapper.OrderSettingMapper;
import com.youlai.mall.oms.model.entity.OmsOrderSetting;
import com.youlai.mall.oms.service.app.OrderSettingService;
import com.youlai.mall.order.mapper.OrderSettingMapper;
import com.youlai.mall.order.model.entity.OmsOrderSetting;
import com.youlai.mall.order.service.app.OrderSettingService;
import org.springframework.stereotype.Service;

View File

@ -0,0 +1,32 @@
package com.youlai.mall.order.util;
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
import org.springframework.http.HttpHeaders;
/**
* 微信支付工具类
*
* @author Rya Hao
* @since 2024/6/6
*/
public class WxPayUtils {
private WxPayUtils() {
// 私有构造方法防止实例化
}
/**
* HttpHeaders 中提取微信支付签名相关的头信息并封装为 SignatureHeader 对象
*
* @param headers 包含微信支付签名头信息的 HttpHeaders 对象
* @return SignatureHeader 对象
*/
public static SignatureHeader getSignatureHeader(HttpHeaders headers) {
SignatureHeader signatureHeader = new SignatureHeader();
signatureHeader.setSignature(headers.getFirst("Wechatpay-Signature"));
signatureHeader.setSerial(headers.getFirst("Wechatpay-Serial"));
signatureHeader.setTimeStamp(headers.getFirst("Wechatpay-Timestamp"));
signatureHeader.setNonce(headers.getFirst("Wechatpay-Nonce"));
return signatureHeader;
}
}

View File

@ -5,7 +5,7 @@
<mapper namespace="com.youlai.mall.oms.mapper.OrderItemMapper">
<!-- 根据订单ID获取订单商品列表 -->
<select id="getOrderItemsByOrderId" resultType="com.youlai.mall.oms.model.bo.OrderBO$OrderItem">
<select id="getOrderItemsByOrderId" resultType="com.youlai.mall.order.model.bo.OrderBO$OrderItem">
SELECT
id,
order_id,

View File

@ -4,10 +4,10 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.mall.oms.mapper.OrderMapper">
<resultMap id="OrderMap" type="com.youlai.mall.oms.model.bo.OrderBO">
<resultMap id="OrderMap" type="com.youlai.mall.order.model.bo.OrderBO">
<collection property="orderItems"
column="{orderId=id}"
select="com.youlai.mall.oms.mapper.OrderItemMapper.getOrderItemsByOrderId">
select="com.youlai.mall.order.mapper.OrderItemMapper.getOrderItemsByOrderId">
</collection>
</resultMap>

View File

@ -1,12 +1,12 @@
package com.youlai.mall.oms.controller;
package com.youlai.mall.order.controller;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.youlai.mall.oms.enums.OrderSourceEnum;
import com.youlai.mall.oms.enums.PaymentMethodEnum;
import com.youlai.mall.oms.model.form.OrderPaymentForm;
import com.youlai.mall.oms.model.form.OrderSubmitForm;
import com.youlai.mall.order.enums.OrderSourceEnum;
import com.youlai.mall.order.enums.PaymentMethodEnum;
import com.youlai.mall.order.model.form.OrderPayForm;
import com.youlai.mall.order.model.form.OrderSubmitForm;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -38,7 +38,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest
@AutoConfigureMockMvc
@Slf4j
public class AppOrderControllerTest {
public class OrderControllerTest {
@Autowired
@ -146,7 +146,7 @@ public class AppOrderControllerTest {
orderItem.setSkuId(skuId);
orderItem.setSkuQuantity(1);
orderItem.setSkuName("REDMI K60 16G+1T");
orderItem.setSkuSn("sn001");
orderItem.setSkuCode("sn001");
orderItem.setSpuName("REDMI K60");
orderItem.setSkuPrice(399900L);
orderItem.setImgUrl("https://www.youlai.tech/files/default/c25b39470474494485633c49101a0f5d.png");
@ -188,7 +188,7 @@ public class AppOrderControllerTest {
*/
private void payOrder(String orderSn, HttpHeaders headers) throws Exception {
OrderPaymentForm paymentForm = new OrderPaymentForm();
OrderPayForm paymentForm = new OrderPayForm();
paymentForm.setOrderSn(orderSn);
paymentForm.setPaymentMethod(PaymentMethodEnum.BALANCE);
mockMvc.perform(post("/app-api/v1/orders/payment")

View File

@ -1,11 +1,11 @@
package com.youlai.mall.oms.service.impl;
package com.youlai.mall.order.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OmsOrderPageVO;
import com.youlai.mall.oms.service.admin.OmsOrderService;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OmsOrderPageVO;
import com.youlai.mall.order.service.admin.OmsOrderService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,11 +1,11 @@
package com.youlai.mall.oms.service.impl;
package com.youlai.mall.order.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.mall.oms.model.query.OrderPageQuery;
import com.youlai.mall.oms.model.vo.OrderPageVO;
import com.youlai.mall.oms.service.app.OrderService;
import com.youlai.mall.order.model.query.OrderPageQuery;
import com.youlai.mall.order.model.vo.OrderPageVO;
import com.youlai.mall.order.service.app.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,6 +1,5 @@
package com.youlai.mall.product.controller.admin;
import com.youlai.common.web.model.Option;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -28,7 +27,7 @@ import jakarta.validation.Valid;
@RestController
@RequestMapping("/api/v1/attributes")
@RequiredArgsConstructor
public class AttributeController {
public class PmsAttributeController {
private final AttributeService attributeService;

View File

@ -28,7 +28,7 @@ import java.util.List;
@RestController
@RequestMapping("/api/v1/attribute-groups")
@RequiredArgsConstructor
public class AttributeGroupController {
public class PmsAttributeGroupController {
private final AttributeGroupService attributeGroupService;

View File

@ -28,7 +28,7 @@ import java.util.List;
@RestController
@RequestMapping("/api/v1/brands")
@RequiredArgsConstructor
public class BrandController {
public class PmsBrandController {
private final BrandService brandService;

View File

@ -2,7 +2,6 @@ package com.youlai.mall.product.controller.admin;
import com.youlai.common.result.Result;
import com.youlai.common.web.model.Option;
import com.youlai.mall.product.enums.AttributeTypeEnum;
import com.youlai.mall.product.model.form.CategoryForm;
import com.youlai.mall.product.model.vo.CategoryVO;
import com.youlai.mall.product.service.CategoryService;
@ -25,7 +24,7 @@ import java.util.List;
@RestController
@RequestMapping("/api/v1/categories")
@RequiredArgsConstructor
public class CategoryController {
public class PmsCategoryController {
private final CategoryService categoryService;

View File

@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/v1/spu")
@RequiredArgsConstructor
public class SpuController {
public class PmsSpuController {
private final SpuService spuService;

View File

@ -22,7 +22,7 @@ import java.util.List;
@RestController
@RequestMapping("/app-api/v1/categories")
@RequiredArgsConstructor
public class AppCategoryController {
public class CategoryController {
private final CategoryService categoryService;

View File

@ -4,8 +4,10 @@ package com.youlai.mall.product.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 属性 DTO
*
@ -19,35 +21,27 @@ public class AttributeDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "属性主键")
@Schema(description = "属性主键")
private Long id;
private Long id;
@Schema(description = "属性组主键")
private Long attributeGroupId;
@Schema(description = "属性组主键")
@Schema(description = "属性名称")
private String name;
private Long attributeGroupId;
@Schema(description = "输入录入方式1-手动输入2-从列表选择")
private Integer inputType;
@Schema(description = "属性名称")
@Schema(description = "逗号分割的可选值列表仅当input_type是2使用")
private String options;
private String name;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "输入录入方式1-手动输入2-从列表选择")
@Schema(description = "更新时间")
private LocalDateTime updateTime;
private Integer inputType;
@Schema(description = "逗号分割的可选值列表仅当input_type是2使用")
private String options;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
@Schema(description = "逻辑删除标识(0-未删除1-已删除)")
private Integer isDeleted;;
@Schema(description = "逻辑删除标识(0-未删除1-已删除)")
private Integer isDeleted;
}

View File

@ -4,8 +4,10 @@ package com.youlai.mall.product.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 品牌分类关联 DTO
*
@ -14,28 +16,27 @@ import java.time.LocalDateTime;
*/
@Getter
@Setter
@Schema( description = "品牌分类关联传输层对象")
@Schema(description = "品牌分类关联传输层对象")
public class BrandCategoryDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "主键")
@Schema(description = "主键")
private Long id;
private Long id;
@Schema(description = "分类ID")
@Schema(description = "分类ID")
private Long categoryId;
private Long categoryId;
@Schema(description = "品牌ID")
@Schema(description = "品牌ID")
private Long brandId;
private Long brandId;
@Schema(description = "创建时间")
@Schema(description = "创建时间")
private LocalDateTime createTime;
private LocalDateTime createTime;
@Schema(description = "创建人ID")
@Schema(description = "创建人ID")
private Long createBy;
private Long createBy;
}

View File

@ -40,15 +40,13 @@ public class ${entity}DTO {
#end
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
private ${field.propertyType} ${field.propertyName};
#end
## ---------- END 字段循环遍历 ----------
#if(!${entityLombokModel})