Commit ce0718b646f9588568f3e92d0d74787da998e353

Authored by fengliang
1 parent 39095a05

update:退款暂存

etrade-order/src/main/java/com/diligrp/etrade/order/api/OrderController.java
... ... @@ -806,28 +806,4 @@ public class OrderController {
806 806 return Message.failure("服务暂时不在线,请稍后");
807 807 }
808 808 }
809   -
810   -
811   - /**
812   - * 发起退款
813   - * @param refundDto
814   - * @return
815   - */
816   - @RequestMapping(value = "/refund",method = {RequestMethod.POST},produces="application/json;charset=UTF-8")
817   - public Message<OrderDto> refund(@RequestBody OrderRefundDto refundDto){
818   - try{
819   - RLock lock = redissonClient.getLock(OrderConstant.OrderLock + refundDto.getCode());
820   - try {
821   - lock.lock();
822   - orderService.refundByOrderCode(refundDto);
823   - return Message.success();
824   - }finally {
825   - lock.unlock();
826   - }
827   -
828   - }catch (PlatformServiceException pe) {
829   - LOGGER.warn("服务异常{}:{}",pe.getCode(), pe.getMessage());
830   - return Message.failure("服务暂时不在线,请稍后");
831   - }
832   - }
833 809 }
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/controller/OrderManagerController.java
1 1 package com.diligrp.etrade.order.controller;
2 2  
  3 +import com.diligrp.etrade.core.authority.SessionContext;
  4 +import com.diligrp.etrade.core.authority.UserTicket;
  5 +import com.diligrp.etrade.core.domain.Message;
  6 +import com.diligrp.etrade.core.exception.PlatformServiceException;
  7 +import com.diligrp.etrade.order.domain.OrderRefundDto;
  8 +import com.diligrp.etrade.order.service.OrderRefundService;
  9 +import com.diligrp.etrade.order.util.OrderConstant;
  10 +import jakarta.annotation.Resource;
  11 +import org.redisson.api.RLock;
  12 +import org.redisson.api.RedissonClient;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.web.bind.annotation.RequestBody;
  16 +import org.springframework.web.bind.annotation.RequestMapping;
  17 +import org.springframework.web.bind.annotation.RequestMethod;
  18 +import org.springframework.web.bind.annotation.RestController;
  19 +
  20 +@RestController
  21 +@RequestMapping("/api/orderManager")
