Parcourir la source

物流结算,增加调用中台清分接口逻辑 、校验付款金额是否超过钱包可用余额、清分金额

xucaiqin il y a 2 ans
Parent
commit
5d87b3d986

+ 5 - 5
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/KwpSettlementWalletController.java

@@ -36,11 +36,11 @@ public class KwpSettlementWalletController {
         return HttpResult.ok(kwpSettlementWalletService.pageListLogisticsPayment(settlementWalletReq));
     }
 
-    @GetMapping(name = "物流-电子钱包付款(货到付款)结算记录-详情", path = "detailLogisticsPayment")
-    public HttpResult detailLogisticsPayment(@RequestParam("id") Long id) {
-//        return HttpResult.ok(kwpSettlementWalletService.detailLogisticsPayment(id));
-        return HttpResult.ok(null);
-    }
+//    @GetMapping(name = "物流-电子钱包付款(货到付款)结算记录-详情", path = "detailLogisticsPayment")
+//    public HttpResult detailLogisticsPayment(@RequestParam("id") Long id) {
+////        return HttpResult.ok(kwpSettlementWalletService.detailLogisticsPayment(id));
+//        return HttpResult.ok(null);
+//    }
 
     /**
      * @author Aick Spt

+ 7 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/dao/KwpLedgerTradeMapper.java

@@ -65,6 +65,13 @@ public interface KwpLedgerTradeMapper extends BaseMapper<KwpLedgerTrade> {
 
     List<LedgerPurchaseDto> selectPurchaseIds(@Param("ids") List<Long> ids);
 
+    /**
+     * app端对账统计
+     *
+     * @param tradeReq
+     * @param status
+     * @return
+     */
     LedgerCountSumVo countSum(@Param("tradeReq") TradeReq tradeReq, @Param("status") List<Integer> status);
 
     void updatePrice(@Param("id") Long id, @Param("totalPrice") BigDecimal totalPrice);

+ 3 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/constant/PayCenterEnum.java

