sptkw 2 лет назад
Родитель
Сommit
2141646577

+ 0 - 3
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/KwpSettlementOfflineController.java

@@ -55,9 +55,6 @@ public class KwpSettlementOfflineController {
         return HttpResult.ok(kwpSettlementOfflineService.pageListTradeCollection(settlementOfflineReq));
     }
 
-    @GetMapping(name = "交易-线下付款(销售收款)记录-新增", path = "confirmTradeCollection")
-    public HttpResult confirmTradeCollection(@RequestParam("id") Long id, @RequestParam("price") Float price) {
-        return HttpResult.ok(kwpSettlementOfflineService.confirmTradeCollection(id, price));
     /**
      * 销售收款-收款确认-线下付款
      *

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

@@ -62,8 +62,6 @@ public class KwpSettlementWalletController {
 
     /**
      * 采购-货到付款
-     * @param id    结算单id
-     * @param price 本次付款金额
      * @author Aick Spt
      * @date 2023-07-25 09:55
      */

+ 36 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/constant/SettlementWalletPayTypeEnum.java

@@ -0,0 +1,36 @@
+package com.sckw.payment.model.constant;
+
+/**
+ * Desc: 暂不明确是否使用
+ * @author Aick Spt
+ * @date 2023-07-20 08:35
+ */
+public enum SettlementWalletPayTypeEnum {
+    ADVANCE_PAYMENT(1, "预付款"),
+    CASH_ON_DELIVERY(2, "货到付款");
+//    OFFLINE_PAYMENT(3, "线下付款");
+
+    private int status;
+    private String desc;
+
+    SettlementWalletPayTypeEnum(int status, String desc) {
+        this.status = status;
+        this.desc = desc;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+}

+ 31 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementLogisticsService.java

@@ -13,15 +13,24 @@ import com.sckw.payment.model.dto.SettlementLogisticsDto;
 import com.sckw.payment.model.vo.req.SettlementReq;
 import com.sckw.payment.model.vo.res.SettlementLogisticsStatusCountVo;
 import com.sckw.payment.model.vo.res.SettlementLogisticsSumVo;
+import com.sckw.payment.model.vo.res.SettlementWalletVo;
 import com.sckw.payment.utils.CommonValidator;
 import com.sckw.payment.utils.PageMoreRes;
+import com.sckw.system.api.RemoteSystemService;
+import com.sckw.system.api.model.dto.res.UserCacheResDto;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * @author Aick Spt
@@ -31,6 +40,8 @@ import java.util.List;
 @Service
 @Slf4j
 public class KwpSettlementLogisticsService {
+    @DubboReference(version = "2.0.0", group = "design", check = false)
+    private RemoteSystemService remoteSystemService;
     private final KwpSettlementLogisticsMapper settlementLogisticsMapper;
 
     public void save(KwpSettlementLogistics settlementLogistics) {
@@ -202,6 +213,26 @@ public class KwpSettlementLogisticsService {
         }
         settlementLogisticsDto.setCreateByText("创建人名称");//"创建人名称"
         settlementLogisticsDto.setUpdateByText("更新人名称");//"更新人名称"
+
+        Map<Long, UserCacheResDto> map = new HashMap<>();
+        Long createBy = settlementLogisticsDto.getCreateBy();
+        Long updateBy = settlementLogisticsDto.getUpdateBy();
+        UserCacheResDto userCacheResDto = map.get(createBy);
+        if (Objects.isNull(userCacheResDto)) {
+            userCacheResDto = remoteSystemService.queryUserCacheById(createBy);
+            map.put(createBy, userCacheResDto);
+        }
+        if (Objects.nonNull(userCacheResDto)) {
+            settlementLogisticsDto.setCreateByText(userCacheResDto.getName());
+        }
+        userCacheResDto = map.get(updateBy);
+        if (Objects.isNull(userCacheResDto)) {
+            userCacheResDto = remoteSystemService.queryUserCacheById(updateBy);
+            map.put(updateBy, userCacheResDto);
+        }
+        if (Objects.nonNull(userCacheResDto)) {
+            settlementLogisticsDto.setUpdateByText(userCacheResDto.getName());
+        }
     }
 
 }

+ 35 - 5
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementOfflineService.java

@@ -5,16 +5,26 @@ import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
+import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.context.LoginUserHolder;
+import com.sckw.payment.dao.KwpSettlementLogisticsMapper;
+import com.sckw.payment.dao.KwpSettlementLogisticsTrackMapper;
 import com.sckw.payment.dao.KwpSettlementOfflineMapper;
+import com.sckw.payment.model.KwpSettlementLogistics;
+import com.sckw.payment.model.KwpSettlementLogisticsTrack;
 import com.sckw.payment.model.KwpSettlementOffline;
 import com.sckw.payment.model.KwpSettlementTrade;
+import com.sckw.payment.model.constant.SettlementEnum;
+import com.sckw.payment.model.constant.SettlementOrderTypeEnum;
 import com.sckw.payment.model.constant.TradingEnum;
+import com.sckw.payment.model.dto.SettlementLogisticsDto;
 import com.sckw.payment.model.dto.SettlementOfflineDto;
 import com.sckw.payment.model.dto.SettlementTradeDto;
+import com.sckw.payment.model.vo.req.OfflinePaymentReq;
 import com.sckw.payment.model.vo.req.SettlementOfflinePayReq;
 import com.sckw.payment.model.vo.req.SettlementOfflineReq;
 import com.sckw.payment.model.vo.res.SettlementOfflineVo;
+import com.sckw.payment.model.vo.res.SettlementWalletVo;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
 import jakarta.annotation.Resource;
@@ -47,11 +57,12 @@ public class KwpSettlementOfflineService {
     @DubboReference(version = "2.0.0", group = "design", check = false)
     private RemoteSystemService remoteSystemService;
 
-    private final KwpSettlementLogisticsService kwpSettlementLogisticsService;
-
-    private final KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
-
-    private final KwpSettlementLogisticsTrackMapper kwpSettlementLogisticsTrackMapper;
+    @Resource
+    private KwpSettlementLogisticsService kwpSettlementLogisticsService;
+    @Resource
+    private KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
+    @Resource
+    private KwpSettlementLogisticsTrackMapper kwpSettlementLogisticsTrackMapper;
 
     /**
      * 物流-线下付款(运费收款)记录-列表
@@ -78,10 +89,29 @@ public class KwpSettlementOfflineService {
             entity.setUpdateByText("更新人名称");
         }
 
+        Map<Long, UserCacheResDto> map = new HashMap<>();
         //指定返回值
         List<SettlementOfflineVo> collect = settlementOfflineLogisticsList.stream().map(a -> {
             SettlementOfflineVo settlementOfflineVo = new SettlementOfflineVo();
             BeanUtils.copyProperties(a, settlementOfflineVo);
+            Long createBy = a.getCreateBy();
+            Long updateBy = a.getUpdateBy();
+            UserCacheResDto userCacheResDto = map.get(createBy);
+            if (Objects.isNull(userCacheResDto)) {
+                userCacheResDto = remoteSystemService.queryUserCacheById(createBy);
+                map.put(createBy, userCacheResDto);
+            }
+            if (Objects.nonNull(userCacheResDto)) {
+                settlementOfflineVo.setCreateByText(userCacheResDto.getName());
+            }
+            userCacheResDto = map.get(updateBy);
+            if (Objects.isNull(userCacheResDto)) {
+                userCacheResDto = remoteSystemService.queryUserCacheById(updateBy);
+                map.put(updateBy, userCacheResDto);
+            }
+            if (Objects.nonNull(userCacheResDto)) {
+                settlementOfflineVo.setUpdateByText(userCacheResDto.getName());
+            }
             return settlementOfflineVo;
         }).collect(Collectors.toList());
 

+ 230 - 97
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementWalletService.java

@@ -64,7 +64,8 @@ public class KwpSettlementWalletService {
     @DubboReference(version = "2.0.0", group = "design", check = false)
     private RemoteSystemService remoteSystemService;
 
-    private final KwpSettlementLogisticsTrackMapper kwpSettlementLogisticsTrackMapper;
+    @Resource
+    private KwpSettlementLogisticsTrackMapper kwpSettlementLogisticsTrackMapper;
 
     /**
      * 物流-电子钱包付款(货到付款)结算记录-列表
@@ -73,11 +74,6 @@ public class KwpSettlementWalletService {
      * @date 2023-07-26 16:43
      */
     public PageRes<SettlementWalletVo> pageListLogisticsPayment(SettlementWalletReq settlementWalletReq) {
-//        //todo 查询缓存,获取客户企业id
-//        String keywords = settlementReq.getKeywords();
-//        if (StringUtils.isNotBlank(keywords)) {
-//            System.out.println("关键之:" + keywords);
-//        }
         PageHelper.startPage(settlementWalletReq.getPage(), settlementWalletReq.getPageSize());
         settlementWalletReq.setPayType(SettlementPayTypeEnum.CASH_ON_DELIVERY.getStatus());//只筛选 货到付款
         List<SettlementWalletDto> settlementWalletLogisticsList = settlementWalletMapper.pageListLogisticsPayment(settlementWalletReq);
@@ -91,10 +87,29 @@ public class KwpSettlementWalletService {
             entity.setUpdateByText("更新人名称");
         }
 
+        Map<Long, UserCacheResDto> map = new HashMap<>();
         //指定返回值
         List<SettlementWalletVo> collect = settlementWalletLogisticsList.stream().map(a -> {
             SettlementWalletVo settlementWalletVo = new SettlementWalletVo();
             BeanUtils.copyProperties(a, settlementWalletVo);
+            Long createBy = a.getCreateBy();
+            Long updateBy = a.getUpdateBy();
+            UserCacheResDto userCacheResDto = map.get(createBy);
+            if (Objects.isNull(userCacheResDto)) {
+                userCacheResDto = remoteSystemService.queryUserCacheById(createBy);
+                map.put(createBy, userCacheResDto);
+            }
+            if (Objects.nonNull(userCacheResDto)) {
+                settlementWalletVo.setCreateByText(userCacheResDto.getName());
+            }
+            userCacheResDto = map.get(updateBy);
+            if (Objects.isNull(userCacheResDto)) {
+                userCacheResDto = remoteSystemService.queryUserCacheById(updateBy);
+                map.put(updateBy, userCacheResDto);
+            }
+            if (Objects.nonNull(userCacheResDto)) {
+                settlementWalletVo.setUpdateByText(userCacheResDto.getName());
+            }
             return settlementWalletVo;
         }).collect(Collectors.toList());
 
@@ -116,8 +131,6 @@ public class KwpSettlementWalletService {
     /**
      * 物流-电子钱包付款(货到付款)结算记录-新增
      *
-     * @param id    结算单id
-     * @param price 付款金额
      * @return InsertId
      * @author Aick Spt
      * @date 2023-07-20 14:23
@@ -125,7 +138,9 @@ public class KwpSettlementWalletService {
      * Transactional// isolation:事务的隔离级别,此处使用后端数据库的默认隔离级别, propagation: 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中(常见)。(rollbackFor = Exception.class, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
      */
     @Transactional
-    public Integer confirmLogisticsPayment(Long id, BigDecimal price) {
+    public Integer confirmLogisticsPayment(OfflinePaymentReq offlinePaymentReq) {
+        Long id = offlinePaymentReq.getIdLong();
+        BigDecimal price = offlinePaymentReq.getPrice();
         //先查询出结算单情况
         SettlementLogisticsDto settlementLogisticsDto = kwpSettlementLogisticsService.detailPayment(id);
         log.info(String.valueOf(settlementLogisticsDto));
@@ -234,76 +249,102 @@ public class KwpSettlementWalletService {
 
 
     /**
-     * 销售-付款确认-(新增电子钱包记录-采购货到付款)
+     * 销售-付款确认-货到付款
      *
      * @author Aick Spt
      * @date 2023-07-27 16:13
      */
-    public Integer confirmTradePayment(OfflinePaymentReq offlinePaymentReq) {
-        //先查询出结算单情况
-        Long id = offlinePaymentReq.getIdLong();
-        BigDecimal price = offlinePaymentReq.getPrice();
-        SettlementTradeDto settlementTradeDto = kwpSettlementTradeService.detailPayment(id);
-        log.info(String.valueOf(settlementTradeDto));
-        //检查结算单状态和所差金额
-        if (settlementTradeDto == null) {
-            log.error("非法请求,查无数据:" + id);
-            throw new BusinessException("非法请求运费结算参数ID");
-        }
-        if (settlementTradeDto.getStatus() == SettlementEnum.ALL_PAYMENT.getStatus()) {
-            log.error("非法请求,该订单已结算完成:" + id);
-            throw new BusinessException("该订单已结算完成,无法操作");
-        }
-        BigDecimal remainingReceivables = settlementTradeDto.getTotalPrice();
-        if (settlementTradeDto.getActualPrice() != null) {//剩余金额
-            remainingReceivables = settlementTradeDto.getTotalPrice().subtract(settlementTradeDto.getActualPrice());
-        }
-
-        if (remainingReceivables.compareTo(price) < 0) {//-1表示小于,0是等于,1是大于
-            log.error("本次结算输入金额比剩余付款金额大:ID:" + id + " 剩余金额:" + remainingReceivables + " 本次输入金额:" + price);
-            throw new BusinessException("参数错误:输入金额过大 " + price + " 剩余金额最大值:" + remainingReceivables);
-        }
-        //累加入库结算单
-        KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
-        kwpSettlementTrade.setId(settlementTradeDto.getId());
-        kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
-        if (remainingReceivables.compareTo(price) == 0) {//全部结算
-            kwpSettlementTrade.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
-        }
-        if (remainingReceivables.compareTo(price) > 0) {//部分结算
-            kwpSettlementTrade.setStatus(SettlementEnum.PARTIAL_PAYMENT.getStatus());
-        }
-        BigDecimal actualPrice = settlementTradeDto.getActualPrice();
-        kwpSettlementTrade.setActualPrice((actualPrice == null) ? price : actualPrice.add(price));
-        int upInt = kwpSettlementTradeMapper.updateById(kwpSettlementTrade);
-        if (upInt > 0) {
-            //新增一条电子钱包结算记录
-            remainingReceivables = remainingReceivables.subtract(price);
-            KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
-            kwpSettlementWallet.setId(new IdWorker(1).nextId());
-            kwpSettlementWallet.setEntId(settlementTradeDto.getEntId());
-            kwpSettlementWallet.setSettlementId(settlementTradeDto.getId());
-            kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
-            kwpSettlementWallet.setChannel(WalletChannelEnum.HF.getStatus());//先用数字默认定义为1
-            kwpSettlementWallet.setPayTime(LocalDateTime.now());
-            kwpSettlementWallet.setPayPrice(price);
-            kwpSettlementWallet.setTopayPrice(remainingReceivables);
-            kwpSettlementWallet.setType(SettlementPayTypeEnum.CASH_ON_DELIVERY.getStatus());
-            kwpSettlementWallet.setRemark("");
-            kwpSettlementWallet.setStatus(1);
-            kwpSettlementWallet.setCreateBy(1L);//todo 待处理明确创建人
-            kwpSettlementWallet.setCreateTime(LocalDateTime.now());
-            kwpSettlementWallet.setUpdateBy(1L);//todo 待处理明确更新人
-            kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
-            kwpSettlementWallet.setDelFlag(0);
-            Integer insertKwpSettlementWallet = settlementWalletMapper.insert(kwpSettlementWallet);
-
-            //物流货到付款电子钱包逻辑
-            //todo 待处理费电子钱包逻辑
-
-            return insertKwpSettlementWallet;
+    @Transactional(rollbackFor = Exception.class)
+    public String confirmTradePayment(WalletPayReq walletPayReq) {
+        String key = String.format(RedisConstant.SETTLEMENT_KEY, walletPayReq.getId());
+        if (redisLockUtil.tryLock(key)) {
+            try {
+                SettlementTradeDto byId = kwpSettlementTradeService.getById(walletPayReq.getIdLong(), TradeUnitType.SELL);
+                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 = kwpSettlementTradeService.getListById(walletPayReq.getIdLong());
+                if (CollectionUtils.isEmpty(listById) || listById.size() != 2) {
+                    throw new BusinessException("对账单交易企业双方不存在或缺少");
+                }
+                Long uid = null;
+                Long filter = null;
+                for (LedgerUnitDto ledgerUnitDto : listById) {
+                    Integer unitType = ledgerUnitDto.getUnitType();
+                    if (TradeUnitType.PURCHASE.equals(unitType)) {
+                        uid = ledgerUnitDto.getTopEntId();
+                        continue;
+                    }
+                    if (TradeUnitType.SELL.equals(unitType)) {
+                        filter = ledgerUnitDto.getTopEntId();
+                    }
+                }
+                String relation = walletRelationService.getRelation(uid);
+                String filterUser = walletRelationService.getRelation(filter);
+                if (StringUtils.isBlank(relation) || StringUtils.isBlank(filterUser)) {
+                    throw new BusinessException("顶级企业未开通电子钱包");
+                }
+                //付款金额
+                BigDecimal price = walletPayReq.getPrice();
+                //todo-xcq-完善
+
+//        R<List<WalletDto>> wallet = payCenterService.wallet(relation, ChannelEnum.getByCode(byId.getTrading()), filterUser);
+//        if (CollectionUtils.isEmpty(wallet.getData())) {
+//            throw new BusinessException("暂未开通电子钱包");
+//        }
+//        List<WalletDto> data = wallet.getData();
+//        BigDecimal bigDecimal = BigDecimal.valueOf(data.get(0).getMoney()).divide(new BigDecimal("100.0"), RoundingMode.UNNECESSARY);
+//
+//        if (bigDecimal.compareTo(price) < 0) {
+//            throw new BusinessException("钱包可用余额不足");
+//        }
+                //待付款金额-本次付款金额= 剩余待付款金额
+                BigDecimal subtract = byId.getWaitPrice().subtract(walletPayReq.getPrice());
+                if (subtract.compareTo(new BigDecimal("0.0")) < 0) {
+                    throw new BusinessException("付款金额不能大于待付款金额");
+                }
+                //新增电子钱包结算记录
+                KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
+                kwpSettlementWallet.setId(new IdWorker(1).nextId());
+                kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
+                kwpSettlementWallet.setSettlementId(walletPayReq.getIdLong());
+                kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
+                kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
+                kwpSettlementWallet.setPayTime(LocalDateTime.now());
+                kwpSettlementWallet.setPayPrice(walletPayReq.getPrice());
+                kwpSettlementWallet.setTopayPrice(subtract);
+                kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
+                kwpSettlementWallet.setRemark("");
+                kwpSettlementWallet.setStatus(0);
+                kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setCreateTime(LocalDateTime.now());
+                kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
+                kwpSettlementWallet.setDelFlag(0);
+                settlementWalletMapper.insert(kwpSettlementWallet);
+
+                //更新交易结算单状态和金额
+                KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
+                kwpSettlementTrade.setId(byId.getId());
+                kwpSettlementTrade.setActualPrice(byId.getActualPrice().add(price));
+                kwpSettlementTrade.setStatus(subtract.compareTo(new BigDecimal("0.0")) == 0 ? SettlementEnum.ALL_PAYMENT.getStatus()
+                        : SettlementEnum.PARTIAL_PAYMENT.getStatus());
+                kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
+                kwpSettlementTradeService.updateById(kwpSettlementTrade);
+
+                settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.RECEIVE_PAY.getStatus()));
+                //todo-xcq 调用中台接口
+
+                return "付款确认成功";
+            } finally {
+                redisLockUtil.unlock(key);
+            }
         }
-        return null;
+        return "请勿重复提交!";
     }
 
     /**
@@ -350,11 +391,6 @@ public class KwpSettlementWalletService {
     }
 
     public PageRes<SettlementWalletVo> pageListTradeCollection(SettlementWalletReq settlementWalletReq) {
-//        //todo 查询缓存,获取客户企业id
-//        String keywords = settlementReq.getKeywords();
-//        if (StringUtils.isNotBlank(keywords)) {
-//            System.out.println("关键之:" + keywords);
-//        }
         PageHelper.startPage(settlementWalletReq.getPage(), settlementWalletReq.getPageSize());
 
         List<SettlementWalletDto> settlementWalletLogisticsList = settlementWalletMapper.pageListLogisticsPayment(settlementWalletReq);
@@ -367,36 +403,133 @@ public class KwpSettlementWalletService {
             return new PageRes<>(new PageInfo<>());
         }
 
+        Map<Long, UserCacheResDto> map = new HashMap<>();
         //指定返回值
         List<SettlementWalletVo> collect = settlementWalletLogisticsList.stream().map(a -> {
             SettlementWalletVo settlementWalletVo = new SettlementWalletVo();
             BeanUtils.copyProperties(a, settlementWalletVo);
+            Long createBy = a.getCreateBy();
+            Long updateBy = a.getUpdateBy();
+            UserCacheResDto userCacheResDto = map.get(createBy);
+            if (Objects.isNull(userCacheResDto)) {
+                userCacheResDto = remoteSystemService.queryUserCacheById(createBy);
+                map.put(createBy, userCacheResDto);
+            }
+            if (Objects.nonNull(userCacheResDto)) {
+                settlementWalletVo.setCreateByText(userCacheResDto.getName());
+            }
+            userCacheResDto = map.get(updateBy);
+            if (Objects.isNull(userCacheResDto)) {
+                userCacheResDto = remoteSystemService.queryUserCacheById(updateBy);
+                map.put(updateBy, userCacheResDto);
+            }
+            if (Objects.nonNull(userCacheResDto)) {
+                settlementWalletVo.setUpdateByText(userCacheResDto.getName());
+            }
             return settlementWalletVo;
         }).collect(Collectors.toList());
 
         return new PageRes<>(new PageInfo<>(collect));
     }
 
+    /**
+     * 销售-预付款
+     *
+     * @param id
+     * @return
+     */
+    public String confirmTradeCollection(Long id) {
+        String key = String.format(RedisConstant.SETTLEMENT_KEY, id);
+
+        if (redisLockUtil.tryLock(key)) {
+            try {
+                SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.PURCHASE);
+                if (Objects.isNull(byId)) {
+                    throw new BusinessException("结算单不存在");
+                }
+                if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
+                    throw new BusinessException("只支持预付款交易方式进行预付款确认操作");
+                }
+                //更新交易结算单状态和金额
+                KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
+                kwpSettlementTrade.setId(byId.getId());
+                kwpSettlementTrade.setActualPrice(byId.getTotalPrice());
+                kwpSettlementTrade.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
+                kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
+                kwpSettlementTradeService.updateById(kwpSettlementTrade);
+                //新增电子钱包结算记录
+                KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
+                kwpSettlementWallet.setId(new IdWorker(1).nextId());
+                kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
+                kwpSettlementWallet.setSettlementId(byId.getId());
+                kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
+                kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
+                kwpSettlementWallet.setPayTime(LocalDateTime.now());
+                kwpSettlementWallet.setPayPrice(byId.getTotalPrice());
+                kwpSettlementWallet.setTopayPrice(new BigDecimal("0.0"));
+                kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.ADVANCE_PAYMENT.getStatus());
+                kwpSettlementWallet.setRemark("");
+                kwpSettlementWallet.setStatus(0);
+                kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setCreateTime(LocalDateTime.now());
+                kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
+                kwpSettlementWallet.setDelFlag(0);
+                settlementWalletMapper.insert(kwpSettlementWallet);
+                settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.PRE_PAY.getStatus()));
+                //todo-xcq 调用中台接口
+                //todo-xcq 调用订单接口,更新订单状态
+                return "确认回款成功";
+            } finally {
+                redisLockUtil.unlock(key);
+            }
+        }
+        return "请勿重复提交!";
 
-    public Integer confirmTradeCollection(Long id, Float price) {
-        log.info("接收到数据,开始物流-销售-收款确认-预付款(电子钱包)-新增,待完善");
-        //todo 待完善
-        //先查询出结算单情况
-
-        //检查结算单状态和所差金额
-
-        //对比金额
-
-        //累加入库结算单
-
-        //扣费电子钱包
+    }
 
-        //新增电子钱包结算记录
-        KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
-        kwpSettlementWallet.setId(new IdWorker(1).nextId());
-        //todo 待完善
-        settlementWalletMapper.insert(kwpSettlementWallet);
-        return settlementWalletMapper.confirmLogisticsPayment(id, price);
+    /**
+     * 电子钱包余额
+     *
+     * @param id
+     * @return
+     */
+    public BigDecimal getConfirmTradePayment(Long id) {
+        SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.SELL);
+        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 = kwpSettlementTradeService.getListById(id);
+        if (CollectionUtils.isEmpty(listById) || listById.size() != 2) {
+            throw new BusinessException("对账单交易企业双方不存在或缺少");
+        }
+        Long uid = null;
+        Long filter = null;
+        for (LedgerUnitDto ledgerUnitDto : listById) {
+            Integer unitType = ledgerUnitDto.getUnitType();
+            if (TradeUnitType.PURCHASE.equals(unitType)) {
+                uid = ledgerUnitDto.getTopEntId();
+                continue;
+            }
+            if (TradeUnitType.SELL.equals(unitType)) {
+                filter = ledgerUnitDto.getTopEntId();
+            }
+        }
+        String relation = walletRelationService.getRelation(uid);
+        String filterUser = walletRelationService.getRelation(filter);
+        if (StringUtils.isBlank(relation) || StringUtils.isBlank(filterUser)) {
+            throw new BusinessException("顶级企业未开通电子钱包");
+        }
+        R<List<WalletDto>> wallet = payCenterService.wallet(relation, ChannelEnum.getByCode(byId.getTrading()), filterUser);
+        if (CollectionUtils.isEmpty(wallet.getData())) {
+            throw new BusinessException("暂未开通电子钱包");
+        }
+        List<WalletDto> data = wallet.getData();
+        return BigDecimal.valueOf(data.get(0).getMoney() / 100.0);
     }
 }
 

+ 3 - 0
sckw-modules/sckw-payment/src/main/resources/META-INF/MANIFEST.MF

@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.sckw.payment.PaymentApplication
+