diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationOrderController.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationOrderController.java index f0eca14..e92bffd 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationOrderController.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationOrderController.java @@ -28,7 +28,7 @@ import java.util.List; @Validated @RequiredArgsConstructor @RestController -@RequestMapping("/scale/reservationOrder") +@RequestMapping("/reservation/order") public class ReservationOrderController extends BaseController { private final IReservationOrderService reservationOrderService; @@ -36,7 +36,7 @@ public class ReservationOrderController extends BaseController { /** * 查询预约订单列表 */ - @SaCheckPermission("scale:reservationOrder:list") + @SaCheckPermission("reservation:order:list") @GetMapping("/list") public TableDataInfo list(ReservationOrderBo bo, PageQuery pageQuery) { return reservationOrderService.queryPageList(bo, pageQuery); @@ -45,7 +45,7 @@ public class ReservationOrderController extends BaseController { /** * 导出预约订单列表 */ - @SaCheckPermission("scale:reservationOrder:export") + @SaCheckPermission("reservation:order:export") @Log(title = "预约订单", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(ReservationOrderBo bo, HttpServletResponse response) { @@ -58,7 +58,7 @@ public class ReservationOrderController extends BaseController { * * @param id 主键 */ - @SaCheckPermission("scale:reservationOrder:query") + @SaCheckPermission("reservation:order:query") @GetMapping("/{id}") public R getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) { diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationRefundController.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationRefundController.java index a239e58..1811ccb 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationRefundController.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/ReservationRefundController.java @@ -5,7 +5,9 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import org.dromara.common.core.domain.R; +import org.dromara.common.core.validate.EditGroup; import org.dromara.common.excel.utils.ExcelUtil; +import org.dromara.common.idempotent.annotation.RepeatSubmit; import org.dromara.common.log.annotation.Log; import org.dromara.common.log.enums.BusinessType; import org.dromara.common.mybatis.core.page.PageQuery; @@ -28,7 +30,7 @@ import java.util.List; @Validated @RequiredArgsConstructor @RestController -@RequestMapping("/scale/reservationRefund") +@RequestMapping("/reservation/refund") public class ReservationRefundController extends BaseController { private final IReservationRefundService reservationRefundService; @@ -61,8 +63,20 @@ public class ReservationRefundController extends BaseController { @SaCheckPermission("reservation:refund:query") @GetMapping("/{id}") public R getInfo(@NotNull(message = "主键不能为空") - @PathVariable Long id) { + @PathVariable Long id) { return R.ok(reservationRefundService.queryById(id)); } + /** + * 同意退款 + * + * @param bo + * @return + */ + @Log(title = "同意退款", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping("/agree") + public R refundAgree(@Validated(EditGroup.class) @RequestBody ReservationRefundBo bo) throws Exception { + return toAjax(reservationRefundService.agree(bo)); + } } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/wx/WxPayController.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/wx/WxPayController.java index b17f6aa..336cfe5 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/wx/WxPayController.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/controller/wx/WxPayController.java @@ -3,11 +3,13 @@ package org.dromara.scale.controller.wx; import cn.dev33.satoken.annotation.SaIgnore; import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; +import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.dromara.scale.service.IReservationOrderService; +import org.dromara.scale.service.IReservationRefundService; import org.dromara.scale.service.ISysScaleOrderService; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; @@ -37,6 +39,8 @@ public class WxPayController { private final IReservationOrderService reservationOrderService; + private final IReservationRefundService reservationRefundService; + @PostMapping("/notify/order/scale") public String parseScaleNotifyResult(@RequestBody String xmlData) throws WxPayException { log.info("---------量表支付回调-----------------"); @@ -51,4 +55,11 @@ public class WxPayController { reservationOrderService.processOrder(notifyResult); return WxPayNotifyResponse.success("成功"); } + + @PostMapping("/notify/refund/reservation") + public String refundReservationNotifyResult(@RequestBody String xmlData) throws WxPayException { + final WxPayRefundNotifyResult result = this.payService.parseRefundNotifyResult(xmlData); + reservationRefundService.refundOrder(result); + return WxPayNotifyResponse.success("成功"); + } } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/ReservationRefund.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/ReservationRefund.java index 89e9e42..9684a7f 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/ReservationRefund.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/ReservationRefund.java @@ -42,10 +42,11 @@ public class ReservationRefund extends BaseEntity { */ private String refundDesc; + /** * 退款状态 */ private Integer status; - + private String wxRefundId; } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/ReservationRefundBo.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/ReservationRefundBo.java index 8992c3c..5e8e60d 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/ReservationRefundBo.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/bo/ReservationRefundBo.java @@ -23,13 +23,13 @@ public class ReservationRefundBo extends BaseEntity { /** * */ - @NotNull(message = "不能为空", groups = { EditGroup.class }) + @NotNull(message = "不能为空", groups = {EditGroup.class}) private Long id; /** * 订单号 */ - @NotNull(message = "订单号不能为空", groups = { AddGroup.class, EditGroup.class }) + @NotNull(message = "订单号不能为空", groups = {AddGroup.class, EditGroup.class}) private Long orderId; /** @@ -41,7 +41,7 @@ public class ReservationRefundBo extends BaseEntity { /** * 退款原因 */ - @NotBlank(message = "退款原因不能为空", groups = { AddGroup.class, EditGroup.class }) + @NotBlank(message = "退款原因不能为空", groups = {AddGroup.class}) private String refundDesc; /** diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/ReservationRefundVo.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/ReservationRefundVo.java index 6bf926e..935ba98 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/ReservationRefundVo.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/domain/vo/ReservationRefundVo.java @@ -1,5 +1,8 @@ package org.dromara.scale.domain.vo; +import io.github.linpeilie.annotations.AutoMapping; +import org.dromara.common.translation.annotation.Translation; +import org.dromara.common.translation.constant.TransConstant; import org.dromara.scale.domain.ReservationRefund; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; @@ -39,9 +42,14 @@ public class ReservationRefundVo implements Serializable { /** * 申请人 */ + @Translation(type = TransConstant.USER_ID_TO_NICKNAME) @ExcelProperty(value = "申请人") private Long userId; + @Translation(type = TransConstant.USER_ID_TO_NICKNAME) + @AutoMapping(target = "userId") + private Long userPhone; + /** * 退款原因 */ diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/IReservationRefundService.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/IReservationRefundService.java index 556c2bd..1c1dcfd 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/IReservationRefundService.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/IReservationRefundService.java @@ -1,5 +1,6 @@ package org.dromara.scale.service; +import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.scale.domain.bo.ReservationRefundBo; @@ -56,4 +57,8 @@ public interface IReservationRefundService { */ Boolean updateByBo(ReservationRefundBo bo); + Boolean agree(ReservationRefundBo bo) throws Exception ; + + Boolean refundOrder(WxPayRefundNotifyResult notifyResult); + } diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationOrderServiceImpl.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationOrderServiceImpl.java index 9179a09..97693b6 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationOrderServiceImpl.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationOrderServiceImpl.java @@ -8,6 +8,7 @@ import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; import com.github.binarywang.wxpay.service.WxPayService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -34,6 +35,7 @@ import java.util.Map; * @author cjw * @date 2024-08-22 */ +@Slf4j @RequiredArgsConstructor @Service public class ReservationOrderServiceImpl implements IReservationOrderService { @@ -132,7 +134,19 @@ public class ReservationOrderServiceImpl implements IReservationOrderService { @Override public Boolean processOrder(WxPayOrderNotifyResult notifyResult) { + String returnCode = notifyResult.getReturnCode(); String orderId = notifyResult.getOutTradeNo(); + if ("FAIL".equals(returnCode)) { + log.error("预约订单:{},支付时通信异常。异常原因:{}", orderId, notifyResult.getReturnMsg()); + return false; + } + String resultCode = notifyResult.getResultCode(); + if("FAIL".equals(resultCode)){ + String errCode = notifyResult.getErrCode(); + String errCodeDes = notifyResult.getErrCodeDes(); + log.error("预约订单:{},支付异常。异常代码:{}。异常原因:{}", orderId, errCode,errCodeDes); + return false; + } String transactionId = notifyResult.getTransactionId(); long id = Long.parseLong(orderId); ReservationOrder reservationOrder = baseMapper.selectById(id); diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationRefundServiceImpl.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationRefundServiceImpl.java index 4d6f033..83a2dd8 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationRefundServiceImpl.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/ReservationRefundServiceImpl.java @@ -3,7 +3,11 @@ package org.dromara.scale.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; +import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; +import com.github.binarywang.wxpay.service.WxPayService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; @@ -19,6 +23,8 @@ import org.dromara.scale.mapper.ReservationRefundMapper; import org.dromara.scale.service.IReservationRefundService; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.util.Date; import java.util.List; import java.util.Map; @@ -28,12 +34,14 @@ import java.util.Map; * @author cjw * @date 2024-10-15 */ +@Slf4j @RequiredArgsConstructor @Service public class ReservationRefundServiceImpl implements IReservationRefundService { private final ReservationRefundMapper baseMapper; private final ReservationOrderMapper orderMapper; + private final WxPayService wxService; /** * 查询预约退款 @@ -115,6 +123,56 @@ public class ReservationRefundServiceImpl implements IReservationRefundService { return baseMapper.updateById(update) > 0; } + @Override + public Boolean agree(ReservationRefundBo bo) throws Exception { + Long orderId = bo.getOrderId(); + Long refundId = bo.getId(); + ReservationOrder order = orderMapper.selectById(orderId); + BigDecimal orderPrice = order.getOrderPrice(); + int totalFee = orderPrice.multiply(new BigDecimal(100)).intValue(); + WxPayRefundRequest request = new WxPayRefundRequest(); + request.setOutTradeNo(orderId.toString()); + request.setOutRefundNo(refundId.toString()); + request.setTotalFee(totalFee); + request.setRefundFee(totalFee); + request.setNotifyUrl("https://api.ysmental.com/tenant/wx/pay/notify/refund/reservation"); + this.wxService.refund(request); + return null; + } + + @Override + public Boolean refundOrder(WxPayRefundNotifyResult notifyResult) { + String returnCode = notifyResult.getReturnCode(); + WxPayRefundNotifyResult.ReqInfo reqInfo = notifyResult.getReqInfo(); + String refundId = reqInfo.getOutRefundNo(); + if ("FAIL".equals(returnCode)) { + log.error("退款单号:{},退款时通信异常。异常原因:{}", refundId, notifyResult.getReturnMsg()); + return false; + } + String resultCode = reqInfo.getRefundStatus(); + if (!"SUCCESS".equals(resultCode)) { + log.error("退款单号:{},退款异常。异常代码:{}。", refundId, resultCode); + return false; + } + String orderId = reqInfo.getOutTradeNo(); + String wxRefundId = reqInfo.getRefundId(); + + //更新订单状态 + Date date = new Date(); + ReservationOrder order = new ReservationOrder(); + order.setId(Long.parseLong(orderId)); + order.setOrderStatus(99); + order.setUpdateTime(date); + boolean orderFlag = orderMapper.updateById(order) > 0; + ReservationRefund refund = new ReservationRefund(); + refund.setId(Long.parseLong(refundId)); + refund.setStatus(1); + refund.setWxRefundId(wxRefundId); + refund.setUpdateTime(date); + boolean refundFlag = baseMapper.insert(refund) > 0; + return orderFlag && refundFlag; + } + /** * 保存前的数据校验 */ diff --git a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysScaleOrderServiceImpl.java b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysScaleOrderServiceImpl.java index 316f811..39fa6dd 100644 --- a/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysScaleOrderServiceImpl.java +++ b/ruoyi-modules/rouyi-scale/src/main/java/org/dromara/scale/service/impl/SysScaleOrderServiceImpl.java @@ -8,6 +8,7 @@ import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; import com.github.binarywang.wxpay.service.WxPayService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -25,6 +26,7 @@ import org.dromara.scale.service.ISysScaleOrderService; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.util.Date; import java.util.List; import java.util.Map; @@ -34,6 +36,7 @@ import java.util.Map; * @author cjw * @date 2024-07-30 */ +@Slf4j @RequiredArgsConstructor @Service public class SysScaleOrderServiceImpl implements ISysScaleOrderService { @@ -145,12 +148,25 @@ public class SysScaleOrderServiceImpl implements ISysScaleOrderService { @Override public Boolean processOrder(WxPayOrderNotifyResult notifyResult) { + String returnCode = notifyResult.getReturnCode(); String orderId = notifyResult.getOutTradeNo(); + if ("FAIL".equals(returnCode)) { + log.error("量表订单:{},通信异常。异常原因:{}", orderId, notifyResult.getReturnMsg()); + return false; + } + String resultCode = notifyResult.getResultCode(); + if ("FAIL".equals(resultCode)) { + String errCode = notifyResult.getErrCode(); + String errCodeDes = notifyResult.getErrCodeDes(); + log.error("量表订单:{},支付异常。异常代码:{}。异常原因:{}", orderId, errCode, errCodeDes); + return false; + } String transactionId = notifyResult.getTransactionId(); long id = Long.parseLong(orderId); SysScaleOrder scaleOrder = baseMapper.selectById(id); Long userId = scaleOrder.getCreateBy(); Long recordId = scaleOrder.getRecordId(); + Date date = new Date(); //初始量测记录 SysEvaluationRecord record = new SysEvaluationRecord(); record.setRecordId(recordId); @@ -158,12 +174,14 @@ public class SysScaleOrderServiceImpl implements ISysScaleOrderService { //个人测评订单号就是批次号 record.setBatchNo(id); record.setUpdateBy(userId); + record.setUpdateTime(date); boolean recordFlag = recordMapper.updateById(record) > 0; //更新订单状态 SysScaleOrder order = new SysScaleOrder(); order.setId(id); order.setOrderStatus(1); - order.setUpdateBy(userId); + //order.setUpdateBy(userId); + order.setUpdateTime(date); order.setTransactionId(transactionId); boolean orderFlag = baseMapper.updateById(order) > 0; return recordFlag && orderFlag;