3 22 public class OrderManagerController {
  23 + private static final Logger LOGGER = LoggerFactory.getLogger(OrderManagerController.class);
  24 +
  25 + @Resource
  26 + private RedissonClient redissonClient;
  27 + @Resource
  28 + private OrderRefundService orderRefundService;
  29 + /**
  30 + * 发起退款
  31 + * @param refundDto
  32 + * @return
  33 + */
  34 + @RequestMapping(value = "/refund",method = {RequestMethod.POST},produces="application/json;charset=UTF-8")
  35 + public Message refund(@RequestBody OrderRefundDto refundDto){
  36 + UserTicket userTicket = SessionContext.getUserTicket();
  37 + try{
  38 + RLock lock = redissonClient.getLock(OrderConstant.OrderLock + refundDto.getCode());
  39 + try {
  40 + lock.lock();
  41 + return orderRefundService.addRefund(refundDto,userTicket);
  42 + }finally {
  43 + lock.unlock();
  44 + }
  45 +
  46 + }catch (PlatformServiceException pe) {
  47 + LOGGER.warn("服务异常{}:{}",pe.getCode(), pe.getMessage());
  48 + return Message.failure("服务暂时不在线,请稍后");
  49 + }
  50 + }
  51 +
  52 + @RequestMapping(value = "/refundCheck",method = {RequestMethod.POST},produces="application/json;charset=UTF-8")
  53 + public Message refundCheck(@RequestBody OrderRefundDto refundDto){
  54 + try{
  55 + return orderRefundService.refundCheck();
  56 + }catch (PlatformServiceException pe) {
  57 + LOGGER.warn("服务异常{}:{}",pe.getCode(), pe.getMessage());
  58 + return Message.failure("服务暂时不在线,请稍后");
  59 + }
  60 + }
  61 +
  62 + @RequestMapping(value = "/refundCallBack",method = {RequestMethod.POST},produces="application/json;charset=UTF-8")
  63 + public Message refundCallBack(@RequestBody OrderRefundDto refundDto){
  64 + try{
  65 + return orderRefundService.refundCheck();
  66 + }catch (PlatformServiceException pe) {
  67 + LOGGER.warn("服务异常{}:{}",pe.getCode(), pe.getMessage());
  68 + return Message.failure("服务暂时不在线,请稍后");
  69 + }
  70 + }
4 71 }
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/dao/OrderRefundMapper.java 0 → 100644
  1 +package com.diligrp.etrade.order.dao;
  2 +
  3 +import com.diligrp.etrade.core.mybatis.MybatisMapperSupport;
  4 +import com.diligrp.etrade.order.model.OrderRefund;
  5 +import org.apache.ibatis.annotations.Param;
  6 +import org.springframework.stereotype.Repository;
  7 +
  8 +import java.util.Map;
  9 +
  10 +@Repository("orderRefundMapper")
  11 +public interface OrderRefundMapper extends MybatisMapperSupport {
  12 + Map<String, Long> getRefundInfoBefore(@Param("orderId") Long orderId);
  13 +
  14 + Long insert(OrderRefund orderRefund);
  15 +
  16 + Integer update(OrderRefund orderRefund);
  17 +}
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/model/Order.java
... ... @@ -284,6 +284,12 @@ public class Order {
284 284 /** 扣减库存状态(1未扣减,2已扣减) */
285 285 private Integer stockDeductionState;
286 286  
  287 + /**
  288 + * 退款总计
  289 + * @return
  290 + */
  291 + private Long totalRefundAmount;
  292 +
287 293 public Integer getAchieveType() {
288 294 return achieveType;
289 295 }
... ... @@ -755,4 +761,12 @@ public class Order {
755 761 public void setStockDeductionState(Integer stockDeductionState) {
756 762 this.stockDeductionState = stockDeductionState;
757 763 }
  764 +
  765 + public Long getTotalRefundAmount() {
  766 + return totalRefundAmount;
  767 + }
  768 +
  769 + public void setTotalRefundAmount(Long totalRefundAmount) {
  770 + this.totalRefundAmount = totalRefundAmount;
  771 + }
758 772 }
759 773 \ No newline at end of file
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/model/OrderRefund.java 0 → 100644
  1 +package com.diligrp.etrade.order.model;
  2 +
  3 +import java.time.LocalDateTime;
  4 +
  5 +/**
  6 + * 交易订单结算单
  7 + * @author fengliang
  8 + * @since 2023.08.25
  9 + */
  10 +public class OrderRefund {
  11 + private Long id;
  12 +
  13 + /**
  14 + * 实际退款单号
  15 + */
  16 + private String refundId;
  17 +
  18 + /**
  19 + * 市场主键
  20 + */
  21 + private Long marketId;
  22 +
  23 + /**
  24 + * 订单主键
  25 + */
  26 + private Long orderId;
  27 +
  28 + /**
  29 + * 订单编号
  30 + */
  31 + private String orderCode;
  32 +
  33 + /**
  34 + * 退款金额
  35 + */
  36 + private Long refundAmount;
  37 +
  38 + /**
  39 + * 退款说明
  40 + */
  41 + private String refundMessage;
  42 +
  43 + /**
  44 + * 退款单状态
  45 + */
  46 + private Integer state;
  47 +
  48 + /**
  49 + * paymentId微信交易单号
  50 + */
  51 + private String tradeId;
  52 +
  53 + /**
  54 + * 退款失败原因
  55 + */
  56 + private String notic;
  57 +
  58 + /**
  59 + * 交费单主键
  60 + */
  61 + private Long orderPaymentId;
  62 +
  63 + /**
  64 + * 版本号
  65 + */
  66 + private Integer version;
  67 +
  68 + /** 退款单创建时间 */
  69 + private LocalDateTime createdTime;
  70 +
  71 + /** 退款单更新时间 */
  72 + private LocalDateTime modifiedTime;
  73 +
  74 + /**
  75 + * 退款时间
  76 + */
  77 + private LocalDateTime refundTime;
  78 +
  79 + private Long createId;
  80 +
  81 + private String createName;
  82 +
  83 + public Long getId() {
  84 + return id;
  85 + }
  86 +
  87 + public void setId(Long id) {
  88 + this.id = id;
  89 + }
  90 +
  91 + public String getRefundId() {
  92 + return refundId;
  93 + }
  94 +
  95 + public void setRefundId(String refundId) {
  96 + this.refundId = refundId;
  97 + }
  98 +
  99 + public Long getMarketId() {
  100 + return marketId;
  101 + }
  102 +
  103 + public void setMarketId(Long marketId) {
  104 + this.marketId = marketId;
  105 + }
  106 +
  107 + public Long getOrderId() {
  108 + return orderId;
  109 + }
  110 +
  111 + public void setOrderId(Long orderId) {
  112 + this.orderId = orderId;
  113 + }
  114 +
  115 + public String getOrderCode() {
  116 + return orderCode;
  117 + }
  118 +
  119 + public void setOrderCode(String orderCode) {
  120 + this.orderCode = orderCode;
  121 + }
  122 +
  123 + public Long getRefundAmount() {
  124 + return refundAmount;
  125 + }
  126 +
  127 + public void setRefundAmount(Long refundAmount) {
  128 + this.refundAmount = refundAmount;
  129 + }
  130 +
  131 + public String getRefundMessage() {
  132 + return refundMessage;
  133 + }
  134 +
  135 + public void setRefundMessage(String refundMessage) {
  136 + this.refundMessage = refundMessage;
  137 + }
  138 +
  139 + public Integer getState() {
  140 + return state;
  141 + }
  142 +
  143 + public void setState(Integer state) {
  144 + this.state = state;
  145 + }
  146 +
  147 + public String getTradeId() {
  148 + return tradeId;
  149 + }
  150 +
  151 + public void setTradeId(String tradeId) {
  152 + this.tradeId = tradeId;
  153 + }
  154 +
  155 + public String getNotic() {
  156 + return notic;
  157 + }
  158 +
  159 + public void setNotic(String notic) {
  160 + this.notic = notic;
  161 + }
  162 +
  163 + public Long getOrderPaymentId() {
  164 + return orderPaymentId;
  165 + }
  166 +
  167 + public void setOrderPaymentId(Long orderPaymentId) {
  168 + this.orderPaymentId = orderPaymentId;
  169 + }
  170 +
  171 + public LocalDateTime getCreatedTime() {
  172 + return createdTime;
  173 + }
  174 +
  175 + public void setCreatedTime(LocalDateTime createdTime) {
  176 + this.createdTime = createdTime;
  177 + }
  178 +
  179 + public LocalDateTime getModifiedTime() {
  180 + return modifiedTime;
  181 + }
  182 +
  183 + public void setModifiedTime(LocalDateTime modifiedTime) {
  184 + this.modifiedTime = modifiedTime;
  185 + }
  186 +
  187 + public Integer getVersion() {
  188 + return version;
  189 + }
  190 +
  191 + public void setVersion(Integer version) {
  192 + this.version = version;
  193 + }
  194 +
  195 + public LocalDateTime getRefundTime() {
  196 + return refundTime;
  197 + }
  198 +
  199 + public void setRefundTime(LocalDateTime refundTime) {
  200 + this.refundTime = refundTime;
  201 + }
  202 +
  203 + public Long getCreateId() {
  204 + return createId;
  205 + }
  206 +
  207 + public void setCreateId(Long createId) {
  208 + this.createId = createId;
  209 + }
  210 +
  211 + public String getCreateName() {
  212 + return createName;
  213 + }
  214 +
  215 + public void setCreateName(String createName) {
  216 + this.createName = createName;
  217 + }
  218 +}
0 219 \ No newline at end of file
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/service/OrderRefundService.java 0 → 100644
  1 +package com.diligrp.etrade.order.service;
  2 +
  3 +import com.diligrp.etrade.core.authority.UserTicket;
  4 +import com.diligrp.etrade.core.domain.Message;
  5 +import com.diligrp.etrade.order.domain.OrderRefundDto;
  6 +import com.diligrp.etrade.order.model.OrderPayment;
  7 +import com.diligrp.etrade.order.model.OrderRefund;
  8 +
  9 +/** 订单接口 */
  10 +public interface OrderRefundService {
  11 +
  12 + /**
  13 + * 退款申请
  14 + * @param refundDto
  15 + * @param userTicket
  16 + * @return
  17 + */
  18 + Message addRefund(OrderRefundDto refundDto, UserTicket userTicket);
  19 +
  20 + /**
  21 + * 根据退款单发起退款
  22 + * @param orderRefund
  23 + */
  24 + OrderRefund bulidRefundOrderAndRefund(OrderRefund orderRefund);
  25 +
  26 + /**
  27 + * 退款查询
  28 + * @return
  29 + */
  30 + Message refundCheck();
  31 +}
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/service/OrderService.java
1 1 package com.diligrp.etrade.order.service;
2 2  
3 3 import com.diligrp.etrade.admin.domain.StoreCustomerResponseDto;
  4 +import com.diligrp.etrade.core.authority.UserTicket;
4 5 import com.diligrp.etrade.core.domain.Message;
5 6 import com.diligrp.etrade.order.domain.*;
6 7 import com.diligrp.etrade.order.model.Order;
... ... @@ -8,6 +9,7 @@ import com.diligrp.etrade.order.type.OrderOrderState;
8 9 import com.diligrp.etrade.rpc.dto.WeChatPayFunctionDto;
9 10 import com.diligrp.etrade.rpc.dto.WeChatPayTradeCallBackDto;
10 11 import com.diligrp.etrade.shared.domain.OrderQrCode;
  12 +import org.springframework.transaction.annotation.Transactional;
11 13  
12 14 import java.time.LocalDateTime;
13 15 import java.util.List;
... ... @@ -22,6 +24,12 @@ public interface OrderService {
22 24 Order createOrder(OrderCreateDto orderBuyerDto, Integer orderType,Boolean transportFeeFlag);
23 25  
24 26 /**
  27 + * 更新订单
  28 + * @param order
  29 + */
  30 + void updateByOnly(Order order);
  31 +
  32 + /**
25 33 * 创建或更新订单
26 34 * @param orderBuyerDto
27 35 * @param orderType 身份类型
... ... @@ -258,6 +266,4 @@ public interface OrderService {
258 266 OrderDto checkOrderState(String code);
259 267  
260 268 TransportFeeDto getTransportFee(OrderTransportFeeQuery order);
261   -
262   - void refundByOrderCode(OrderRefundDto refundDto);
263 269 }
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderRefundServiceImpl.java 0 → 100644
  1 +package com.diligrp.etrade.order.service.impl;
  2 +
  3 +import com.diligrp.etrade.core.authority.UserTicket;
  4 +import com.diligrp.etrade.core.domain.Message;
  5 +import com.diligrp.etrade.order.dao.OrderRefundMapper;
  6 +import com.diligrp.etrade.order.domain.OrderGetDto;
  7 +import com.diligrp.etrade.order.domain.OrderRefundDto;
  8 +import com.diligrp.etrade.order.exception.OrderErrorCode;
  9 +import com.diligrp.etrade.order.model.Order;
  10 +import com.diligrp.etrade.order.model.OrderPayment;
  11 +import com.diligrp.etrade.order.model.OrderRefund;
  12 +import com.diligrp.etrade.order.service.OrderPaymentService;
  13 +import com.diligrp.etrade.order.service.OrderRefundService;
  14 +import com.diligrp.etrade.order.service.OrderService;
  15 +import com.diligrp.etrade.order.type.OrderPaymentState;
  16 +import com.diligrp.etrade.order.type.OrderRefundState;
  17 +import com.diligrp.etrade.order.util.NumberTransform;
  18 +import com.diligrp.etrade.order.util.OrderConstant;
  19 +import com.diligrp.etrade.rpc.dto.WeChatRefundBackDto;
  20 +import com.diligrp.etrade.rpc.dto.WeChatPayRefundDto;
  21 +import com.diligrp.etrade.rpc.resolver.WeChatPayRpcResolver;
  22 +import com.diligrp.etrade.rpc.type.WeChatRefundState;
  23 +import jakarta.annotation.Resource;
  24 +import org.slf4j.Logger;
  25 +import org.slf4j.LoggerFactory;
  26 +import org.springframework.stereotype.Service;
  27 +import org.springframework.transaction.annotation.Transactional;
  28 +
  29 +import java.math.RoundingMode;
  30 +import java.time.LocalDateTime;
  31 +import java.util.Map;
  32 +
  33 +
  34 +/**
  35 + * 订单主单服务实现
  36 + */
  37 +@Service
  38 +public class OrderRefundServiceImpl implements OrderRefundService {
  39 +
  40 + private static final Logger LOGGER = LoggerFactory.getLogger(OrderRefundServiceImpl.class);
  41 +
  42 + @Resource
  43 + private OrderRefundMapper orderRefundMapper;
  44 +
  45 + @Resource
  46 + private OrderService orderService;
  47 +
  48 + @Resource
  49 + private OrderPaymentService orderPaymentService;
  50 +
  51 + @Resource
  52 + private WeChatPayRpcResolver weChatPayRpcResolver;
  53 + @Transactional(rollbackFor = Exception.class)
  54 + @Override
  55 + public Message addRefund(OrderRefundDto refundDto, UserTicket userTicket) {
  56 + //基础参数效验
  57 + LOGGER.info("退款单入参{},操作员{}",refundDto,userTicket);
  58 + Order order = orderService.getOneOrder(new OrderGetDto(null, refundDto.getCode(), refundDto.getMarketId()));
  59 + if(order == null){
  60 + return Message.failure(OrderErrorCode.PARAM_ERROR,"订单不存在");
  61 + }
  62 + OrderPayment orderPayment = orderPaymentService.getOrderPaymentById(order.getId(), order.getMarketId(), OrderPaymentState.FINISH_PAY.getCode());
  63 + if(orderPayment == null){
  64 + return Message.failure(OrderErrorCode.PARAM_ERROR,"订单未支付");
  65 + }
  66 + //是否可退款效验
  67 + Map<String,Long> oldMap = orderRefundMapper.getRefundInfoBefore(order.getId());
  68 + Long refundAmount = refundDto.getRefundAmount().setScale(2, RoundingMode.HALF_UP).multiply(NumberTransform.ONE_HUNDERD).longValue();
  69 + if(oldMap!=null){
  70 + if(oldMap.get("doing")!=null&&!oldMap.get("doing").equals(0L)){
  71 + return Message.failure(OrderErrorCode.PARAM_ERROR,"有处理中的退款单据,请确定状态后,再操作");
  72 + }
  73 + Long AllRefundAmount = orderPayment.getPayAmount()-orderPayment.getPayDiscount();
  74 + if(oldMap.get("success")!=null&&oldMap.get("success")> AllRefundAmount - refundAmount){
  75 + return Message.failure(OrderErrorCode.PARAM_ERROR,"退款金额不能大于可退金额");
  76 + }
  77 + }
  78 + OrderRefund orderRefund = bulidOrderReFund(refundDto,order,orderPayment,userTicket);
  79 + orderRefundMapper.insert(orderRefund);
  80 +
  81 + //发起退款
  82 + orderRefund = bulidRefundOrderAndRefund(orderRefund);
  83 + orderRefundMapper.update(orderRefund);
  84 + //根据退款结果更新退款单内容
  85 + if(orderRefund.getState().equals(OrderRefundState.SUCCESS.getCode())){
  86 + order.setTotalRefundAmount(order.getTotalRefundAmount()+refundAmount);
  87 + orderService.updateByOnly(order);
  88 + return Message.success();
  89 + }else{
  90 + return Message.failure(OrderErrorCode.PARAM_ERROR,"已成功发起退款,退款结果暂未获得");
  91 + }
  92 +
  93 + }
  94 +
  95 + /**
  96 + * 发起退款
  97 + * @param orderRefund
  98 + */
  99 + @Transactional(rollbackFor = Exception.class)
  100 + @Override
  101 + public OrderRefund bulidRefundOrderAndRefund(OrderRefund orderRefund) {
  102 + WeChatPayRefundDto weChatPayRefundDto = bulidWeChatPayRefundDto(orderRefund);
  103 + Message<WeChatRefundBackDto> refundInfo = weChatPayRpcResolver.refund(weChatPayRefundDto);
  104 + if(refundInfo!=null&&refundInfo.getData()!=null){
  105 + orderRefund.setRefundId(refundInfo.getData().getRefundId());
  106 + if(refundInfo.getData().getState().equals(WeChatRefundState.REFUND_SUCCESS.getCode())){
  107 + orderRefund.setRefundTime(refundInfo.getData().getWhen()==null?LocalDateTime.now():refundInfo.getData().getWhen());
  108 + orderRefund.setState(OrderRefundState.SUCCESS.getCode());
  109 + } else if (refundInfo.getData().getState().equals(WeChatRefundState.REFUND_FAIL.getCode())) {
  110 + orderRefund.setState(OrderRefundState.FAIL.getCode());
  111 + }
  112 + }
  113 + return orderRefund;
  114 + }
  115 +
  116 + @Override
  117 + public Message refundCheck() {
  118 + return null;
  119 + }
  120 +
  121 + private WeChatPayRefundDto bulidWeChatPayRefundDto(OrderRefund orderRefund) {
  122 + WeChatPayRefundDto weChatPayRefundDto = new WeChatPayRefundDto();
  123 + weChatPayRefundDto.setPaymentId(orderRefund.getTradeId());
  124 + weChatPayRefundDto.setMarketId(orderRefund.getMarketId());
  125 + weChatPayRefundDto.setAmount(orderRefund.getRefundAmount());
  126 + weChatPayRefundDto.setDescription(orderRefund.getRefundMessage());
  127 + weChatPayRefundDto.setNotifyUrl(OrderConstant.WECHAT_REFUND_BACK_API);
  128 + return weChatPayRefundDto;
  129 + }
  130 +
  131 + /**
  132 + * 构建退款单
  133 + * @param refundDto
  134 + * @param order
  135 + * @param orderPayment
  136 + * @param userTicket
  137 + * @return
  138 + */
  139 + private OrderRefund bulidOrderReFund(OrderRefundDto refundDto, Order order, OrderPayment orderPayment,UserTicket userTicket) {
  140 + OrderRefund orderRefund = new OrderRefund();
  141 + orderRefund.setOrderCode(order.getCode());
  142 + orderRefund.setOrderId(order.getId());
  143 + orderRefund.setMarketId(order.getMarketId());
  144 + orderRefund.setRefundAmount(refundDto.getRefundAmount().setScale(2, RoundingMode.HALF_UP).multiply(NumberTransform.ONE_HUNDERD).longValue());
  145 + orderRefund.setRefundMessage(refundDto.getRefundMessage());
  146 + orderRefund.setState(OrderRefundState.DOING.getCode());
  147 + orderRefund.setTradeId(orderPayment.getTradeId());
  148 + orderRefund.setVersion(NumberTransform.DEFAULT_VERSION);
  149 + orderRefund.setOrderPaymentId(orderPayment.getId());
  150 + orderRefund.setCreateId(userTicket.getId());
  151 + orderRefund.setCreateName(userTicket.getRealName());
  152 + return orderRefund;
  153 + }
  154 +}
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderServiceImpl.java
... ... @@ -25,28 +25,22 @@ import com.diligrp.etrade.order.util.NumberTransform;
25 25 import com.diligrp.etrade.rpc.CustomerRpc;
26 26 import com.diligrp.etrade.rpc.UapRpc;
27 27 import com.diligrp.etrade.rpc.UidRpc;
28   -import com.diligrp.etrade.rpc.basicdata.BasicDataConfigRpc;
29 28 import com.diligrp.etrade.rpc.dto.*;
30   -import com.diligrp.etrade.rpc.dto.request.ConfigQueryDto;
31 29 import com.diligrp.etrade.rpc.dto.response.*;
32 30 import com.diligrp.etrade.rpc.resolver.PayRpcResolver;
33 31 import com.diligrp.etrade.rpc.dto.response.BalanceResponseDto;
34 32 import com.diligrp.etrade.rpc.dto.response.Customer;
35 33 import com.diligrp.etrade.rpc.dto.response.CustomerMarket;
36 34 import com.diligrp.etrade.rpc.dto.response.DataDictionaryValueDTO;
37   -import com.diligrp.etrade.rpc.resolver.WeChatPayRpcResolver;
38 35 import com.diligrp.etrade.rpc.type.CustomerState;
39 36 import com.diligrp.etrade.rpc.type.WeChatPayState;
40   -import com.diligrp.etrade.rpc.type.WeChatPayType;
41 37 import com.diligrp.etrade.rpc.util.Constants;
42 38 import com.diligrp.etrade.shared.SharedConfiguration;
43 39 import com.diligrp.etrade.shared.domain.OrderQrCode;
44   -import com.diligrp.etrade.shop.domain.request.ShopCo;
45 40 import com.diligrp.etrade.shop.domain.request.ShopExpressQueryCo;
46 41 import com.diligrp.etrade.shop.domain.response.ShopExpressVo;
47 42 import com.diligrp.etrade.shop.domain.response.ShopVo;
48 43 import com.diligrp.etrade.shop.service.ShopExpressSettingService;
49   -import com.diligrp.etrade.shop.service.ShopService;
50 44 import com.diligrp.etrade.shop.type.ExpressCondition;
51 45 import com.diligrp.etrade.shop.type.ExpressType;
52 46 import jakarta.annotation.Resource;
... ... @@ -390,7 +384,9 @@ public class OrderServiceImpl implements OrderService {
390 384 updateByOnly(order);
391 385 }
392 386  
393   - private void updateByOnly(Order order) {
  387 + @Transactional(rollbackFor = Exception.class)
  388 + @Override
  389 + public void updateByOnly(Order order) {
394 390 Long l = orderMapper.updateByIdSelective(order);
395 391 if(l<=0){
396 392 throw new OrderException(OrderErrorCode.ORDER_SYSTEM_ERROR,"数据已在其他地方处理,请刷新后重试");
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/type/OrderRefundState.java 0 → 100644
  1 +package com.diligrp.etrade.order.type;
  2 +
  3 +import com.diligrp.etrade.core.type.IEnumType;
  4 +
  5 +public enum OrderRefundState implements IEnumType {
  6 + FAIL("失败", 1),
  7 + DOING("处理中", 2),
  8 + SUCCESS("成功", 3);
  9 +
  10 + private String name;
  11 + private Integer code;
  12 +
  13 + private OrderRefundState(String name, Integer code) {
  14 + this.name = name;
  15 + this.code = code;
  16 + }
  17 +
  18 + public static OrderRefundState getByCode(Integer code) {
  19 + for (OrderRefundState temp : OrderRefundState.values()) {
  20 + if (temp.getCodeInteger().equals(code)) {
  21 + return temp;
  22 + }
  23 + }
  24 + return null;
  25 + }
  26 +
  27 + public static String getNameByCode(Integer code) {
  28 + for (OrderRefundState temp : OrderRefundState.values()) {
  29 + if (temp.getCodeInteger().equals(code)) {
  30 + return temp.getName();
  31 + }
  32 + }
  33 + return null;
  34 + }
  35 +
  36 + public Integer getCodeInteger() {
  37 + return this.code;
  38 + }
  39 +
  40 + public String getName() {
  41 + return this.name;
  42 + }
  43 +
  44 + public int getCode() {
  45 + return this.code;
  46 + }
  47 +
  48 + public String toString() {
  49 + return this.name;
  50 + }
  51 +}
0 52 \ No newline at end of file
... ...
etrade-order/src/main/java/com/diligrp/etrade/order/util/OrderConstant.java
... ... @@ -123,4 +123,9 @@ public class OrderConstant {
123 123 */
124 124 public static final String WECHATPAY_BACK_API= "api/order/wxChatPayCallBack";
125 125  
  126 + /**
  127 + * 微信退款回调地址
  128 + */
  129 + public static final String WECHAT_REFUND_BACK_API= "api/orderManager/refundCallBack";
  130 +
126 131 }
... ...
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/order/OrderRefundMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.diligrp.etrade.order.dao.OrderRefundMapper">
  4 + <resultMap id="BaseResultMap" type="com.diligrp.etrade.order.model.OrderRefund">
  5 + <id column="id" jdbcType="BIGINT" property="id" />
  6 + <result column="refund_id" jdbcType="VARCHAR" property="refundId" />
  7 + <result column="order_id" jdbcType="BIGINT" property="orderId" />
  8 + <result column="order_code" jdbcType="VARCHAR" property="orderCode" />
  9 + <result column="market_id" jdbcType="BIGINT" property="marketId" />
  10 + <result column="refund_amount" jdbcType="BIGINT" property="refundAmount" />
  11 + <result column="refund_message" jdbcType="VARCHAR" property="refundMessage" />
  12 + <result column="state" jdbcType="INTEGER" property="state" />
  13 + <result column="notic" jdbcType="VARCHAR" property="notic" />
  14 + <result column="trade_id" jdbcType="VARCHAR" property="tradeId" />
  15 + <result column="order_payment_id" jdbcType="BIGINT" property="orderPaymentId" />
  16 + <result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
  17 + <result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
  18 + <result column="version" jdbcType="INTEGER" property="version" />
  19 + <result column="refund_time" jdbcType="TIMESTAMP" property="refundTime" />
  20 + <result column="create_id" jdbcType="BIGINT" property="createId" />
  21 + <result column="create_name" jdbcType="VARCHAR" property="createName" />
  22 + </resultMap>
  23 + <sql id="baseSql" >
  24 + id,refund_id,order_id,order_code,market_id,
  25 + refund_amount,refund_message,state,notic,trade_id,
  26 + order_payment_id,created_time,modified_time,version,
  27 + refund_time,create_id,create_name
  28 + </sql>
  29 + <insert id="insert" parameterType="com.diligrp.etrade.order.model.OrderRefund" useGeneratedKeys="true" keyProperty="id" >
  30 + insert into order_refund (refund_id,order_id,order_code,market_id,
  31 + refund_amount,refund_message,state,notic,trade_id,
  32 + order_payment_id,created_time,version,refund_time,create_id,create_name)
  33 + values (#{refundId,jdbcType=VARCHAR},#{orderId,jdbcType=BIGINT},#{orderCode,jdbcType=VARCHAR},#{marketId,jdbcType=BIGINT},
  34 + #{refundAmount,jdbcType=BIGINT},#{refundMessage,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{notic,jdbcType=VARCHAR},#{tradeId,jdbcType=VARCHAR},
  35 + #{orderPaymentId,jdbcType=BIGINT},#{createdTime},#{version},#{refundTime},#{createId},#{createName})
  36 + </insert>
  37 + <update id="update" parameterType="com.diligrp.etrade.order.model.OrderRefund">
  38 + update order_refund
  39 + <set>
  40 + <if test="refundId != null" >
  41 + refund_id = #{refundId,jdbcType=VARCHAR},
  42 + </if>
  43 + <if test="orderId != null" >
  44 + order_id = #{orderId,jdbcType=BIGINT},
  45 + </if>
  46 + <if test="orderCode != null" >
  47 + order_code = #{orderCode,jdbcType=VARCHAR},
  48 + </if>
  49 + <if test="marketId != null" >
  50 + market_id = #{marketId,jdbcType=BIGINT},
  51 + </if>
  52 + <if test="refundAmount != null" >
  53 + refund_amount = #{refundAmount,jdbcType=BIGINT},
  54 + </if>
  55 + <if test="refundMessage != null" >
  56 + refund_message = #{refundMessage,jdbcType=VARCHAR},
  57 + </if>
  58 + <if test="state != null" >
  59 + state = #{state,jdbcType=INTEGER},
  60 + </if>
  61 + <if test="notic != null" >
  62 + notic = #{notic,jdbcType=VARCHAR},
  63 + </if>
  64 + <if test="tradeId != null" >
  65 + trade_id = #{tradeId,jdbcType=VARCHAR},
  66 + </if>
  67 + <if test="orderPaymentId != null" >
  68 + order_payment_id = #{orderPaymentId,jdbcType=BIGINT},
  69 + </if>
  70 + <if test="refundTime != null" >
  71 + refund_time = #{refundTime,jdbcType=TIMESTAMP},
  72 + </if>
  73 + <if test="createId != null" >
  74 + create_id = #{createId,jdbcType=BIGINT},
  75 + </if>
  76 + <if test="createName != null" >
  77 + create_name = #{createName,jdbcType=VARCHAR},
  78 + </if>
  79 + version = version + 1
  80 + </set>
  81 + where id = #{id}
  82 + </update>
  83 + <select id="getRefundInfoBefore" resultType="java.util.Map" parameterType="java.lang.Long">
  84 + select SUM(case when state = 2 then refund_amount else 0 end) as 'doing',
  85 + SUM(case when state = 3 then refund_amount else 0 end) as 'success' FROM order_refund
  86 + WHERE order_id = #{orderId}
  87 + </select>
  88 +</mapper>
0 89 \ No newline at end of file
... ...
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/PayRpc.java
... ... @@ -147,14 +147,14 @@ public interface PayRpc {
147 147 * @return
148 148 */
149 149 @RequestMapping(value = "/wechat/api/gateway.do?service=hzbank.payment.service:refund", method = RequestMethod.POST)
150   - Message<WeChatPayRefundBackDto> refundHg(@RequestBody WeChatPayRefundDto requestDto, @RequestHeader HttpHeaders headers);
  150 + Message<WeChatRefundBackDto> refundHg(@RequestBody WeChatPayRefundDto requestDto, @RequestHeader HttpHeaders headers);
151 151  
152 152 /**
153   - * 杭州银行微信退款
  153 + * 杭州银行微信退款查询
154 154 * @param requestDto
155 155 * @param headers
156 156 * @return
157 157 */
158 158 @RequestMapping(value = "/wechat/api/gateway.do?service=hzbank.payment.service:refundState", method = RequestMethod.POST)
159   - Message<WeChatPayRefundBackDto> refundCheckHg(@RequestBody WeChatPayRefundCheckDto requestDto, @RequestHeader HttpHeaders headers);
  159 + Message<WeChatRefundBackDto> refundCheckHg(@RequestBody WeChatPayRefundCheckDto requestDto, @RequestHeader HttpHeaders headers);
160 160 }
... ...
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/dto/WeChatPayRefundBackDto.java renamed to etrade-rpc/src/main/java/com/diligrp/etrade/rpc/dto/WeChatRefundBackDto.java
1 1 package com.diligrp.etrade.rpc.dto;
2 2  
  3 +import java.time.LocalDateTime;
  4 +
3 5 /**
4 6 * 微信预支付返回
5 7 * @author fengliang
6 8 * @Date 2024-3-25
7 9 */
8   -public class WeChatPayRefundBackDto {
  10 +public class WeChatRefundBackDto {
9 11  
10 12 /**
11 13 * 退款单号
... ... @@ -22,6 +24,11 @@ public class WeChatPayRefundBackDto {
22 24 */
23 25 private String message;
24 26  
  27 + /**
  28 + * 退款时间
  29 + */
  30 + private LocalDateTime when;
  31 +
25 32 public String getRefundId() {
26 33 return refundId;
27 34 }
... ... @@ -45,4 +52,12 @@ public class WeChatPayRefundBackDto {
45 52 public void setMessage(String message) {
46 53 this.message = message;
47 54 }
  55 +
  56 + public LocalDateTime getWhen() {
  57 + return when;
  58 + }
  59 +
  60 + public void setWhen(LocalDateTime when) {
  61 + this.when = when;
  62 + }
48 63 }
... ...
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/resolver/WeChatPayRpcResolver.java
... ... @@ -15,8 +15,6 @@ import org.springframework.http.HttpHeaders;
15 15 import org.springframework.http.MediaType;
16 16 import org.springframework.stereotype.Component;
17 17  
18   -import java.time.LocalDateTime;
19   -
20 18 @Component
21 19 @RefreshScope
22 20 public class WeChatPayRpcResolver {
... ... @@ -107,10 +105,11 @@ public class WeChatPayRpcResolver {
107 105 * @param weChatPayRefundDto
108 106 * @return
109 107 */
110   - public Message<WeChatPayRefundBackDto> refund(WeChatPayRefundDto weChatPayRefundDto){
  108 + public Message<WeChatRefundBackDto> refund(WeChatPayRefundDto weChatPayRefundDto){
  109 + weChatPayRefundDto.setNotifyUrl(backBaseUrl+weChatPayRefundDto.getNotifyUrl());
111 110 //组装headers
112 111 HttpHeaders prepareHeaders = creatHeader(weChatPayRefundDto.getMarketId().toString(), REFUND_STATE_INFO);
113   - Message<WeChatPayRefundBackDto> refundJsonObject = payRpc.refundHg(weChatPayRefundDto, prepareHeaders);
  112 + Message<WeChatRefundBackDto> refundJsonObject = payRpc.refundHg(weChatPayRefundDto, prepareHeaders);
114 113 if(!refundJsonObject.getCode().equals(200)){
115 114 log.info("退款参数{},请求体头部为{},请求结果为{}",weChatPayRefundDto,prepareHeaders,refundJsonObject);
116 115 throw new PlatformServiceException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "退款失败:" + refundJsonObject.getMessage());
... ... @@ -124,10 +123,10 @@ public class WeChatPayRpcResolver {
124 123 * @param weChatPayRefundCheckDto
125 124 * @return
126 125 */
127   - public Message<WeChatPayRefundBackDto> refundCheck(WeChatPayRefundCheckDto weChatPayRefundCheckDto){
  126 + public Message<WeChatRefundBackDto> refundCheck(WeChatPayRefundCheckDto weChatPayRefundCheckDto){
128 127 //组装headers
129 128 HttpHeaders prepareHeaders = creatHeader(weChatPayRefundCheckDto.getMarketId().toString(), REFUND_CHECK_INFO);
130   - Message<WeChatPayRefundBackDto> refundJsonObject = payRpc.refundCheckHg(weChatPayRefundCheckDto, prepareHeaders);
  129 + Message<WeChatRefundBackDto> refundJsonObject = payRpc.refundCheckHg(weChatPayRefundCheckDto, prepareHeaders);
131 130 if(!refundJsonObject.getCode().equals(200)){
132 131 log.info("退款查询参数{},请求体头部为{},请求结果为{}",weChatPayRefundCheckDto,prepareHeaders,refundJsonObject);
133 132 throw new PlatformServiceException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "退款失败:" + refundJsonObject.getMessage());
... ...
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/type/WeChatRefundState.java 0 → 100644
  1 +package com.diligrp.etrade.rpc.type;
  2 +
  3 +
  4 +/**
  5 + * 微信支付类型
  6 + */
  7 +public enum WeChatRefundState {
  8 + REFUND_SUCCESS(4, "支付成功"),
  9 +
  10 + REFUND_FAIL(5, "支付失败");
  11 +
  12 + private Integer code;
  13 + private String value;
  14 +
  15 + WeChatRefundState(Integer code, String value) {
  16 + this.code = code;
  17 + this.value = value;
  18 + }
  19 +
  20 + public static WeChatRefundState getInstance(Integer code) {
  21 + WeChatRefundState[] var1 = values();
  22 + int var2 = var1.length;
  23 +
  24 + for(int var3 = 0; var3 < var2; ++var3) {
  25 + WeChatRefundState state = var1[var3];
  26 + if (state.getCode().equals(code)) {
  27 + return state;
  28 + }
  29 + }
  30 + return null;
  31 + }
  32 +
  33 + public Boolean equalsToCode(Integer code) {
  34 + return this.getCode().equals(code);
  35 + }
  36 +
  37 + public Integer getCode() {
  38 + return this.code;
  39 + }
  40 +
  41 + public String getValue() {
  42 + return this.value;
  43 + }
  44 +
  45 +}
... ...