Explorar el Código

新增接口,发起退款余额查询及校验

xucaiqin hace 2 años
padre
commit
4ce8fbd32b

+ 13 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletController.java

@@ -226,8 +226,20 @@ public class WalletController {
         return HttpResult.ok(walletService.applyRefund(refundReq));
     }
 
+
+    /**
+     * 发起退款余额查询及校验
+     *
+     * @param refundReq
+     * @return
+     */
+    @PostMapping("refundCheck")
+    public HttpResult refundCheck(@RequestBody @Valid RefundCheckReq refundReq) {
+        return HttpResult.ok(walletService.refundCheck(refundReq));
+    }
+
     /**
-     * 退款
+     * 发起退款
      *
      * @param refundReq
      * @return

+ 48 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/WalletInfoDto.java

@@ -0,0 +1,48 @@
+package com.sckw.payment.model.dto;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import com.sckw.payment.model.vo.res.MoneyChange;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 钱包清单
+ */
+@Data
+public class WalletInfoDto implements MoneyChange, Serializable {
+    /**
+     * 企业名称
+     */
+    private String name;
+    /**
+     * 钱包名称
+     */
+    @JSONField(name = "wallet_name")
+    private String walletName;
+
+    /**
+     * 渠道
+     */
+    private String channel;
+
+    private Integer status;
+
+    /**
+     * 预付金额(分)
+     */
+    @JSONField(name = "ap_money")
+    private BigDecimal apMoney;
+    /**
+     * 提现余额
+     */
+    @JSONField(name = "wd_money")
+    private BigDecimal wdMoney;
+    /**
+     * 可用余额
+     */
+    private BigDecimal money;
+
+
+}

+ 2 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/PrePayWalletVo.java

@@ -22,6 +22,7 @@ public class PrePayWalletVo implements Serializable {
     @JSONField(name = "uid")
     private String uid;
     private String uidName;
+    private Long uidEnt;
 
     /**
      * 预付时,代表收款人
@@ -30,6 +31,7 @@ public class PrePayWalletVo implements Serializable {
     @JSONField(name = "filter")
     private String filter;
     private String filterName;
+    private Long filterEnt;
 
     @JSONField(name = "channel")
     private String channel;

+ 1 - 2
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/req/FinanceCount.java

@@ -1,6 +1,5 @@
 package com.sckw.payment.model.vo.req;
 
-import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import jakarta.validation.constraints.Size;
 import lombok.Getter;
@@ -20,7 +19,7 @@ public class FinanceCount {
     /**
      * 周期维度 1-日、2-周、3-月 4-年
      */
-    @NotBlank(message = "周期维度不能为空")
+    @NotNull(message = "周期维度不能为空")
     private Integer circle;
     /**
      * 开始时间

+ 32 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/req/RefundCheckReq.java

@@ -0,0 +1,32 @@
+package com.sckw.payment.model.vo.req;
+
+import com.sckw.payment.model.vo.res.MoneyChange;
+import jakarta.validation.constraints.NotBlank;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 预收-退款校验参数
+ *
+ * @author xucaiqin
+ * @date 2023-08-29 09:14:04
+ */
+@Getter
+@Setter
+public class RefundCheckReq implements MoneyChange {
+    /**
+     * 预收时,收款人 当前登录企业
+     */
+    @NotBlank(message = "当前企业不能为空")
+    private String uid;
+    /**
+     * 支付通道 huifu
+     */
+    @NotBlank(message = "支付通道不能为空")
+    private String channel;
+    /**
+     * 预收时,付款方
+     */
+    @NotBlank(message = "合作企业不能为空")
+    private String filter;
+}

+ 14 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/res/MoneyChange.java

@@ -1,6 +1,7 @@
 package com.sckw.payment.model.vo.res;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Objects;
 
 /**
@@ -24,4 +25,17 @@ public interface MoneyChange {
         return divide.longValueExact();
     }
 
+    /**
+     * 分转元
+     *
+     * @param big
+     * @return
+     */
+    default BigDecimal smallMoney(BigDecimal big) {
+        if (Objects.isNull(big)) {
+            return new BigDecimal("0.00");
+        }
+        return big.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
+    }
+
 }

+ 8 - 6
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementLogisticsService.java

@@ -103,6 +103,7 @@ public class KwpSettlementLogisticsService {
         settlementReq.setUnitTypeTwo(LogisticsUnitType.SHIPPER);
         return pageSelect(settlementReq);
     }
+
     /**
      * 查询贸易结算详情
      *
@@ -126,15 +127,15 @@ public class KwpSettlementLogisticsService {
         Integer payType = TradingEnum.getPrefix(trading);
         List<SettlementVo> settlementVoList = new ArrayList<>();
         if (Objects.nonNull(payType)) {
-            if(payType==TradingEnum.OFFLINE_PAY.getStatus()){
+            if (payType == TradingEnum.OFFLINE_PAY.getStatus()) {
                 settlementVoList = kwpSettlementOfflineService.queryList(id, SettlementOrderTypeEnum.LOGISTICS.getStatus(), payType);
-            }else {
+            } else {
                 settlementVoList = kwpSettlementWalletService.queryList(id, SettlementOrderTypeEnum.LOGISTICS.getStatus(), payType);
             }
         }
-        List<SettlementVo> settlementWallet = kwpSettlementWalletService.queryList(id, SettlementOrderTypeEnum.LOGISTICS.getStatus(), TradingEnum.getPrefix(trading));
         return new SettlementDetailDto<>(settlementLogisticsDto, settlementVoList);
     }
+
     /**
      * 运费收款-物流订单详情
      *
@@ -375,14 +376,15 @@ public class KwpSettlementLogisticsService {
     public List<String> checkOrder(Long entId, Long entTarget) {
         return settlementLogisticsMapper.selectJoin(entId, entTarget);
     }
+
     /**
      * @param entId    顶级企业id
-     * @param cur       当月/周
-     * @param pre       上月/周
+     * @param cur      当月/周
+     * @param pre      上月/周
      * @param unitType 企业类型 2-销售 1-采购
      */
     public List<MoneyType> moneySum(Long entId, List<LocalDateTime> cur, List<LocalDateTime> pre, Integer unitType) {
-        return settlementLogisticsMapper.sumMoneyType(entId,  cur, pre,  unitType);
+        return settlementLogisticsMapper.sumMoneyType(entId, cur, pre, unitType);
 
     }
 }

+ 6 - 6
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/PayCenterService.java

@@ -55,7 +55,7 @@ public class PayCenterService {
     }
 
     private String getHttp(PayCenterEnum payCenterEnum, Map<String, Object> para) {
-        log.debug("{}入参->{}", payCenterEnum.getDesc(), JSONObject.toJSONString(para));
+        log.info("{}入参->{}", payCenterEnum.getDesc(), JSONObject.toJSONString(para));
         OkHttpUtils okHttpUtils = OkHttpUtils.builder().url(payCenterAddr + payCenterEnum.getAddr());
         if (!CollectionUtils.isEmpty(para)) {
             for (Map.Entry<String, Object> p : para.entrySet()) {
@@ -90,12 +90,12 @@ public class PayCenterService {
             log.error("中台服务异常", e.getCause());
             throw new RuntimeException("支付服务异常!");
         }
-        log.debug("{}返回值->{}", payCenterEnum.getDesc(), sync);
+        log.info("{}返回值->{}", payCenterEnum.getDesc(), sync);
         return changeRes(sync);
     }
 
     private String postHttp(PayCenterEnum payCenterEnum, Map<String, Object> para) {
-        log.debug("{}入参->{}", payCenterEnum.getDesc(), JSONObject.toJSONString(para));
+        log.info("{}入参->{}", payCenterEnum.getDesc(), JSONObject.toJSONString(para));
         OkHttpUtils okHttpUtils = OkHttpUtils.builder().url(payCenterAddr + payCenterEnum.getAddr());
         if (!CollectionUtils.isEmpty(para)) {
             for (Map.Entry<String, Object> p : para.entrySet()) {
@@ -129,13 +129,13 @@ public class PayCenterService {
             log.error("中台服务异常", e.getCause());
             throw new RuntimeException("支付服务异常!");
         }
-        log.debug("{}返回值->{}", payCenterEnum.getDesc(), sync);
+        log.info("{}返回值->{}", payCenterEnum.getDesc(), sync);
         return changeRes(sync);
     }
 
     private String jsonHttp(PayCenterEnum payCenterEnum, Object object) {
         String para = object instanceof JSONObject jsonObject ? jsonObject.toJSONString() : JSONObject.toJSONString(object);
-        log.debug("{}入参->{}", payCenterEnum.getDesc(), para);
+        log.info("{}入参->{}", payCenterEnum.getDesc(), para);
         OkHttpUtils okHttpUtils = OkHttpUtils.builder().url(payCenterAddr + payCenterEnum.getAddr());
         okHttpUtils.addBodyJsonStr(para);
         String sync;
@@ -145,7 +145,7 @@ public class PayCenterService {
             log.error("中台服务异常", e.getCause());
             throw new RuntimeException("支付服务异常!");
         }
-        log.debug("{}返回值->{}", payCenterEnum.getDesc(), sync);
+        log.info("{}返回值->{}", payCenterEnum.getDesc(), sync);
         return changeRes(sync);
     }
 

+ 52 - 2
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletService.java

@@ -24,11 +24,11 @@ import com.sckw.payment.model.KwpWalletTransfer;
 import com.sckw.payment.model.constant.RefundEnum;
 import com.sckw.payment.model.constant.TransferEnum;
 import com.sckw.payment.model.constant.WalletChannelEnum;
+import com.sckw.payment.model.dto.WalletInfoDto;
 import com.sckw.payment.model.dto.common.BusinessNo;
 import com.sckw.payment.model.dto.page.CashPage;
 import com.sckw.payment.model.dto.page.PrePayWalletPage;
 import com.sckw.payment.model.dto.wallet.*;
-import com.sckw.payment.model.dto.wallet.ChannelStatistics;
 import com.sckw.payment.model.vo.PrePayWalletVo;
 import com.sckw.payment.model.vo.req.*;
 import com.sckw.payment.model.vo.res.*;
@@ -91,6 +91,13 @@ public class WalletService {
         return "";
     }
 
+    private Long getEnt(String id) {
+        if (StringUtils.isBlank(id)) {
+            return null;
+        }
+        return walletRelationService.getEnt(id);
+    }
+
     /**
      * 通过企业名称查询关联的中台用户id
      *
@@ -696,7 +703,9 @@ public class WalletService {
                     BeanUtils.copyProperties(row, prePayWalletVo);
                     prePayWalletVo.setApMoney(dfMoney(row.getApMoney()));
                     prePayWalletVo.setUidName(getFirmName(row.getUid()));
+                    prePayWalletVo.setUidEnt(getEnt(row.getUid()));
                     prePayWalletVo.setFilterName(getFirmName(row.getFilter()));
+                    prePayWalletVo.setFilterEnt(getEnt(row.getFilter()));
                     prePayWalletVo.setUsingApMoney(dfMoney(row.getUsingApMoney()));
                     prePayWalletVo.setSettlingApMoney(dfMoney(row.getSettlingApMoney()));
                     prePayWalletVo.setTotalApMoney(dfMoney(row.getTotalApMoney()));
@@ -799,7 +808,9 @@ public class WalletService {
                     BeanUtils.copyProperties(row, prePayWalletVo);
                     prePayWalletVo.setApMoney(dfMoney(row.getApMoney()));
                     prePayWalletVo.setUidName(getFirmName(row.getUid()));
+                    prePayWalletVo.setUidEnt(getEnt(row.getUid()));
                     prePayWalletVo.setFilterName(getFirmName(row.getFilter()));
+                    prePayWalletVo.setFilterEnt(getEnt(row.getFilter()));
                     prePayWalletVo.setUsingApMoney(dfMoney(row.getUsingApMoney()));
                     prePayWalletVo.setSettlingApMoney(dfMoney(row.getSettlingApMoney()));
                     prePayWalletVo.setTotalApMoney(dfMoney(row.getTotalApMoney()));
@@ -891,7 +902,15 @@ public class WalletService {
         if (Objects.isNull(data)) {
             throw new BusinessException("不存在交易");
         }
-        return data;
+        WalletInfoDto walletInfoDto = new WalletInfoDto();
+        walletInfoDto.setName(data.getName());
+        walletInfoDto.setWalletName(data.getWalletName());
+        walletInfoDto.setChannel(data.getChannel());
+        walletInfoDto.setStatus(data.getStatus());
+        walletInfoDto.setApMoney(walletInfoDto.smallMoney(data.getApMoney()));
+        walletInfoDto.setWdMoney(walletInfoDto.smallMoney(data.getWdMoney()));
+        walletInfoDto.setMoney(walletInfoDto.smallMoney(data.getMoney()));
+        return walletInfoDto;
     }
 
     /**
@@ -1019,6 +1038,37 @@ public class WalletService {
         return businessNoR;
     }
 
+    /**
+     * 发起退款校验
+     *
+     * @param refundReq
+     * @return
+     */
+    public Object refundCheck(RefundCheckReq refundReq) {
+        ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
+        if (Objects.isNull(channelEnum)) {
+            throw new BusinessException("支付通道不存在");
+        }
+        //发起退款是预收业务,uid和filter是相反的,查询时需要方向查询钱包
+        R<WalletInfo> walletInfoR = payCenterService.totalInfo(refundReq.getFilter(), channelEnum, refundReq.getUid());
+        if (!walletInfoR.getStatus()) {
+            throw new BusinessException(StringUtils.isNotBlank(walletInfoR.getMsg()) ? walletInfoR.getMsg() : "未找到交易方");
+        }
+        WalletInfo data = walletInfoR.getData();
+        if (Objects.isNull(data)) {
+            throw new BusinessException("不存在交易");
+        }
+        WalletInfoDto walletInfoDto = new WalletInfoDto();
+        walletInfoDto.setName(data.getName());
+        walletInfoDto.setWalletName(data.getWalletName());
+        walletInfoDto.setChannel(data.getChannel());
+        walletInfoDto.setStatus(data.getStatus());
+        walletInfoDto.setApMoney(walletInfoDto.smallMoney(data.getApMoney()));
+        walletInfoDto.setWdMoney(walletInfoDto.smallMoney(data.getWdMoney()));
+        walletInfoDto.setMoney(walletInfoDto.smallMoney(data.getMoney()));
+        return walletInfoDto;
+    }
+
     /**
      * 退款处理
      *