From 64a35eaf71681cf4dbc71092c7ab36a506991bdc Mon Sep 17 00:00:00 2001 From: wayn <1669738430@qq.com> Date: Sun, 15 Oct 2023 22:25:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=95=86=E5=9F=8E):=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wayn/common/core/domain/vo/OrderVO.java | 1 + .../shop/impl/AdminOrderServiceImpl.java | 12 -- .../com/wayn/common/enums/PayTypeEnum.java | 7 +- .../com/wayn/common/enums/ReturnCodeEnum.java | 1 + .../api/controller/OrderController.java | 5 - .../api/controller/OrderRefundController.java | 28 +++++ .../mobile/api/controller/PayController.java | 3 +- .../mobile/api/service/IOrderService.java | 12 -- .../wayn/mobile/api/service/IPayService.java | 33 ++++-- .../api/service/impl/OrderServiceImpl.java | 29 ----- .../api/service/impl/PayServiceImpl.java | 112 ++++++++++++++++-- .../wayn/mobile/api/util/OrderSnGenUtil.java | 17 ++- .../src/main/resources/application.yml | 6 +- 13 files changed, 175 insertions(+), 91 deletions(-) create mode 100644 waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderRefundController.java diff --git a/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/OrderVO.java b/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/OrderVO.java index 7cd731e..d682cdc 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/OrderVO.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/OrderVO.java @@ -31,4 +31,5 @@ public class OrderVO { * 支付方式 1微信 2支付宝 */ private Integer payType; + private String returnUrl; } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/AdminOrderServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/AdminOrderServiceImpl.java index b5b875c..83ab946 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/AdminOrderServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/AdminOrderServiceImpl.java @@ -102,15 +102,6 @@ public class AdminOrderServiceImpl extends ServiceImpl } } - // 返还优惠券 -// List couponUsers = couponUserService.findByOid(orderId); -// for (LitemallCouponUser couponUser: couponUsers) { -// // 优惠券状态设置为可使用 -// couponUser.setStatus(CouponUserConstant.STATUS_USABLE); -// couponUser.setUpdateTime(LocalDateTime.now()); -// couponUserService.update(couponUser); -// } - // 退款成功通知用户, 例如“您申请的订单退款 [ 单号:{1} ] 已成功,请耐心等待到账。” // 注意订单号只发后6位 String email = iMemberService.getById(order.getUserId()).getEmail(); @@ -118,7 +109,6 @@ public class AdminOrderServiceImpl extends ServiceImpl iMailService.sendEmail("订单已经退款", order.getOrderSn().substring(8, 14), email, WaynConfig.getAdminUrl() + "/callback/email"); } - // logHelper.logOrderSucceed("退款", "订单编号 " + order.getOrderSn()); return R.success(); } @@ -169,6 +159,4 @@ public class AdminOrderServiceImpl extends ServiceImpl data.put("user", member); return R.success().add("data", data); } - - } diff --git a/waynboot-common/src/main/java/com/wayn/common/enums/PayTypeEnum.java b/waynboot-common/src/main/java/com/wayn/common/enums/PayTypeEnum.java index fb46b6a..e912b69 100644 --- a/waynboot-common/src/main/java/com/wayn/common/enums/PayTypeEnum.java +++ b/waynboot-common/src/main/java/com/wayn/common/enums/PayTypeEnum.java @@ -1,8 +1,11 @@ package com.wayn.common.enums; +import lombok.Getter; + /** * 支付方式枚举 */ +@Getter public enum PayTypeEnum { // 微信 WX(1), @@ -17,10 +20,6 @@ public enum PayTypeEnum { this.code = code; } - public int getCode() { - return code; - } - public static PayTypeEnum of(int code) { for (PayTypeEnum value : PayTypeEnum.values()) { if (code == value.getCode()) { diff --git a/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java b/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java index 2a0eada..9b2ec39 100644 --- a/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java +++ b/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java @@ -43,6 +43,7 @@ public enum ReturnCodeEnum { ORDER_USER_NOT_SAME_ERROR(5012, "订单用户和当前登陆用户不一致"), ORDER_ERROR_CART_EMPTY_ERROR(5013, "下单失败,当前购物车无数据"), ORDER_ERROR_ADDRESS_ERROR(50143, "下单失败,当前地址错误"), + ORDER_REFUND_ERROR(50144, "退款失败"), // 用户错误 USER_NOT_EXISTS_ERROR(5101, "用户不存在"), diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderController.java index bfc5e22..e344651 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderController.java @@ -61,11 +61,6 @@ public class OrderController extends BaseController { return iOrderService.cancel(orderId); } - @PostMapping("refund/{orderId}") - public R refund(@PathVariable Long orderId) throws UnsupportedEncodingException { - return iOrderService.refund(orderId); - } - @PostMapping("confirm/{orderId}") public R confirm(@PathVariable Long orderId) { return iOrderService.confirm(orderId); diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderRefundController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderRefundController.java new file mode 100644 index 0000000..9fac596 --- /dev/null +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/OrderRefundController.java @@ -0,0 +1,28 @@ +package com.wayn.mobile.api.controller; + + +import com.alipay.api.AlipayApiException; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.wayn.common.base.controller.BaseController; +import com.wayn.common.core.domain.vo.OrderVO; +import com.wayn.common.util.R; +import com.wayn.mobile.api.service.IPayService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; + +@Slf4j +@RestController +@AllArgsConstructor +@RequestMapping("order/refund") +public class OrderRefundController extends BaseController { + + private IPayService payService; + + @PostMapping("{orderId}") + public R refund(@PathVariable Long orderId) throws UnsupportedEncodingException, AlipayApiException, WxPayException { + return payService.refund(orderId); + } +} diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/PayController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/PayController.java index 35bb7c8..46c2f40 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/PayController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/PayController.java @@ -4,7 +4,6 @@ package com.wayn.mobile.api.controller; import com.wayn.common.base.controller.BaseController; import com.wayn.common.core.domain.vo.OrderVO; import com.wayn.common.util.R; -import com.wayn.mobile.api.service.IOrderService; import com.wayn.mobile.api.service.IPayService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -42,7 +41,7 @@ public class PayController extends BaseController { */ @PostMapping("h5pay") public R h5pay(@RequestBody OrderVO orderVO) throws UnsupportedEncodingException { - return payService.h5pay(orderVO.getOrderSn(), orderVO.getPayType(), request); + return payService.h5pay(orderVO); } } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IOrderService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IOrderService.java index 42517ee..262423c 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IOrderService.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IOrderService.java @@ -67,18 +67,6 @@ public interface IOrderService extends IService { */ R cancel(Long orderId); - - /** - * 订单退款 - *