@@ -14,7 +14,8 @@ public enum PayCenterEnum {
     MEMBER_WALLET("/v1/member/wallet", "钱包清单"),
     MEMBER_WALLET_V2("/v2/member/wallet", "钱包清单v2"),
     MEMBER_GENERAL("/v2/wallet/general", "总览信息"),
-    WITHDRAW_DETAIL("/v1/wallet/withdraw/detail", "提现详情"),
+    WITHDRAW_DETAIL("/v2/wallet/withdraw/detail", "提现详情"),
+    //    WITHDRAW_DETAIL("/v1/wallet/withdraw/detail", "提现详情"), 原接口
     //    WITHDRAW_INDEX("/v1/wallet/withdraw/index", "提现清单"), 原接口
     WITHDRAW_INDEX("/v2/wallet/withdraw/index", "提现清单"),
     WITHDRAW_CATEGORY("/v2/wallet/withdraw/categories", "提现清单分类"),
@@ -40,6 +41,7 @@ public enum PayCenterEnum {
     MEMBER_PAY_INDEX("/v1/member/pay/index", "订单记录"),
     MEMBER_INDEX("/v1/member/index", "创建/更新账户"),
     PAY_INDEX("/v1/pay/index", "在线充值"),
+    RECHARGE_ORDER("/v2/wallet/recharge/orders", "充值记录清单"),
     WALLET_FREEZE("/v1/wallet/freeze", "冻结资金"),
     WALLET_UNFREEZE("/v1/wallet/unfreeze", "解冻金额"),
     PAY_AGENT_PAY("/v1/pay/agent_pay", "清分"),

+ 5 - 2
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/wallet/PatchPay.java

@@ -1,7 +1,7 @@
 package com.sckw.payment.model.dto.wallet;
 
 import com.alibaba.fastjson.annotation.JSONField;
-import lombok.Data;
+import lombok.*;
 
 import java.io.Serial;
 import java.io.Serializable;
@@ -10,7 +10,10 @@ import java.io.Serializable;
  * @author xucaiqin
  * @date 2023-07-25 17:09:42
  */
-@Data
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
 public class PatchPay implements Serializable {
     @Serial
     private static final long serialVersionUID = -719246443006291337L;

+ 64 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/wallet/Recharge.java

@@ -0,0 +1,64 @@
+package com.sckw.payment.model.dto.wallet;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class Recharge implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 5266898999492496164L;
+    @JSONField(name = "uid")
+    private String uid;
+
+    @JSONField(name = "order_no")
+    private String orderNo;
+
+    @JSONField(name = "status")
+    private int status;
+
+    @JSONField(name = "status_label")
+    private String statusLabel;
+
+
+    @JSONField(name = "channel")
+    private String channel;
+
+    @JSONField(name = "channel_label")
+    private String channelLabel;
+    /**
+     * 往来单位uid
+     */
+    @JSONField(name = "filter")
+    private String filter;
+
+    /**
+     * 充值金额
+     */
+    @JSONField(name = "money")
+    private BigDecimal money;
+    /**
+     * 充值到账后余额
+     */
+    @JSONField(name = "after_money")
+    private BigDecimal afterMoney;
+
+    @JSONField(name = "remarks")
+    private String remarks;
+    /**
+     * 订单提交时间
+     */
+    @JSONField(name = "create_time")
+    private String createTime;
+    /**
+     * 支付完成时间
+     */
+    @JSONField(name = "pay_time")
+    private String payTime;
+}

+ 18 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/wallet/RechargePage.java

@@ -0,0 +1,18 @@
+package com.sckw.payment.model.dto.wallet;
+
+import com.sckw.payment.model.dto.common.Page;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serial;
+
+/**
+ * @author xucaiqin
+ * @date 2023-07-25 16:30:37
+ */
+@Getter
+@Setter
+public class RechargePage extends Page<Recharge> {
+    @Serial
+    private static final long serialVersionUID = 8527382562920050885L;
+}

+ 17 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/req/CashDetailReq.java

@@ -0,0 +1,17 @@
+package com.sckw.payment.model.vo.req;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 详细记录提现
+ *
+ * @author xucaiqin
+ * @date 2023-09-20 10:16:12
+ */
+@Getter
+@Setter
+public class CashDetailReq {
+    private String uid;
+    private String orderNo;
+}

+ 5 - 3
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/res/WalletDetailBase.java

@@ -15,7 +15,7 @@ import java.time.LocalDateTime;
  */
 @Getter
 @Setter
-public class WalletDetailBase {
+public class WalletDetailBase implements MoneyChange {
     /**
      * 业务流水号
      */
@@ -49,6 +49,8 @@ public class WalletDetailBase {
     /**
      * 创建时间
      */
-    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
-    private LocalDateTime createTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private String createTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private String payTime;
 }

+ 136 - 107
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementWalletService.java

@@ -9,6 +9,7 @@ import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
+import com.sckw.core.utils.OrderUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.order.api.dubbo.TradeOrderInfoService;
@@ -69,6 +70,7 @@ public class KwpSettlementWalletService {
     private final KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
     private final KwpLedgerTradeOrderService tradeOrderService;
     private final KwpSettlementLogisticsService kwpSettlementLogisticsService;
+    private final WalletBusinessService walletBusinessService;
     @Resource
     private KwpSettlementTradeService kwpSettlementTradeService;
     private final PayCenterService payCenterService;
@@ -165,7 +167,7 @@ public class KwpSettlementWalletService {
      * <p>
      * Transactional// isolation:事务的隔离级别,此处使用后端数据库的默认隔离级别, propagation: 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中(常见)。(rollbackFor = Exception.class, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
      */
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public Integer confirmLogisticsPayment(OfflinePaymentReq offlinePaymentReq) {
         Long id = offlinePaymentReq.getIdLong();
         BigDecimal price = offlinePaymentReq.getPrice();
@@ -175,7 +177,6 @@ public class KwpSettlementWalletService {
         if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
             throw new BusinessException("结算参数金额必填");
         }
-
         //先查询出结算单情况
         SettlementLogisticsDto settlementLogisticsDto = kwpSettlementLogisticsService.detailPayment(id);
         //检查结算单状态和所差金额
@@ -198,84 +199,107 @@ public class KwpSettlementWalletService {
             log.error("本次结算输入金额比剩余付款金额大:ID:" + id + " 剩余金额:" + remainingReceivables + " 本次输入金额:" + price);
             throw new BusinessException("参数错误:输入金额过大 " + price + " 剩余金额最大值:" + remainingReceivables);
         }
-        //累加入库结算单
-        KwpSettlementLogistics settlementLogistics = new KwpSettlementLogistics();
-        settlementLogistics.setId(settlementLogisticsDto.getId());
-        settlementLogistics.setUpdateTime(LocalDateTime.now());
-        //全部结算
-        if (remainingReceivables.compareTo(price) == 0) {
-            settlementLogistics.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
-        }
-        //部分结算
-        if (remainingReceivables.compareTo(price) > 0) {
-            settlementLogistics.setStatus(SettlementEnum.PARTIAL_PAYMENT.getStatus());
-        }
-        BigDecimal actualPrice = settlementLogisticsDto.getActualPrice();
-        settlementLogistics.setActualPrice((actualPrice == null) ? price : actualPrice.add(price));
-        int upInt = kwpSettlementLogisticsMapper.updateById(settlementLogistics);
-        if (upInt > 0) {
-            //新增一条修改记录
-            String remark = LoginUserHolder.getUserName() + "[" + LoginUserHolder.getUserId() + "]" + "结算[" + settlementLogistics.getId() + "]" + settlementLogistics.getActualPrice() + "(" + SettlementEnum.getStatusDesc(settlementLogistics.getStatus()) + ")";
-            KwpSettlementLogisticsTrack kwpSettlementLogisticsTrack = new KwpSettlementLogisticsTrack();
-            kwpSettlementLogisticsTrack.setId(new IdWorker(1).nextId());
-            kwpSettlementLogisticsTrack.setLSettlementId(settlementLogistics.getId());
-            kwpSettlementLogisticsTrack.setRemark(remark);
-            kwpSettlementLogisticsTrack.setStatus(settlementLogistics.getStatus());
-            kwpSettlementLogisticsTrack.setCreateBy(LoginUserHolder.getUserId());
-            kwpSettlementLogisticsTrack.setCreateTime(LocalDateTime.now());
-            kwpSettlementLogisticsTrack.setUpdateBy(LoginUserHolder.getUserId());
-            kwpSettlementLogisticsTrack.setUpdateTime(LocalDateTime.now());
-            kwpSettlementLogisticsTrack.setDelFlag(0);
-            kwpSettlementLogisticsTrackMapper.insert(kwpSettlementLogisticsTrack);
-
-            //新增一条电子钱包结算记录
-            remainingReceivables = remainingReceivables.subtract(price);
-            KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
-            kwpSettlementWallet.setId(new IdWorker(1).nextId());
-            kwpSettlementWallet.setEntId(settlementLogisticsDto.getEntId());
-            kwpSettlementWallet.setSettlementId(settlementLogisticsDto.getId());
-            kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
-            //先用数字默认定义为1
-            kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(settlementLogisticsDto.getTrading()));
-            kwpSettlementWallet.setPayTime(LocalDateTime.now());
-            kwpSettlementWallet.setPayPrice(price);
-            kwpSettlementWallet.setTopayPrice(remainingReceivables);
-            kwpSettlementWallet.setType(SettlementPayTypeEnum.CASH_ON_DELIVERY.getStatus());
-            kwpSettlementWallet.setRemark(Global.EMPTY_STRING);
-            kwpSettlementWallet.setStatus(1);
-            kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
-            kwpSettlementWallet.setCreateTime(LocalDateTime.now());
-            kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
-            kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
-            kwpSettlementWallet.setDelFlag(0);
-            Integer insertKwpSettlementWallet = settlementWalletMapper.insert(kwpSettlementWallet);
-            log.info("新增一条电子钱包结算记录:" + insertKwpSettlementWallet);
-            //需要将金额同步到对应的对账表中
-            KwpLedgerLogistics kwpLedgerLogistics = new KwpLedgerLogistics();
-            kwpLedgerLogistics.setId(settlementLogisticsDto.getLLedgerId());
-            kwpLedgerLogistics.setActualPrice(settlementLogistics.getActualPrice());
-            kwpLedgerLogisticsMapper.updateById(kwpLedgerLogistics);
-
-            //物流货到付款电子钱包逻辑
-            //todo 待处理费电子钱包逻辑
-
-            return insertKwpSettlementWallet;
-        }
-
         //托运方
         KwpLedgerLogisticsUnit logisticsUnit = logisticsUnitService.queryCustomerEnt(settlementLogisticsDto.getLLedgerId(), LogisticsUnitType.SHIPPER);
-        //承运方
+        //承运方(对账发起方,收钱方)
         KwpLedgerLogisticsUnit logisticsUnit2 = logisticsUnitService.queryCustomerEnt(settlementLogisticsDto.getLLedgerId(), LogisticsUnitType.CARRIER);
-
-        //推送双方系统管理员
-        messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
-            put("company", logisticsUnit.getFirmName());
-            put("number", settlementLogisticsDto.getSlOrderNo());
-        }}, logisticsUnit2.getEntId(), MessageEnum.SETTLEMENT_START_CARRIER);
-        messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
-            put("company", logisticsUnit2.getFirmName());
-            put("number", settlementLogisticsDto.getSlOrderNo());
-        }}, logisticsUnit.getEntId(), MessageEnum.SETTLEMENT_START_SHIPPER);
+        String uid = walletRelationService.getRelation(logisticsUnit.getTopEntId());
+        if (StringUtils.isBlank(uid)) {
+            throw new BusinessException("我方单位暂未开通电子钱包");
+        }
+        String filter = walletRelationService.getRelation(logisticsUnit2.getTopEntId());
+        if (StringUtils.isBlank(filter)) {
+            throw new BusinessException("客户单位暂未开通电子钱包");
+        }
+        String trading = settlementLogisticsDto.getTrading();
+        ChannelEnum channelEnum = ChannelEnum.getByTrading(trading);
+        if (Objects.isNull(channelEnum)) {
+            throw new BusinessException("交易方式异常");
+        }
+        //加锁
+        String key = String.format(RedisConstant.SETTLEMENT_KEY, offlinePaymentReq.getId());
+        if (redisLockUtil.tryLock(key)) {
+            try {
+                //钱包余额校验
+                walletBusinessService.checkMoney(uid, filter, channelEnum, price);
+                //累加入库结算单
+                KwpSettlementLogistics settlementLogistics = new KwpSettlementLogistics();
+                settlementLogistics.setId(settlementLogisticsDto.getId());
+                settlementLogistics.setUpdateTime(LocalDateTime.now());
+                //全部结算
+                if (remainingReceivables.compareTo(price) == 0) {
+                    settlementLogistics.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
+                }
+                //部分结算
+                if (remainingReceivables.compareTo(price) > 0) {
+                    settlementLogistics.setStatus(SettlementEnum.PARTIAL_PAYMENT.getStatus());
+                }
+                BigDecimal actualPrice = settlementLogisticsDto.getActualPrice();
+                settlementLogistics.setActualPrice((actualPrice == null) ? price : actualPrice.add(price));
+                int upInt = kwpSettlementLogisticsMapper.updateById(settlementLogistics);
+                if (upInt > 0) {
+                    //新增一条修改记录
+                    String remark = LoginUserHolder.getUserName() + "[" + LoginUserHolder.getUserId() + "]" + "结算[" + settlementLogistics.getId() + "]" + settlementLogistics.getActualPrice() + "(" + SettlementEnum.getStatusDesc(settlementLogistics.getStatus()) + ")";
+                    KwpSettlementLogisticsTrack kwpSettlementLogisticsTrack = new KwpSettlementLogisticsTrack();
+                    kwpSettlementLogisticsTrack.setId(new IdWorker(1).nextId());
+                    kwpSettlementLogisticsTrack.setLSettlementId(settlementLogistics.getId());
+                    kwpSettlementLogisticsTrack.setRemark(remark);
+                    kwpSettlementLogisticsTrack.setStatus(settlementLogistics.getStatus());
+                    kwpSettlementLogisticsTrack.setCreateBy(LoginUserHolder.getUserId());
+                    kwpSettlementLogisticsTrack.setCreateTime(LocalDateTime.now());
+                    kwpSettlementLogisticsTrack.setUpdateBy(LoginUserHolder.getUserId());
+                    kwpSettlementLogisticsTrack.setUpdateTime(LocalDateTime.now());
+                    kwpSettlementLogisticsTrack.setDelFlag(0);
+                    kwpSettlementLogisticsTrackMapper.insert(kwpSettlementLogisticsTrack);
+
+                    //新增一条电子钱包结算记录
+                    String orderNo = OrderUtils.generateOrderNo("SL");
+                    remainingReceivables = remainingReceivables.subtract(price);
+                    KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
+                    kwpSettlementWallet.setId(new IdWorker(1).nextId());
+                    kwpSettlementWallet.setEntId(settlementLogisticsDto.getEntId());
+                    kwpSettlementWallet.setOrderNo(orderNo);
+                    kwpSettlementWallet.setSettlementId(settlementLogisticsDto.getId());
+                    kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
+                    //先用数字默认定义为1
+                    kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(settlementLogisticsDto.getTrading()));
+                    kwpSettlementWallet.setPayTime(LocalDateTime.now());
+                    kwpSettlementWallet.setPayPrice(price);
+                    kwpSettlementWallet.setTopayPrice(remainingReceivables);
+                    kwpSettlementWallet.setType(SettlementPayTypeEnum.CASH_ON_DELIVERY.getStatus());
+                    kwpSettlementWallet.setRemark(Global.EMPTY_STRING);
+                    kwpSettlementWallet.setStatus(1);
+                    kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
+                    kwpSettlementWallet.setCreateTime(LocalDateTime.now());
+                    kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
+                    kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
+                    kwpSettlementWallet.setDelFlag(0);
+                    Integer insertKwpSettlementWallet = settlementWalletMapper.insert(kwpSettlementWallet);
+                    log.info("新增一条电子钱包结算记录:" + insertKwpSettlementWallet);
+                    //需要将金额同步到对应的对账表中
+                    KwpLedgerLogistics kwpLedgerLogistics = new KwpLedgerLogistics();
+                    kwpLedgerLogistics.setId(settlementLogisticsDto.getLLedgerId());
+                    kwpLedgerLogistics.setActualPrice(settlementLogistics.getActualPrice());
+                    kwpLedgerLogisticsMapper.updateById(kwpLedgerLogistics);
+
+                    // 调用电子钱包进行清分操作
+                    walletBusinessService.splitMoney(orderNo, uid, filter, channelEnum, price, "2");
+
+                    //推送双方系统管理员
+                    messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
+                        put("company", logisticsUnit.getFirmName());
+                        put("number", settlementLogisticsDto.getSlOrderNo());
+                    }}, logisticsUnit2.getEntId(), MessageEnum.SETTLEMENT_START_CARRIER);
+                    messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
+                        put("company", logisticsUnit2.getFirmName());
+                        put("number", settlementLogisticsDto.getSlOrderNo());
+                    }}, logisticsUnit.getEntId(), MessageEnum.SETTLEMENT_START_SHIPPER);
+                    return insertKwpSettlementWallet;
+                }
+            } finally {
+                redisLockUtil.unlock(key);
+            }
+        }
         return null;
     }
 
@@ -393,8 +417,7 @@ public class KwpSettlementWalletService {
                 KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
                 kwpSettlementTrade.setId(byId.getId());
                 kwpSettlementTrade.setActualPrice(byId.getActualPrice().add(price));
-                int status = subtract.compareTo(new BigDecimal("0.0")) == NumberConstant.ZERO ? SettlementEnum.ALL_PAYMENT.getStatus()
-                        : SettlementEnum.PARTIAL_PAYMENT.getStatus();
+                int status = subtract.compareTo(new BigDecimal("0.0")) == NumberConstant.ZERO ? SettlementEnum.ALL_PAYMENT.getStatus() : SettlementEnum.PARTIAL_PAYMENT.getStatus();
                 kwpSettlementTrade.setStatus(status);
                 kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
                 kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
@@ -617,33 +640,38 @@ public class KwpSettlementWalletService {
 
     }
 
+    /**
+     * 物流,货到付款(付钱方) 查询电子钱余额
+     *
+     * @param id
+     * @return
+     */
     public WalletDto getConfirmLogisticsPayment(Long id) {
-        //todo
-        WalletDto walletDto = new WalletDto();
-        walletDto.setName("测试钱宝");
-        walletDto.setMemberName("");
-        walletDto.setUid("kll_0001");
-        walletDto.setChannel("1");
-        walletDto.setCreateTime(LocalDateTime.now());
-        walletDto.setFilter("kll_0002");
-        walletDto.setFreeze(0L);
-        walletDto.setApMoney(0L);
-        walletDto.setTotalMoney(12000L);
-        walletDto.setMoney(1L);
-
-        return walletDto;
-//        SettlementLogisticsDto byId = kwpSettlementLogisticsService.detail(id, LogisticsUnitType.CARRIER, LogisticsUnitType.SHIPPER);
-//        if (Objects.isNull(byId)) {
-//            throw new BusinessException("结算单不存在");
-//        }
-//        if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
-//            throw new BusinessException("只支持货货到付款方式订单进行当前操作");
-//        }
-//        List<LedgerUnitDto> listById = kwpSettlementLogisticsService.getListById(id);
-//        if (CollectionUtils.isEmpty(listById) || listById.size() != NumberConstant.TWO) {
-//            throw new BusinessException("对账单交易企业双方不存在或缺少");
-//        }
-//        return getWalletBalance(listById, byId.getTrading());
+//        WalletDto walletDto = new WalletDto();
+//        walletDto.setName("测试钱宝");
+//        walletDto.setMemberName("");
+//        walletDto.setUid("kll_0001");
+//        walletDto.setChannel("1");
+//        walletDto.setCreateTime(LocalDateTime.now());
+//        walletDto.setFilter("kll_0002");
+//        walletDto.setFreeze(0L);
+//        walletDto.setApMoney(0L);
+//        walletDto.setTotalMoney(12000L);
+//        walletDto.setMoney(1L);
+//
+//        return walletDto;
+        SettlementLogisticsDto byId = kwpSettlementLogisticsService.detail(id, LogisticsUnitType.CARRIER, LogisticsUnitType.SHIPPER);
+        if (Objects.isNull(byId)) {
+            throw new BusinessException("结算单不存在");
+        }
+        if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
+            throw new BusinessException("只支持货货到付款方式订单进行当前操作");
+        }
+        List<LedgerUnitDto> listById = kwpSettlementLogisticsService.getListById(id);
+        if (CollectionUtils.isEmpty(listById) || listById.size() != NumberConstant.TWO) {
+            throw new BusinessException("对账单交易企业双方不存在或缺少");
+        }
+        return getWalletBalance(listById, byId.getTrading());
     }
 
 
@@ -705,7 +733,7 @@ public class KwpSettlementWalletService {
 //        return BigDecimal.valueOf(data.get(NumberConstant.ZERO).getMoney() / 100.0);
     }
 
-    private BigDecimal getWalletBalance(List<LedgerUnitDto> listById, String trading) {
+    private WalletDto getWalletBalance(List<LedgerUnitDto> listById, String trading) {
         Long uid = null;
         Long filter = null;
         for (LedgerUnitDto ledgerUnitDto : listById) {
@@ -728,7 +756,8 @@ public class KwpSettlementWalletService {
             throw new BusinessException("暂未开通电子钱包");
         }
         List<WalletDto> data = wallet.getData();
-        return BigDecimal.valueOf(data.get(NumberConstant.ZERO).getMoney() / 100.0);
+        return data.get(0);
+//        return BigDecimal.valueOf(data.get(NumberConstant.ZERO).getMoney() / 100.0);
     }
 
     /**

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

@@ -237,11 +237,10 @@ public class PayCenterService {
      * 提现详情
      *
      * @param uid
-     * @param view
      * @param orderNo
      * @return
      */
-    public R<CashDetail> withdrawDetail(String uid, String view, String orderNo) {
+    public R<CashDetail> withdrawDetail(String uid, String orderNo) {
         if (StringUtils.isBlank(uid)) {
             throw new BusinessException("提现用户不能为空");
         }
@@ -250,7 +249,6 @@ public class PayCenterService {
         }
         String sync = getHttp(PayCenterEnum.WITHDRAW_DETAIL, new HashMap<>() {{
             put("uid", uid);
-            put("view", view);
             put("order_no", orderNo);
         }});
         return JSONObject.parseObject(sync, new TypeReference<>() {
@@ -721,6 +719,38 @@ public class PayCenterService {
         return parseArray(sync, SplitDto.class);
     }
 
+    /**
+     * 充值订单详情
+     *
+     * @param uid
+     * @param startDate
+     * @param endDate
+     * @param keyword
+     * @param page
+     * @param pageSize
+     * @return
+     */
+    public R<RechargePage> rechargeOrder(String uid, String startDate, String endDate, String keyword, Integer page, Integer pageSize) {
+        if (Objects.isNull(page)) {
+            page = 1;
+        }
+        if (Objects.isNull(pageSize)) {
+            pageSize = 5;
+        }
+        Integer finalPage = page;
+        Integer finalPageSize = pageSize;
+        String sync = getHttp(PayCenterEnum.RECHARGE_ORDER, new HashMap<>() {{
+            put("uid", uid);
+            put("keyword", keyword);
+            put("startDate", startDate);
+            put("endDate", endDate);
+            put("page", finalPage);
+            put("pageSize", finalPageSize);
+        }});
+        return JSONObject.parseObject(sync, new TypeReference<>() {
+        });
+    }
+
     /**
      * 创建/更新账户
      *

+ 75 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletBusinessService.java

@@ -0,0 +1,75 @@
+package com.sckw.payment.service;
+
+import com.sckw.core.exception.BusinessException;
+import com.sckw.core.utils.StringUtils;
+import com.sckw.payment.api.model.constant.ChannelEnum;
+import com.sckw.payment.api.model.dto.common.R;
+import com.sckw.payment.model.dto.common.BusinessNo;
+import com.sckw.payment.model.dto.wallet.PatchPay;
+import com.sckw.payment.model.dto.wallet.WalletInfo;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author xucaiqin
+ * @date 2023-09-20 15:04:06
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class WalletBusinessService {
+    private final PayCenterService payCenterService;
+
+    /**
+     * 校验付款金额是否超过钱包可用余额
+     *
+     * @param uid         支付方
+     * @param filter      收款方
+     * @param channelEnum 渠道
+     * @param price       支付金额 元
+     */
+    public void checkMoney(String uid, String filter, ChannelEnum channelEnum, BigDecimal price) {
+        R<WalletInfo> walletInfoR = payCenterService.totalInfo(uid, channelEnum, filter);
+        if (!walletInfoR.getStatus()) {
+            throw new BusinessException(StringUtils.isNotBlank(walletInfoR.getMsg()) ? walletInfoR.getMsg() : "双方企业暂未开通电子钱包");
+        }
+        //钱包余额校验
+        WalletInfo data = Objects.isNull(walletInfoR.getData()) ? new WalletInfo() : walletInfoR.getData();
+        //可用余额 分
+        BigDecimal money = data.getMoney();
+        //付款金额大于钱包可用余额
+        if (price.compareTo(money.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP)) > 0) {
+            log.error("付款金额:{} 钱包可用余额:{}", price, money);
+            throw new BusinessException("钱包可用余额不足");
+        }
+    }
+
+    /**
+     * 清分金额
+     *
+     * @param businessNo  流水号
+     * @param uid
+     * @param filter
+     * @param channelEnum
+     * @param price       清分金额
+     * @param payType     支付方式 支付类型0-默认1-仅预付支付2-仅余额支付
+     */
+    public void splitMoney(String businessNo, String uid, String filter, ChannelEnum channelEnum, BigDecimal price, String payType) {
+        long value = price.multiply(new BigDecimal("100")).longValueExact();
+        List<PatchPay> split = new ArrayList<>() {{
+            add(new PatchPay(filter, value, uid + "清分" + value + "至" + filter));
+        }};
+        R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(uid, filter, channelEnum, value, split, businessNo, payType);
+        if (!businessNoR.getStatus()) {
+            log.error("流水号:{} uid:{} filter:{} channel:{} price:{} payType:{}", businessNoR, uid, filter, channelEnum, price, payType);
+            throw new BusinessException("清分失败异常");
+        }
+    }
+}

+ 60 - 25
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletService.java

@@ -81,6 +81,20 @@ public class WalletService {
     @DubboReference(version = "1.0.0", group = "design", check = false)
     private RemoteManageService remoteManageService;
 
+    /**
+     * 填充时间等参数
+     *
+     * @param tradeReq 请求参数
+     */
+    private void fillPara(MoneyPage tradeReq) {
+        if (StringUtils.isNotBlank(tradeReq.getStartCreateTime())) {
+            tradeReq.setStartCreateTime(StringTimeUtil.fillStart(tradeReq.getStartCreateTime()));
+        }
+        if (StringUtils.isNotBlank(tradeReq.getEndCreateTime())) {
+            tradeReq.setEndCreateTime(StringTimeUtil.fillEnd(tradeReq.getEndCreateTime()));
+        }
+    }
+
     /**
      * 通过中台用户id转为企业名称
      *
@@ -1268,26 +1282,36 @@ public class WalletService {
      * @return
      */
     public PageRes<ChargeDetailVo> rechargeList(MoneyPage moneyPage) {
-        ChargeDetailVo chargeDetailVo = new ChargeDetailVo();
-        chargeDetailVo.setBalance(new BigDecimal("0"));
-        chargeDetailVo.setOrderNo("");
-        chargeDetailVo.setChannel("");
-        chargeDetailVo.setChannelDict("");
-        chargeDetailVo.setChannelLabel("");
-        chargeDetailVo.setUid("");
-        chargeDetailVo.setUidName("");
-        chargeDetailVo.setFilter("");
-        chargeDetailVo.setFilterName("");
-        chargeDetailVo.setStatus(0);
-        chargeDetailVo.setStatusLabel("");
-        chargeDetailVo.setMoney(new BigDecimal("0"));
-        chargeDetailVo.setRemark("");
-        chargeDetailVo.setCreateTime(LocalDateTime.now());
-        List<ChargeDetailVo> objects = new ArrayList<>() {{
-            add(chargeDetailVo);
-        }};
-        PageInfo<ChargeDetailVo> objectPageInfo = new PageInfo<>();
-        return new PageRes<>(objectPageInfo, objects);
+        fillPara(moneyPage);
+        R<RechargePage> rechargePageR = payCenterService.rechargeOrder(moneyPage.getUid(), moneyPage.getStartCreateTime(), moneyPage.getEndCreateTime(), moneyPage.getKeywords(), moneyPage.getPage(), moneyPage.getPageSize());
+        if (!rechargePageR.getStatus()) {
+            throw new BusinessException(StringUtils.isBlank(rechargePageR.getMsg()) ? "查询失败" : rechargePageR.getMsg());
+        }
+        RechargePage data = rechargePageR.getData();
+        List<Recharge> rows = data.getRows();
+        if (!CollectionUtils.isEmpty(rows)) {
+            List<ChargeDetailVo> collect = rows.stream().map(a -> {
+                ChargeDetailVo chargeDetailVo = new ChargeDetailVo();
+                chargeDetailVo.setOrderNo(a.getOrderNo());
+                chargeDetailVo.setChannel(a.getChannel());
+                chargeDetailVo.setChannelDict(ChannelEnum.getDict(a.getChannel()));
+                chargeDetailVo.setChannelLabel(ChannelEnum.getDesc(a.getChannel()));
+                chargeDetailVo.setUid(a.getUid());
+                chargeDetailVo.setUidName(getFirmName(a.getUid()));
+                chargeDetailVo.setFilter(a.getFilter());
+                chargeDetailVo.setFilterName(getFirmName(a.getFilter()));
+                chargeDetailVo.setStatus(a.getStatus());
+                chargeDetailVo.setStatusLabel(a.getStatusLabel());
+                chargeDetailVo.setMoney(chargeDetailVo.smallMoney(a.getMoney()));
+                chargeDetailVo.setBalance(chargeDetailVo.smallMoney(a.getAfterMoney()));
+                chargeDetailVo.setRemark(a.getRemarks());
+                chargeDetailVo.setCreateTime(a.getCreateTime());
+                chargeDetailVo.setPayTime(a.getPayTime());
+                return chargeDetailVo;
+            }).collect(Collectors.toList());
+            return new PageRes<>(moneyPage.getPage(), moneyPage.getPageSize(), data.getTotal(), (int) (data.getTotal() / data.getPageSize() + 1), collect);
+        }
+        return new PageRes<>(moneyPage.getPage(), moneyPage.getPageSize(), 0, 0, new ArrayList<>());
     }
 
     /**
@@ -1310,7 +1334,7 @@ public class WalletService {
         chargeDetailVo.setStatusLabel("");
         chargeDetailVo.setMoney(new BigDecimal("0"));
         chargeDetailVo.setRemark("");
-        chargeDetailVo.setCreateTime(LocalDateTime.now());
+//        chargeDetailVo.setCreateTime(LocalDateTime.now());
         List<WalletDetailBase> objects = new ArrayList<>() {{
             add(chargeDetailVo);
         }};
@@ -1338,7 +1362,7 @@ public class WalletService {
         chargeDetailVo.setStatusLabel("");
         chargeDetailVo.setMoney(new BigDecimal("0"));
         chargeDetailVo.setRemark("");
-        chargeDetailVo.setCreateTime(LocalDateTime.now());
+//        chargeDetailVo.setCreateTime(LocalDateTime.now());
         List<WalletDetailBase> objects = new ArrayList<>() {{
             add(chargeDetailVo);
         }};
@@ -1367,7 +1391,7 @@ public class WalletService {
         chargeDetailVo.setStatusLabel("");
         chargeDetailVo.setMoney(new BigDecimal("0"));
         chargeDetailVo.setRemark("");
-        chargeDetailVo.setCreateTime(LocalDateTime.now());
+//        chargeDetailVo.setCreateTime(LocalDateTime.now());
         List<ChargeDetailVo> objects = new ArrayList<>() {{
             add(chargeDetailVo);
         }};
@@ -1395,7 +1419,7 @@ public class WalletService {
         chargeDetailVo.setStatusLabel("");
         chargeDetailVo.setMoney(new BigDecimal("0"));
         chargeDetailVo.setRemark("");
-        chargeDetailVo.setCreateTime(LocalDateTime.now());
+//        chargeDetailVo.setCreateTime(LocalDateTime.now());
         List<WalletDetailBase> objects = new ArrayList<>() {{
             add(chargeDetailVo);
         }};
@@ -1423,7 +1447,7 @@ public class WalletService {
         chargeDetailVo.setStatusLabel("");
         chargeDetailVo.setMoney(new BigDecimal("0"));
         chargeDetailVo.setRemark("");
-        chargeDetailVo.setCreateTime(LocalDateTime.now());
+//        chargeDetailVo.setCreateTime(LocalDateTime.now());
         List<WalletDetailBase> objects = new ArrayList<>() {{
             add(chargeDetailVo);
         }};
@@ -1431,6 +1455,17 @@ public class WalletService {
         return new PageRes<>(objectPageInfo, objects);
     }
 
+    /**
+     * 详细记录-提现
+     *
+     * @param cashDetailReq
+     * @return
+     */
+    public String cashDetail(CashDetailReq cashDetailReq) {
+        payCenterService.withdrawDetail(cashDetailReq.getUid(), cashDetailReq.getOrderNo());
+        return null;
+    }
+
     /**
      * 退款处理
      *