From e17699338b74ee85f468ddb4db8cbf36884ebe52 Mon Sep 17 00:00:00 2001 From: gaowdong Date: Fri, 25 Apr 2025 16:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A9=BF=E7=AB=99=E4=BB=98=E6=AC=BE=E9=80=80?= =?UTF-8?q?=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/common/utils/HeaderFetchUtil.java | 5 +++ .../common/business/OrderRefundBusiness.java | 3 ++ .../impl/OrderRefundBusinessImpl.java | 21 ++++++++++++ .../common/constants/StageWhiteList.java | 5 +++ .../order/common/dto/StageRefundParam.java | 17 ++++++++++ .../business/OrderPlaceMobileBusiness.java | 4 +++ .../impl/OrderPlaceMobileBusinessImplV3.java | 17 ++++++++++ .../controller/OrderInfoMobileController.java | 19 +++++++++++ .../OrderPlaceMobileController.java | 32 +++++++++++++++++++ .../order/mobile/dto/StagePayMobileDTO.java | 19 +++++++++++ 10 files changed, 142 insertions(+) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/constants/StageWhiteList.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/dto/StageRefundParam.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/dto/StagePayMobileDTO.java diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/HeaderFetchUtil.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/HeaderFetchUtil.java index 2b4b4343..24f84fe8 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/HeaderFetchUtil.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/HeaderFetchUtil.java @@ -63,6 +63,11 @@ public class HeaderFetchUtil { return NumberUtil.isNumber(value) ? Integer.valueOf(value) : null; } + public static String getSign(Map headers) { + String value = getValueFromHeadersIgnoreCase(headers, "sign"); + return value; + } + public static String getValueFromHeadersIgnoreCase(Map headers, String targetKey) { if (CollUtil.isEmpty(headers)) { return null; diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/OrderRefundBusiness.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/OrderRefundBusiness.java index 79109a82..874c6500 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/OrderRefundBusiness.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/OrderRefundBusiness.java @@ -2,8 +2,10 @@ package com.bonus.canteen.core.order.common.business; import com.bonus.canteen.core.order.common.constants.OrderRefundBizEnum; import com.bonus.canteen.core.order.common.dto.OrderRefundParam; +import com.bonus.canteen.core.order.common.dto.StageRefundParam; import com.bonus.canteen.core.order.common.model.OrderInfo; import com.bonus.canteen.core.order.common.vo.OrderRefundResultVO; +import com.bonus.canteen.core.pay.api.vo.UnifyRefundVO; import java.util.List; @@ -21,4 +23,5 @@ public interface OrderRefundBusiness { // void didEndOrderRefundFlow(Long orderRefundId, boolean isPass, String remark); // // void transferUncheckCorrectAfterOrderCreated(String macOrderId); + UnifyRefundVO stageRefund(StageRefundParam stageRefundParam); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/impl/OrderRefundBusinessImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/impl/OrderRefundBusinessImpl.java index 2eafb537..e6806127 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/impl/OrderRefundBusinessImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/business/impl/OrderRefundBusinessImpl.java @@ -5,6 +5,9 @@ import cn.hutool.core.map.MapUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.NumberUtil; import com.alibaba.nacos.shaded.com.google.common.collect.Lists; +import com.bonus.canteen.core.order.common.dto.StageRefundParam; +import com.bonus.canteen.core.pay.common.model.TradeRecord; +import com.bonus.canteen.core.pay.common.service.TradeRecordService; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.security.utils.SecurityUtils; import com.bonus.common.houqin.constant.LeConstants; @@ -133,6 +136,9 @@ public class OrderRefundBusinessImpl implements OrderRefundBusiness { @Autowired @Lazy protected AllocHolidayApi allocHolidayApi; + @Lazy + @Autowired + protected TradeRecordService tradeRecordService; public void orderCancel(OrderInfo orderInfo) { if (!this.orderCustomBusiness.refund().willCancelOrder(orderInfo)) { @@ -197,6 +203,21 @@ public class OrderRefundBusinessImpl implements OrderRefundBusiness { return var8; } + @Override + public UnifyRefundVO stageRefund(StageRefundParam stageRefundParam) { + LogUtil.printArgsIn("stagePayRefund", stageRefundParam); + TradeRecord tradeRecord = tradeRecordService.getTradeRecordById(stageRefundParam.getTradeId()); + if (tradeRecord == null) { + log.error("[统一支付退款]交易记录不存在"); + throw new ServiceException("交易记录不存在"); + } + UnifyRefundDTO payRefundDTO = new UnifyRefundDTO(); + payRefundDTO.setTradeId(stageRefundParam.getTradeId()); + payRefundDTO.setRefundId(Id.next()); + payRefundDTO.setRefundAmount(tradeRecord.getAmount()); + return this.payApi.refund(payRefundDTO); + } + // public void orderCorrect(OrderPartRefundDTO orderPartRefundDTO, OrderRefundBizEnum biz) { // if (CollUtil.isEmpty(orderPartRefundDTO.getDetailRefundList())) { // throw new LeException(I18n.getMessage("order.buffet.correct-lack-detail", new Object[0])); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/constants/StageWhiteList.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/constants/StageWhiteList.java new file mode 100644 index 00000000..0cc2628a --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/constants/StageWhiteList.java @@ -0,0 +1,5 @@ +package com.bonus.canteen.core.order.common.constants; + +public class StageWhiteList { + public static final String STAGE_SIGN_WHITE_LIST = "f678443b-99b4-41ec-8e9a-b7a5c92367f1"; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/dto/StageRefundParam.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/dto/StageRefundParam.java new file mode 100644 index 00000000..f63b201b --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/common/dto/StageRefundParam.java @@ -0,0 +1,17 @@ +package com.bonus.canteen.core.order.common.dto; + +import com.bonus.canteen.core.common.utils.SysUtil; +import com.bonus.canteen.core.pay.api.dto.UnifyRefundDTO; +import com.bonus.common.houqin.constant.LeConstants; +import com.fasterxml.jackson.databind.JsonNode; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Min; +import java.math.BigDecimal; +import java.util.List; + +@Data +public class StageRefundParam extends OrderRefundParam { + private Long tradeId; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/OrderPlaceMobileBusiness.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/OrderPlaceMobileBusiness.java index f59fb922..5ae2cd3d 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/OrderPlaceMobileBusiness.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/OrderPlaceMobileBusiness.java @@ -4,7 +4,9 @@ package com.bonus.canteen.core.order.mobile.business; import com.bonus.canteen.core.order.common.dto.RequestHeaderDTO; import com.bonus.canteen.core.order.mobile.dto.OrderPayMobileDTO; import com.bonus.canteen.core.order.mobile.dto.OrderReserveMealTotalDTO; +import com.bonus.canteen.core.order.mobile.dto.StagePayMobileDTO; import com.bonus.canteen.core.order.mobile.vo.OrderPayMobileVO; +import com.bonus.canteen.core.pay.api.vo.UnifyPayVO; public interface OrderPlaceMobileBusiness { // OrderPayMobileVO addCurrentMealOrder(RequestHeaderDTO headerDTO, OrderCurrMealTotalDTO currMealTotalDTO); @@ -22,4 +24,6 @@ public interface OrderPlaceMobileBusiness { // OrderPayMobileVO orderMixPayByTradeId(RequestHeaderDTO headerDTO, OrderMixPayMobileDTO orderMixPayMobileDTO); // // void orderPreBookAdd(RequestHeaderDTO headerDTO, OrderPreBookAddDTO addDTO); + + UnifyPayVO stageOrderPay(RequestHeaderDTO headerDTO, StagePayMobileDTO stagePayDTO); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/impl/OrderPlaceMobileBusinessImplV3.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/impl/OrderPlaceMobileBusinessImplV3.java index cb0cf30b..7bb3cb8a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/impl/OrderPlaceMobileBusinessImplV3.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/business/impl/OrderPlaceMobileBusinessImplV3.java @@ -332,6 +332,23 @@ public class OrderPlaceMobileBusinessImplV3 implements OrderPlaceMobileBusiness orderSavePO.setAmountChangeList(amountChangeList); return LeConstants.COMMON_YES.equals(orderPayDTO.getIfTrial()) ? this.trialPay(orderSavePO, (OrderDeliveryResultVO)null) : this.saveAndPay(orderSavePO, false, true); } + + @Override + public UnifyPayVO stageOrderPay(RequestHeaderDTO headerDTO, StagePayMobileDTO stagePayDTO) { + CustPayVO custInfo = this.getCustInfo(stagePayDTO.getCustId(), headerDTO.getSourceType()); + UnifyPayDTO unifyPayDTO = this.createPay(stagePayDTO.getPayType(), + stagePayDTO.getCouponId(), + headerDTO.getSourceType(), + null, + null, + headerDTO.getOpenid(), + custInfo, + stagePayDTO); + unifyPayDTO.setAmount(stagePayDTO.getAmount()); + unifyPayDTO.setRemark("驿站支付"); + return payApi.pay(unifyPayDTO); + } + // // public OrderPayMobileVO orderMixPayByTradeId(RequestHeaderDTO headerDTO, OrderMixPayMobileDTO orderMixPayMobileDTO) { // LogUtil.info("订单混合支付|入参", orderMixPayMobileDTO); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderInfoMobileController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderInfoMobileController.java index d6e15ec9..638951c2 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderInfoMobileController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderInfoMobileController.java @@ -1,5 +1,8 @@ package com.bonus.canteen.core.order.mobile.controller; +import com.bonus.canteen.core.order.common.constants.StageWhiteList; +import com.bonus.canteen.core.order.common.dto.StageRefundParam; +import com.bonus.canteen.core.pay.api.vo.UnifyRefundVO; import com.bonus.common.core.domain.R; import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.domain.AjaxResult; @@ -23,6 +26,7 @@ import com.bonus.canteen.core.pay.api.vo.UnifyPaySelectVO; import com.bonus.common.houqin.utils.LeRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -129,6 +133,21 @@ public class OrderInfoMobileController extends BaseController { OrderRefundResultVO resultVO = this.orderRefundBusiness.orderRefund(request.convertToOrderRefundParam(), OrderRefundBizEnum.MOBILE); return resultVO.ifSuccess() ? AjaxResult.success(resultVO) : AjaxResult.error(resultVO.getResultCode(), resultVO.getResultMsg()); } + + @PostMapping({"/stage/refund"}) + @ApiOperation( + value = "驿站退款", + notes = "驿站退款" + ) + public AjaxResult stageRefundMobile(@RequestHeader Map headers, + @RequestBody StageRefundParam request) { + String sign = HeaderFetchUtil.getSign(headers); + if(StringUtils.isBlank(sign) || !sign.equals(StageWhiteList.STAGE_SIGN_WHITE_LIST)) { + return AjaxResult.error("签名失败"); + } + UnifyRefundVO resultVO = this.orderRefundBusiness.stageRefund(request); + return AjaxResult.success(resultVO); + } // // @PostMapping({"/book/stat"}) // public LeResponse orderBookStat(@RequestHeader Map headers, @RequestBody LeRequest request) { diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderPlaceMobileController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderPlaceMobileController.java index 0c0c67d0..7021995d 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderPlaceMobileController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/controller/OrderPlaceMobileController.java @@ -1,6 +1,11 @@ package com.bonus.canteen.core.order.mobile.controller; +import com.bonus.canteen.core.common.utils.HeaderFetchUtil; +import com.bonus.canteen.core.order.common.constants.StageWhiteList; import com.bonus.canteen.core.order.mobile.dto.OrderPayMobileDTO; +import com.bonus.canteen.core.order.mobile.dto.StagePayMobileDTO; +import com.bonus.canteen.core.pay.api.vo.UnifyPayVO; +import com.bonus.canteen.core.pay.common.constants.PayTypeEnum; import com.bonus.common.core.domain.R; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.houqin.constant.RetCodeEnum; @@ -13,6 +18,7 @@ import com.bonus.common.houqin.utils.LeRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -127,6 +133,32 @@ public class OrderPlaceMobileController { LogUtil.info("[根据订单id支付]支付耗时", System.currentTimeMillis() - startTime, mobileVO); return !mobileVO.success() ? AjaxResult.error( mobileVO.getMsg(), mobileVO) : AjaxResult.success(mobileVO); } + + @PostMapping({"/stage/pay"}) + @ApiOperation( + value = "驿站付款", + notes = "驿站付款" + ) + public AjaxResult stageOrderPay(@RequestHeader Map headers, + @RequestBody StagePayMobileDTO stagePayDTO) { + String sign = HeaderFetchUtil.getSign(headers); + if(StringUtils.isBlank(sign) || !sign.equals(StageWhiteList.STAGE_SIGN_WHITE_LIST)) { + return AjaxResult.error("签名失败"); + } + UnifyPayVO mobileVO = null; + try{ + long startTime = System.currentTimeMillis(); + RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers); + stagePayDTO.setCustId(headerDTO.getCustId()); + stagePayDTO.setPayType(PayTypeEnum.MEAL_CARD.getKey()); + mobileVO = this.orderPlaceMobileBusiness.stageOrderPay(headerDTO, stagePayDTO); + LogUtil.info("[驿站支付]支付耗时", System.currentTimeMillis() - startTime, mobileVO); + }catch (Exception ex) { + log.error("驿站支付异常", ex); + return AjaxResult.error("支付失败", 500); + } + return AjaxResult.success(mobileVO); + } // // @PostMapping({"/mixPay/by/orderId"}) // @ApiOperation( diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/dto/StagePayMobileDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/dto/StagePayMobileDTO.java new file mode 100644 index 00000000..415c0dc1 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/mobile/dto/StagePayMobileDTO.java @@ -0,0 +1,19 @@ +package com.bonus.canteen.core.order.mobile.dto; + +import com.bonus.common.houqin.constant.LeConstants; +import com.fasterxml.jackson.databind.JsonNode; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; + +@ApiModel("移动端根据订单号支付DTO") +@Data +public class StagePayMobileDTO extends OrderPayMobileDTO{ + @ApiModelProperty("支付金额") + private @NotNull @Min(value = 0L, message = "金额不能小于0") BigDecimal amount; + +}