- * 1. 检测当前订单是否可以退款; - * 2. 更改订单状态为已退款。 - * - * @param orderId 订单ID - * @return r - */ - R refund(Long orderId) throws UnsupportedEncodingException; - /** * 删除订单 *

diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IPayService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IPayService.java index a51ba51..975608b 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IPayService.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IPayService.java @@ -1,12 +1,9 @@ package com.wayn.mobile.api.service; import com.alipay.api.AlipayApiException; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; -import com.wayn.common.core.domain.shop.Order; +import com.github.binarywang.wxpay.exception.WxPayException; import com.wayn.common.core.domain.vo.OrderVO; import com.wayn.common.util.R; -import com.wayn.message.core.dto.OrderDTO; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -20,15 +17,6 @@ import java.io.UnsupportedEncodingException; */ public interface IPayService { - /** - * 微信H5支付 - * - * @param orderSn 订单编号 - * @param request 请求 - * @return r - */ - R h5pay(String orderSn, Integer payType, HttpServletRequest request) throws UnsupportedEncodingException; - /** * 付款订单的预支付会话标识 *

@@ -42,6 +30,25 @@ public interface IPayService { */ R prepay(String orderSn, Integer payType, HttpServletRequest request); + /** + * 微信H5支付 + * + * @param orderVO 订单VO + * @return r + */ + R h5pay(OrderVO orderVO) throws UnsupportedEncodingException; + + /** + * 订单退款 + *

+ * 1. 检测当前订单是否可以退款; + * 2. 更改订单状态为已退款。 + * + * @param orderId 订单ID + * @return r + */ + R refund(Long orderId) throws UnsupportedEncodingException, AlipayApiException, WxPayException; + String wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException; String aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException, UnsupportedEncodingException; diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java index 12c4a62..65c9ef2 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java @@ -417,35 +417,6 @@ public class OrderServiceImpl extends ServiceImpl implements return R.success(); } - @Override - public R refund(Long orderId) throws UnsupportedEncodingException { - Order order = getById(orderId); - ReturnCodeEnum returnCodeEnum = checkOrderOperator(order); - if (!ReturnCodeEnum.SUCCESS.equals(returnCodeEnum)) { - return R.error(returnCodeEnum); - } - - OrderHandleOption handleOption = OrderUtil.build(order); - if (!handleOption.isRefund()) { - return R.error(ReturnCodeEnum.ORDER_CANNOT_REFUND_ERROR); - } - - // 设置订单申请退款状态 - order.setOrderStatus(OrderUtil.STATUS_REFUND); - order.setUpdateTime(new Date()); - updateById(order); - - // 有用户申请退款,邮件通知运营人员 - String email = iMemberService.getById(order.getUserId()).getEmail(); - if (StringUtils.isNotEmpty(email)) { - if (StringUtils.isNotBlank(email)) { - iMailService.sendEmail("订单正在退款", order.toString(), email, WaynConfig.getMobileUrl() + "/callback/email"); - } - } - - return R.success(); - } - @Override @Transactional(rollbackFor = Exception.class) public R delete(Long orderId) { diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/PayServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/PayServiceImpl.java index be4da8b..9bade55 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/PayServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/PayServiceImpl.java @@ -6,28 +6,37 @@ import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; import com.alipay.api.DefaultAlipayClient; import com.alipay.api.internal.util.AlipaySignature; +import com.alipay.api.request.AlipayTradeRefundRequest; import com.alipay.api.request.AlipayTradeWapPayRequest; +import com.alipay.api.response.AlipayTradeRefundResponse; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; +import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request; import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; +import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.wayn.common.config.AlipayConfig; import com.wayn.common.config.WaynConfig; -import com.wayn.common.core.domain.shop.*; -import com.wayn.common.core.service.shop.*; +import com.wayn.common.core.domain.shop.Member; +import com.wayn.common.core.domain.shop.Order; +import com.wayn.common.core.domain.vo.OrderVO; +import com.wayn.common.core.service.shop.IMailService; +import com.wayn.common.core.service.shop.IMemberService; import com.wayn.common.core.util.OrderHandleOption; import com.wayn.common.core.util.OrderUtil; import com.wayn.common.enums.PayTypeEnum; import com.wayn.common.enums.ReturnCodeEnum; import com.wayn.common.util.R; +import com.wayn.common.util.ServletUtils; import com.wayn.common.util.ip.IpUtils; import com.wayn.mobile.api.service.IOrderService; import com.wayn.mobile.api.service.IPayService; +import com.wayn.mobile.api.util.OrderSnGenUtil; import com.wayn.mobile.framework.security.util.MobileSecurityUtils; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -38,11 +47,13 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.IOException; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.util.*; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; /** * 订单表 服务实现类 @@ -60,6 +71,7 @@ public class PayServiceImpl implements IPayService { private AlipayConfig alipayConfig; private IOrderService orderService; private WxPayService wxPayService; + private OrderSnGenUtil orderSnGenUtil; @Override @Transactional(rollbackFor = Exception.class) @@ -88,7 +100,7 @@ public class PayServiceImpl implements IPayService { orderRequest.setOutTradeNo(order.getOrderSn()); orderRequest.setOpenid(openid); orderRequest.setBody("商城订单:" + order.getOrderSn()); - String url = WaynConfig.getMobileUrl() + request.getContextPath(); + String url = WaynConfig.getMobileUrl(); orderRequest.setNotifyUrl(url + "/pay/callback/weixinPayNotify"); // 元转成分 int fee; @@ -107,7 +119,9 @@ public class PayServiceImpl implements IPayService { @Override @Transactional(rollbackFor = Exception.class) - public R h5pay(String orderSn, Integer payType, HttpServletRequest request) throws UnsupportedEncodingException { + public R h5pay(OrderVO orderVO) throws UnsupportedEncodingException { + String orderSn = orderVO.getOrderSn(); + Integer payType = orderVO.getPayType(); // 获取订单详情 Order order = orderService.getOne(new QueryWrapper().eq("order_sn", orderSn)); Long userId = order.getUserId(); @@ -132,7 +146,7 @@ public class PayServiceImpl implements IPayService { WxPayMpOrderResult result; try { WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); - String url = WaynConfig.getMobileUrl() + request.getContextPath(); + String url = WaynConfig.getMobileUrl(); orderRequest.setOutTradeNo(order.getOrderSn()); orderRequest.setTradeType(WxPayConstants.TradeType.MWEB); orderRequest.setNotifyUrl(url + "/pay/callback/weixinPayNotify"); @@ -142,7 +156,7 @@ public class PayServiceImpl implements IPayService { BigDecimal actualPrice = order.getActualPrice(); fee = actualPrice.multiply(new BigDecimal(100)).intValue(); orderRequest.setTotalFee(fee); - orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(request)); + orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest())); result = wxPayService.createOrder(orderRequest); return R.success().add("result", result); @@ -159,8 +173,10 @@ public class PayServiceImpl implements IPayService { // 创建API对应的request,使用手机网站支付request AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest(); // 在公共参数中设置回跳和通知地址 - String url = WaynConfig.getMobileUrl() + request.getContextPath(); - alipayRequest.setReturnUrl(url + "/returnOrders/" + orderSn + "/" + userId); + String url = WaynConfig.getMobileUrl(); + if (StringUtils.isNotBlank(orderVO.getReturnUrl())) { + alipayRequest.setReturnUrl(orderVO.getReturnUrl()); + } alipayRequest.setNotifyUrl(url + "/pay/callback/aliPayNotify"); // 填充业务参数 @@ -190,6 +206,7 @@ public class PayServiceImpl implements IPayService { // 请求 String form; try { + log.info("alipayRequest:{}", JSON.toJSONString(alipayRequest)); // 需要自行申请支付宝的沙箱账号、申请appID,并在配置文件中依次配置AppID、密钥、公钥,否则这里会报错。 form = alipayClient.pageExecute(alipayRequest).getBody();// 调用SDK生成表单 return R.success().add("form", form); @@ -220,6 +237,81 @@ public class PayServiceImpl implements IPayService { } } + @Override + public R refund(Long orderId) throws UnsupportedEncodingException, AlipayApiException, WxPayException { + Order order = orderService.getById(orderId); + ReturnCodeEnum returnCodeEnum = orderService.checkOrderOperator(order); + if (!ReturnCodeEnum.SUCCESS.equals(returnCodeEnum)) { + return R.error(returnCodeEnum); + } + + OrderHandleOption handleOption = OrderUtil.build(order); + if (!handleOption.isRefund()) { + return R.error(ReturnCodeEnum.ORDER_CANNOT_REFUND_ERROR); + } + + // 设置订单申请退款状态 + order.setOrderStatus(OrderUtil.STATUS_REFUND); + order.setUpdateTime(new Date()); + if (!orderService.updateById(order)) { + return R.error(ReturnCodeEnum.ERROR); + } + Integer payType = order.getPayType(); + switch (Objects.requireNonNull(PayTypeEnum.of(payType))) { + case WX -> { + WxPayRefundV3Request refundV3Request = new WxPayRefundV3Request(); + String refundSn = orderSnGenUtil.generateRefundOrderSn(); + refundV3Request.setTransactionId(order.getPayId()); + refundV3Request.setOutRefundNo(refundSn); + refundV3Request.setReason("商城退款:refund:{}" + refundSn); + WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount(); + amount.setRefund(order.getActualPrice().multiply(new BigDecimal("100")).intValue()); + amount.setCurrency("CNY"); + amount.setTotal(order.getActualPrice().multiply(new BigDecimal("100")).intValue()); + refundV3Request.setAmount(amount); + WxPayRefundV3Result refundV3Result = wxPayService.refundV3(refundV3Request); + log.info("response:{}", JSON.toJSONString(refundV3Result)); + String status = refundV3Result.getStatus(); + if (!"SUCCESS".equals(status)) { + return R.error(ReturnCodeEnum.ORDER_REFUND_ERROR); + } + break; + } + case ALI -> { + AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig.getGateway(), alipayConfig.getAppId(), + alipayConfig.getRsaPrivateKey(), alipayConfig.getFormat(), alipayConfig.getCharset(), alipayConfig.getAlipayPublicKey(), + alipayConfig.getSigntype()); + AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); + JSONObject bizContent = new JSONObject(); + String refundSn = orderSnGenUtil.generateRefundOrderSn(); + bizContent.put("trade_no", order.getPayId()); + bizContent.put("refund_amount", order.getActualPrice()); + bizContent.put("out_request_no", refundSn); + bizContent.put("refund_reason", "商城退款:refund:{}" + refundSn); + + request.setBizContent(bizContent.toString()); + AlipayTradeRefundResponse response = alipayClient.execute(request); + log.info("response:{}", JSON.toJSONString(response)); + if (!response.isSuccess()) { + return R.error(ReturnCodeEnum.ORDER_REFUND_ERROR); + } + break; + } + default -> { + } + } + + // 有用户申请退款,邮件通知运营人员 + String email = iMemberService.getById(order.getUserId()).getEmail(); + if (StringUtils.isNotEmpty(email)) { + if (StringUtils.isNotBlank(email)) { + iMailService.sendEmail("订单正在退款", order.toString(), email, WaynConfig.getMobileUrl() + "/callback/email"); + } + } + return R.success(); + } + + @Override public String wxPayNotify(HttpServletRequest request, HttpServletResponse response) { try { diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/util/OrderSnGenUtil.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/util/OrderSnGenUtil.java index 9cf2fc3..ef753b7 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/util/OrderSnGenUtil.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/util/OrderSnGenUtil.java @@ -21,7 +21,7 @@ public class OrderSnGenUtil { private RedisCache redisCache; /** - * 返回订单编号,生成规则:秒级时间戳 + 加密用户ID + 今日第几次下单 + * 返回订单编号,生成规则:秒级时间戳 + 递增id * * @return 订单编号 */ @@ -34,4 +34,19 @@ public class OrderSnGenUtil { } return now + String.format("%06d", incrKey); } + + /** + * 返回退款订单编号,生成规则:秒级时间戳 + 递增id + * + * @return 订单编号 + */ + public String generateRefundOrderSn() { + long now = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); + Integer orderSnIncrLimit = Constants.ORDER_SN_INCR_LIMIT; + Long incrKey = redisCache.luaIncrKey(CacheConstants.ORDER_SN_INCR_KEY, orderSnIncrLimit); + if (incrKey > (long) orderSnIncrLimit) { + throw new BusinessException("订单编号生成失败"); + } + return "RE" + now + String.format("%06d", incrKey); + } } diff --git a/waynboot-mobile-api/src/main/resources/application.yml b/waynboot-mobile-api/src/main/resources/application.yml index e90ae10..9421e4f 100644 --- a/waynboot-mobile-api/src/main/resources/application.yml +++ b/waynboot-mobile-api/src/main/resources/application.yml @@ -61,8 +61,8 @@ wayn: version: 1.3.0 email: 166738430@qq.com uploadDir: ${UPLOAD_DIR:D:/waynshop/webp} - adminUrl: http://localhost:81 - mobileUrl: http://localhost:82 + adminUrl: ${ADMIN_URL:http://localhost:81} + mobileUrl: ${MOBILE_URL:http://localhost:82} freightLimit: "88" # 运费限额 freightPrice: "10" # 运费 unpaidOrderCancelDelayTime: 30 # 未支付订单超时时间 @@ -70,7 +70,7 @@ wayn: # wx支付配置 shop: # 开发者应该设置成自己的wx相关信息 - wx: + wxpay: app-id: app-secret: mch-id: