xucaiqin 2 timmar sedan
förälder
incheckning
c44245bbf5
15 ändrade filer med 450 tillägg och 155 borttagningar
  1. 31 1
      sckw-modules-api/sckw-payment-api/src/main/java/com/sckw/payment/api/feign/PaymentFeignService.java
  2. 37 0
      sckw-modules-api/sckw-payment-api/src/main/java/com/sckw/payment/api/model/feign/WalletAgentDto.java
  3. 13 13
      sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/operateService/KwcContractLogisticsService.java
  4. 68 34
      sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/operateService/KwcContractTradeService.java
  5. 22 10
      sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTradeOrderService.java
  6. 38 21
      sckw-modules/sckw-order/src/main/java/com/sckw/order/task/TradeOrderTask.java
  7. 22 5
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentController.java
  8. 2 2
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentRecordController.java
  9. 16 1
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletPrepaidController.java
  10. 5 5
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/entity/WalletAgentBalance.java
  11. 21 1
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentManualDto.java
  12. 2 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/IWalletPrepaidService.java
  13. 7 1
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletService.java
  14. 158 61
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/impl/WalletAgentService.java
  15. 8 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/impl/WalletPrepaidServiceImpl.java

+ 31 - 1
sckw-modules-api/sckw-payment-api/src/main/java/com/sckw/payment/api/feign/PaymentFeignService.java

@@ -1,8 +1,9 @@
 package com.sckw.payment.api.feign;
 
 import com.sckw.core.web.response.BaseResult;
-import com.sckw.payment.api.model.feign.WalletPrepaidDto;
+import com.sckw.payment.api.model.feign.WalletAgentDto;
 import com.sckw.payment.api.model.feign.WalletPayableDto;
+import com.sckw.payment.api.model.feign.WalletPrepaidDto;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @FeignClient(name = "sckw-ng-payment",contextId = "paymentFeignService")
 public interface PaymentFeignService {
@@ -29,6 +31,11 @@ public interface PaymentFeignService {
      */
     @PostMapping("/walletPrepaid/updatePrepaidBalance")
     BaseResult<Object> updatePrepaidBalance(@RequestBody WalletPrepaidDto prepaidDto);
+    /**
+     * 预付清单冻结、解冻、消费接口
+     */
+    @PostMapping("/walletPrepaid/batchUpdatePrepaidBalance")
+    BaseResult<Object> batchUpdatePrepaidBalance(@RequestBody List<WalletPrepaidDto> prepaidDto);
 
     /**
      * 初始化运费清单
@@ -43,4 +50,27 @@ public interface PaymentFeignService {
     BaseResult<Object> updatePayable(@RequestBody @Validated WalletPayableDto payableUpdateDto);
 
 
+    /*代理相关*/
+    /**
+     * 初始化代理清单
+     */
+    @PostMapping("/walletAgent/initAgentBalance")
+    BaseResult<Object> initAgentBalance(@RequestBody WalletAgentDto prepaidDto);
+
+
+    /**
+     * 代理 冻结、解冻、消费接口
+     */
+    @PostMapping("/walletAgent/updateAgentBalance")
+    BaseResult<Object> updateAgentBalance(@RequestBody WalletAgentDto agentDto);
+
+    /**
+     * 代理 冻结、解冻、消费接口
+     */
+    @PostMapping("/walletAgent/batchUpdateAgentBalance")
+    BaseResult<Object> batchUpdateAgentBalance(@RequestBody List<WalletAgentDto> agentDto);
+
+
+
+
 }

+ 37 - 0
sckw-modules-api/sckw-payment-api/src/main/java/com/sckw/payment/api/model/feign/WalletAgentDto.java

@@ -0,0 +1,37 @@
+package com.sckw.payment.api.model.feign;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class WalletAgentDto {
+    @Schema(description = "代理商企业id")
+    private Long agtEntId;
+    //供应商id
+    @Schema(description = "供应商企业id")
+    private Long supEntId;
+    //关联订单编号
+    @Schema(description = "关联订单编号")
+    private String orderNo;
+
+    /** 订单类型 2-预付订单  4-贸易订单 */
+    @Schema(description = "订单类型 2-预付订单  4-贸易订单")
+    private Integer orderType;
+
+
+    /** 交易类型 2-预付 3-收益 4-冻结 5-解冻 6-消费 9-人工录入 */
+    @NotNull(message = "交易类型不能为空")
+    @Schema(description = "交易类型 2-预付 3-收益 4-冻结 5-解冻 6-消费 9-人工录入")
+    private Integer tradeType;
+
+    //交易金额
+    @Schema(description = "交易金额")
+    private BigDecimal tradeAmount;
+
+    //备注
+    @Schema(description = "备注")
+    private String remark;
+}

+ 13 - 13
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/operateService/KwcContractLogisticsService.java

@@ -1839,17 +1839,17 @@ public class KwcContractLogisticsService {
                 contractIdList.clear();
                 return contractIdList;
             }
-            
+
             // 查询可见企业下的所有物流合同单位
             List<KwcContractLogisticsUnit> permUnits =
                     kwcContractLogisticsUnitRepository.queryByEntIds(new ArrayList<>(perm.getVisibleEntIds()), null);
-            
+
             // 提取这些单位关联的合同ID
             Set<Long> entScopeContractIds = permUnits.stream()
                     .map(KwcContractLogisticsUnit::getContractId)
                     .filter(Objects::nonNull)
                     .collect(Collectors.toSet());
-            
+
             // 取交集:只保留在可见企业范围内的合同
             int beforeSize = contractIdList.size();
             contractIdList.retainAll(entScopeContractIds);
@@ -1869,17 +1869,17 @@ public class KwcContractLogisticsService {
                 contractIdList.clear();
                 return contractIdList;
             }
-            
+
             log.debug("开启个人数据权限过滤, 校验销售员ID: {}", uid);
             // 通过关联的贸易合同销售员进行过滤
             Set<Long> salesMatched = retainLogisticsContractIdsByLinkedTradeSalesman(contractIdList, uid);
-            
+
             // 更新原列表为过滤后的结果
             contractIdList.clear();
             contractIdList.addAll(salesMatched);
             log.debug("个人数据权限过滤完成, 最终合同数量: {}", contractIdList.size());
         }
-        
+
         return contractIdList;
     }
 
@@ -1912,7 +1912,7 @@ public class KwcContractLogisticsService {
                 .map(RWaybillSubOrderVo::getTradeId)
                 .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
-        
+
         if (CollectionUtils.isEmpty(tradeOrderIds)) {
             log.debug("运单中未包含有效的贸易订单ID");
             return Collections.emptySet();
@@ -1948,18 +1948,18 @@ public class KwcContractLogisticsService {
             if (CollectionUtils.isEmpty(relTradeContractIds)) {
                 continue;
             }
-            
+
             // 只要有一个关联的贸易合同的销售员是指定用户,则该物流合同可见
             boolean ok = relTradeContractIds.stream()
                     .map(tradeMap::get)
                     .filter(Objects::nonNull)
                     .anyMatch(t -> salesmanUserId.equals(t.getSalesmanId()));
-            
+
             if (ok) {
                 result.add(logId);
             }
         }
-        
+
         log.debug("销售员权限过滤结束, 匹配到的物流合同数: {}", result.size());
         return result;
     }
@@ -1983,17 +1983,17 @@ public class KwcContractLogisticsService {
             if (link.getLogContractId() == null || link.getTradeId() == null) {
                 continue;
             }
-            
+
             // 获取运单关联的贸易订单对应的贸易合同ID
             Long tradeContractId = tradeOrderIdToContractId.get(link.getTradeId());
             if (tradeContractId == null) {
                 continue;
             }
-            
+
             // 将贸易合同ID加入该物流合同对应的集合中
             result.computeIfAbsent(link.getLogContractId(), k -> new HashSet<>()).add(tradeContractId);
         }
-        
+
         log.debug("构建物流合同-贸易合同映射完成, 映射数量: {}", result.size());
         return result;
     }

+ 68 - 34
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/operateService/KwcContractTradeService.java

@@ -46,6 +46,7 @@ import com.sckw.order.api.dubbo.TradeOrderInfoService;
 import com.sckw.order.api.model.ContractSignCompletedParam;
 import com.sckw.order.api.model.TradeOrderContractVo;
 import com.sckw.payment.api.feign.PaymentFeignService;
+import com.sckw.payment.api.model.feign.WalletAgentDto;
 import com.sckw.payment.api.model.feign.WalletPrepaidDto;
 import com.sckw.product.api.dubbo.GoodsInfoService;
 import com.sckw.product.api.model.KwpGoods;
@@ -1593,22 +1594,55 @@ public class KwcContractTradeService {
         Boolean result = kwcContractTradeRepository.updateByContractId(updateKwcContractTrade);
         if (Objects.equals(req.getStatus(), ContractStatusEnum.SIGNED.getCode()) && Objects.equals(updateKwcContractTrade.getStatus(), ContractStatusEnum.SIGNED.getCode())) {
             //签约成功,初始化预付清单
-            //根据订单号查询交易企业信息
             List<KwcContractTradeUnit> tradeUnits = kwcContractTradeUnitRepository.queryByContractId(kwcContractTrade.getId());
-            Map<Integer, KwcContractTradeUnit> collect = tradeUnits.stream().collect(Collectors.toMap(KwcContractTradeUnit::getUnitType, Function.identity(), (x, y) -> x));
-            WalletPrepaidDto prepaidDto = new WalletPrepaidDto();
-            prepaidDto.setProEntId(collect.get(CooperateTypeEnum.PURCHASER.getCode()).getEntId());
-            prepaidDto.setSupEntId(collect.get(CooperateTypeEnum.SUPPLIER.getCode()).getEntId());
-            prepaidDto.setTradeAmount(BigDecimal.ZERO);
-            prepaidDto.setRemark("预付清单初始化");
-            log.info("采购商:{}与供应商:{}签订贸易合同,预付清单初始化",prepaidDto.getProEntId(),prepaidDto.getSupEntId());
-            BaseResult<Object> prepaidResult = paymentFeignService.initPrepaidBalance(prepaidDto);
-            if (prepaidResult.getCode() == HttpStatus.SUCCESS_CODE) {
-                log.info("创建预付清单成功");
+
+            if (Objects.equals(kwcContractTrade.getAgentFlag(), 1)) {//代理合同。
+                Map<Integer, KwcContractTradeUnit> collect = tradeUnits.stream().collect(Collectors.toMap(KwcContractTradeUnit::getUnitType, Function.identity(), (x, y) -> x));
+                WalletPrepaidDto prepaidDto = new WalletPrepaidDto();
+                prepaidDto.setProEntId(collect.get(CooperateTypeEnum.PURCHASER.getCode()).getEntId());//买方
+                prepaidDto.setSupEntId(collect.get(3).getEntId());//代理商
+                prepaidDto.setTradeAmount(BigDecimal.ZERO);
+                prepaidDto.setRemark("预付清单初始化");
+                log.info("采购商:{}与代理商:{}签订贸易合同,预付清单初始化", prepaidDto.getProEntId(), prepaidDto.getSupEntId());
+                BaseResult<Object> prepaidResult = paymentFeignService.initPrepaidBalance(prepaidDto);
+                if (prepaidResult.getCode() == HttpStatus.SUCCESS_CODE) {
+                    log.info("创建预付清单成功");
+                } else {
+                    log.error("创建预付清单失败");
+                    throw new BusinessException("创建预付清单失败");
+                }
+                WalletAgentDto walletAgentDto = new WalletAgentDto();
+                walletAgentDto.setSupEntId(collect.get(CooperateTypeEnum.SUPPLIER.getCode()).getEntId());//供应商
+                walletAgentDto.setAgtEntId(collect.get(3).getEntId());//代理商
+                walletAgentDto.setTradeAmount(BigDecimal.ZERO);
+                walletAgentDto.setRemark("代理清单初始化");
+                log.info("代理商:{}与供应商:{}签订贸易合同,代理清单初始化", walletAgentDto.getAgtEntId(), prepaidDto.getSupEntId());
+                BaseResult<Object> objectBaseResult = paymentFeignService.initAgentBalance(walletAgentDto);
+                if (objectBaseResult.getCode() == HttpStatus.SUCCESS_CODE) {
+                    log.info("创建代理清单成功");
+                } else {
+                    log.error("创建代理清单失败");
+                    throw new BusinessException("创建代理清单失败");
+                }
             } else {
-                log.error("创建预付清单失败");
-                throw new BusinessException("创建预付清单失败");
+                //根据订单号查询交易企业信息
+                Map<Integer, KwcContractTradeUnit> collect = tradeUnits.stream().collect(Collectors.toMap(KwcContractTradeUnit::getUnitType, Function.identity(), (x, y) -> x));
+                WalletPrepaidDto prepaidDto = new WalletPrepaidDto();
+                prepaidDto.setProEntId(collect.get(CooperateTypeEnum.PURCHASER.getCode()).getEntId());
+                prepaidDto.setSupEntId(collect.get(CooperateTypeEnum.SUPPLIER.getCode()).getEntId());
+                prepaidDto.setTradeAmount(BigDecimal.ZERO);
+                prepaidDto.setRemark("预付清单初始化");
+                log.info("采购商:{}与供应商:{}签订贸易合同,预付清单初始化", prepaidDto.getProEntId(), prepaidDto.getSupEntId());
+                BaseResult<Object> prepaidResult = paymentFeignService.initPrepaidBalance(prepaidDto);
+                if (prepaidResult.getCode() == HttpStatus.SUCCESS_CODE) {
+                    log.info("创建预付清单成功");
+                } else {
+                    log.error("创建预付清单失败");
+                    throw new BusinessException("创建预付清单失败");
+                }
             }
+
+
         }
         return result;
 
@@ -1957,7 +1991,7 @@ public class KwcContractTradeService {
         if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getPurchaseEntId())) {
             Long purchaseEntId = Long.valueOf(req.getPurchaseEntId());
             log.debug("应用采购方过滤条件: purchaseEntId = {}", purchaseEntId);
-            
+
             Set<Long> purchaseContractIds = units.stream()
                     .filter(unit -> Objects.equals(unit.getEntId(), purchaseEntId))
                     // 必须明确 unitType 为 PURCHASER (采购方)
@@ -1965,7 +1999,7 @@ public class KwcContractTradeService {
                     .map(KwcContractTradeUnit::getContractId)
                     .filter(Objects::nonNull)
                     .collect(Collectors.toSet());
-            
+
             // 取交集:合同必须同时出现在当前企业的合同列表 和 指定采购方的合同列表中
             int beforeSize = contractIds.size();
             contractIds.retainAll(purchaseContractIds);
@@ -1984,7 +2018,7 @@ public class KwcContractTradeService {
                     .map(KwcContractTradeUnit::getContractId)
                     .filter(Objects::nonNull)
                     .collect(Collectors.toSet());
-            
+
             // 取交集
             int beforeSize = contractIds.size();
             contractIds.retainAll(supplyContractIds);
@@ -2007,7 +2041,7 @@ public class KwcContractTradeService {
             log.debug("代理单位过滤后剩余合同数量: {} (原数量: {})", contractIds.size(), beforeSize);
         }
 
-        log.info("最终构建的合同ID集合大小: {}, entId: {}, purchaseEntId: {}, supplyEntId: {}", 
+        log.info("最终构建的合同ID集合大小: {}, entId: {}, purchaseEntId: {}, supplyEntId: {}",
                 contractIds.size(), entId, req.getPurchaseEntId(), req.getSupplyEntId());
         return contractIds;
     }
@@ -2263,9 +2297,9 @@ public class KwcContractTradeService {
      * 2. 根据托运方企业ID查询其关联的物流合同单位,获取合同ID集合。
      * 3. 根据商品ID筛选出包含该商品的物流合同ID集合(用于后续过滤非通用价格合同)。
      * 4. 查询物流合同主表信息,并进行过滤:
-     *    - 保留“指定商品关联的合同”或“拥有通用价格的合同”。
-     *    - 状态必须为“已签约”。
-     *    - 当前时间必须在合同有效期内(处理结束时间为空的情况,视为永久有效)。
+     * - 保留“指定商品关联的合同”或“拥有通用价格的合同”。
+     * - 状态必须为“已签约”。
+     * - 当前时间必须在合同有效期内(处理结束时间为空的情况,视为永久有效)。
      * 5. 组装返回结果,填充托运方、承运方信息及商品价格(优先使用特定商品价格,其次使用通用价格)。
      * 6. 特殊处理:如果传入了贸易合同ID,且该贸易合同满足“买家托运”且“按装货量结算”的条件,则在结果列表首位插入一条“平台默认物流”记录。
      * </p>
@@ -2293,7 +2327,7 @@ public class KwcContractTradeService {
             log.debug("未找到企业[{}]关联的物流合同单位,返回空列表", logisticsOrderDto.getEntId());
             return Collections.emptyList();
         }
-        
+
         // 提取物流合同ID集合
         Set<Long> logTradeContractIds = contractLogisticsUnits.stream()
                 .map(KwcContractLogisticsUnit::getContractId)
@@ -2335,7 +2369,7 @@ public class KwcContractTradeService {
                 .filter(x -> finalGoodsContractIds.contains(x.getId()) || Objects.nonNull(x.getCommonPrice()))
                 .distinct()
                 .collect(Collectors.toList());
-        
+
         if (CollectionUtils.isEmpty(logistics)) {
             log.debug("经过商品/通用价格过滤后,剩余物流合同数量为0,返回空列表");
             return Collections.emptyList();
@@ -2354,11 +2388,11 @@ public class KwcContractTradeService {
                     }
                 })
                 .filter(log -> Objects.nonNull(log.getStartTime()) && Objects.nonNull(log.getEndTime()))
-                .filter(log -> 
-                    // 状态必须为已签约
-                    Objects.equals(log.getStatus(), ContractStatusEnum.SIGNED.getCode())
-                    // 当前时间必须在开始时间之后(或等于)
-                    && !log.getStartTime().after(date) && !log.getEndTime().before(date)
+                .filter(log ->
+                        // 状态必须为已签约
+                        Objects.equals(log.getStatus(), ContractStatusEnum.SIGNED.getCode())
+                                // 当前时间必须在开始时间之后(或等于)
+                                && !log.getStartTime().after(date) && !log.getEndTime().before(date)
                 )
                 .collect(Collectors.toList());
 
@@ -2515,7 +2549,7 @@ public class KwcContractTradeService {
         if (Objects.equals(entType, CooperateTypeEnum.SUPPLIER.getCode())) {
             log.debug("当前查询类型为供应方(Supplier),进入销售员专属查询逻辑。entId: {}, goodsId: {}",
                     contractTradeOrderDto.getEntId(), contractTradeOrderDto.getGoodsId());
-            
+
             // 调用专用方法,内部会过滤 salesmanId = 当前登录用户ID 且状态为已签约的合同
             return querySalesmanSignedTradeOrder(contractTradeOrderDto, contractIds, contractTradeUnitMap);
         }
@@ -2523,11 +2557,11 @@ public class KwcContractTradeService {
         // 场景B:其他类型(主要是采购方 Purchaser)
         // 业务规则:采购商查看合同时,需限制在当前登录企业范围内,且角色为采购方(unitType=2)
         log.debug("当前查询类型非供应方,执行通用采购方查询逻辑。当前登录企业ID: {}", LoginUserHolder.getEntId());
-        
+
         // 再次过滤合同ID:只保留当前登录企业作为“采购方”参与的合同
         // 注意:这里硬编码了 unitType=2 (假设 2 代表 PURCHASER/采购方,需与 CooperateTypeEnum.PURCHASER.getCode() 保持一致)
         Set<Long> filteredContractIds = allTradeUnits.stream()
-                .filter(unit -> Objects.equals(unit.getEntId(), LoginUserHolder.getEntId()) 
+                .filter(unit -> Objects.equals(unit.getEntId(), LoginUserHolder.getEntId())
                         && Objects.equals(unit.getUnitType(), CooperateTypeEnum.PURCHASER.getCode()))
                 .map(KwcContractTradeUnit::getContractId)
                 .collect(Collectors.toSet());
@@ -2589,16 +2623,16 @@ public class KwcContractTradeService {
         // 8. 组装返回结果
         List<ContractTradeOrderInfo> resultList = validTrades.stream()
                 .map(trade -> getContractTradeOrderInfo(
-                        trade, 
-                        contractTradeUnitMap, 
-                        contractTradeOrderDto.getEntType(), 
+                        trade,
+                        contractTradeUnitMap,
+                        contractTradeOrderDto.getEntType(),
                         contractGoodsMap
                 ))
                 .collect(Collectors.toList());
 
         // 9. 关键字模糊匹配过滤(如有)
         List<ContractTradeOrderInfo> finalResult = filterContractTradeOrderInfo(resultList, contractTradeOrderDto.getKeyword());
-        
+
         log.info("查询贸易合同订单完成,最终返回记录数: {}", finalResult.size());
         return finalResult;
     }

+ 22 - 10
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTradeOrderService.java

@@ -62,6 +62,7 @@ import com.sckw.payment.api.feign.PaymentFeignService;
 import com.sckw.payment.api.model.constant.ChannelEnum;
 import com.sckw.payment.api.model.dto.WalletDto;
 import com.sckw.payment.api.model.dto.common.R;
+import com.sckw.payment.api.model.feign.WalletAgentDto;
 import com.sckw.payment.api.model.feign.WalletPrepaidDto;
 import com.sckw.product.api.dubbo.GoodsInfoService;
 import com.sckw.product.api.model.AddressInfoDetail;
@@ -1695,9 +1696,9 @@ public class KwoTradeOrderService {
      * 1. 获取当前登录用户的企业ID。
      * 2. 查询该企业的类型信息(如:供应商、代理商等)。
      * 3. 根据企业类型构建代理可见范围:
-     *    - 若为供应商:可见自身及下属代理商的订单。
-     *    - 若为代理商:仅可见自身的订单。
-     *    - 其他类型:不追加特殊过滤(由数据权限控制)。
+     * - 若为供应商:可见自身及下属代理商的订单。
+     * - 若为代理商:仅可见自身的订单。
+     * - 其他类型:不追加特殊过滤(由数据权限控制)。
      * 4. 将计算出的可见企业ID集合设置到查询DTO中,供后续SQL过滤使用。
      * 5. 若发生异常或企业ID为空,则强制结果为空,防止数据泄露。
      *
@@ -2668,12 +2669,16 @@ public class KwoTradeOrderService {
             // todo 普通结算冻结
 
         } else if (Objects.equals(tradeContractResDto.getSettlement(), 2)) {
-            //预付制结算冻结
-            walletFreeze.setOrderType(4);
-            walletFreeze.setTradeType(4);
-            walletFreeze.setRemark("贸易订单号:" + walletFreeze.getOrderNo() + ",下单冻结");
-            log.info("贸易订单号:{},订单下单调用钱包服务冻结预付余额,参数:{}", walletFreeze.getOrderNo(), JSON.toJSONString(walletFreeze));
-            freezeBaseResult = paymentFeignService.updatePrepaidBalance(walletFreeze);
+            if (Objects.equals(order.getAgentFlag(), 1)) {
+
+            } else {
+                //预付制结算冻结
+                walletFreeze.setOrderType(4);
+                walletFreeze.setTradeType(4);
+                walletFreeze.setRemark("贸易订单号:" + walletFreeze.getOrderNo() + ",下单冻结");
+                log.info("贸易订单号:{},订单下单调用钱包服务冻结预付余额,参数:{}", walletFreeze.getOrderNo(), JSON.toJSONString(walletFreeze));
+                freezeBaseResult = paymentFeignService.updatePrepaidBalance(walletFreeze);
+            }
         }
 
         if (freezeBaseResult.getCode() != 60200) {
@@ -3399,6 +3404,13 @@ public class KwoTradeOrderService {
                 log.error("贸易订单号:{},订单完结消费失败,异常信息为:{}", consumePrepaidDto.getOrderNo(), consumeResult.getMessage());
                 throw new BusinessException("贸易订单号:" + consumePrepaidDto.getOrderNo() + ",订单完结消费失败");
             }
+            List<WalletAgentDto> list = new ArrayList<>();
+            try {
+                paymentFeignService.batchUpdateAgentBalance(list);
+            } catch (Exception e) {
+                log.error("代理费结算错误 {}", e.getMessage());
+            }
+
         }
 
     }
@@ -3553,7 +3565,7 @@ public class KwoTradeOrderService {
             throw new BusinessException("贸易订单企业信息不存在");
         }
         Map<String, KwoTradeOrderUnit> unitMap = orderUnits.stream().collect(Collectors.toMap(KwoTradeOrderUnit::getUnitType, e -> e, (a, b) -> a));
-        if (unitMap.keySet().size() < 2) {
+        if (unitMap.size() < 2) {
             throw new BusinessException("贸易订单企业信息缺失");
         }
         if (Objects.equals(tradeContractResDto.getConsignment(), 2)) {

+ 38 - 21
sckw-modules/sckw-order/src/main/java/com/sckw/order/task/TradeOrderTask.java

@@ -2,7 +2,6 @@ package com.sckw.order.task;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.NumberUtil;
-import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.Global;
@@ -19,6 +18,7 @@ import com.sckw.order.model.KwoTradeOrderGoods;
 import com.sckw.order.model.KwoTradeOrderUnit;
 import com.sckw.payment.api.dubbo.PaymentDubboService;
 import com.sckw.payment.api.feign.PaymentFeignService;
+import com.sckw.payment.api.model.feign.WalletAgentDto;
 import com.sckw.payment.api.model.feign.WalletPrepaidDto;
 import com.sckw.transport.api.dubbo.TransportRemoteService;
 import com.sckw.transport.api.model.param.OrderFinishParam;
@@ -202,8 +202,7 @@ public class TradeOrderTask {
 
             } else if (Objects.equals(kwoTradeOrder.getSettlement(), 2)) {
                 //预付制模式
-                //1解冻运费
-                if (unitMap.keySet().size() < 2) {
+                if (unitMap.size() < 2) {
                     throw new BusinessException("贸易订单企业信息缺失");
                 }
                 //钱包退回金额
@@ -214,17 +213,7 @@ public class TradeOrderTask {
                 unFreezePrepaidDto.setOrderType(4);
                 unFreezePrepaidDto.setTradeType(5);
                 unFreezePrepaidDto.setRemark("贸易订单:" + unFreezePrepaidDto.getOrderNo() + ",");
-                log.info("贸易订单号:{},订单完结调用钱包服务解冻预付余额,参数:{}", unFreezePrepaidDto.getOrderNo(), JSON.toJSONString(unFreezePrepaidDto));
-                BaseResult<Object> unFreezeResult = new BaseResult<>();
-                try {
-                    unFreezeResult = paymentFeignService.updatePrepaidBalance(unFreezePrepaidDto);
-                } catch (Exception e) {
-                    log.error("订单完结调用钱包服务解冻预付余额异常:{}", e.getMessage());
-                }
-                if (unFreezeResult.getCode() != HttpStatus.SUCCESS_CODE) {
-                    log.error("贸易订单号:{},订单完结解冻失败,异常信息为:{}", unFreezePrepaidDto.getOrderNo(), unFreezeResult.getMessage());
-                    throw new BusinessException("贸易订单号:" + unFreezePrepaidDto.getOrderNo() + ",订单完结解冻失败");
-                }
+
                 //2计算订单金额
                 WalletPrepaidDto consumePrepaidDto = new WalletPrepaidDto();
                 consumePrepaidDto.setOrderNo(kwoTradeOrder.getTOrderNo());
@@ -238,17 +227,45 @@ public class TradeOrderTask {
                     consumePrepaidDto.setTradeAmount(NumberUtil.mul(kwoTradeOrder.getUnloadAmount(), unitPrice));
                 }
                 consumePrepaidDto.setRemark("贸易订单号:" + consumePrepaidDto.getOrderNo() + ",订单完结消费");
-                log.info("贸易订单号:{},订单完结调用钱包服务消费预付余额,参数:{}", consumePrepaidDto.getOrderNo(), JSON.toJSONString(consumePrepaidDto));
-                BaseResult<Object> consumeResult = new BaseResult<>();
+
+                BaseResult<Object> unFreezeResult = new BaseResult<>();
                 try {
-                    consumeResult = paymentFeignService.updatePrepaidBalance(consumePrepaidDto);
+                    unFreezeResult = paymentFeignService.batchUpdatePrepaidBalance(List.of(unFreezePrepaidDto, consumePrepaidDto));
                 } catch (Exception e) {
-                    log.error("订单完结调用钱包服务消费预付余额异常:{}", e.getMessage());
+                    log.error("订单完结调用钱包服务解冻并结算异常:{}", e.getMessage());
                 }
-                if (consumeResult.getCode() != HttpStatus.SUCCESS_CODE) {
-                    log.error("贸易订单号:{},订单完结消费失败,异常信息为:{}", consumePrepaidDto.getOrderNo(), consumeResult.getMessage());
-                    throw new BusinessException("贸易订单号:" + consumePrepaidDto.getOrderNo() + ",订单完结消费失败");
+                if (unFreezeResult.getCode() != HttpStatus.SUCCESS_CODE) {
+                    log.error("贸易订单号:{},订单完结解冻并结算失败,异常信息为:{}", unFreezePrepaidDto.getOrderNo(), unFreezeResult.getMessage());
+                    throw new BusinessException("贸易订单号:" + unFreezePrepaidDto.getOrderNo() + ",订单完结解冻并结算失败");
                 }
+                if (Objects.equals(kwoTradeOrder.getAgentFlag(), 1)) {
+                    //代理商 付给 供应商
+                    WalletAgentDto walletAgentDto = new WalletAgentDto();
+                    walletAgentDto.setOrderNo(kwoTradeOrder.getTOrderNo());
+                    walletAgentDto.setAgtEntId(unitMap.get(String.valueOf(3)).getEntId());//todo 确认
+                    walletAgentDto.setSupEntId(unitMap.get(String.valueOf(2)).getEntId());
+                    walletAgentDto.setOrderType(4);
+                    walletAgentDto.setTradeType(5);
+                    walletAgentDto.setRemark("贸易订单:" + walletAgentDto.getOrderNo());
+                    WalletAgentDto walletAgentDto2 = new WalletAgentDto();
+                    walletAgentDto2.setOrderNo(kwoTradeOrder.getTOrderNo());
+                    walletAgentDto2.setAgtEntId(unitMap.get(String.valueOf(3)).getEntId());
+                    walletAgentDto2.setSupEntId(unitMap.get(String.valueOf(2)).getEntId());
+                    walletAgentDto2.setOrderType(4);
+                    walletAgentDto2.setTradeType(6);
+                    if (Objects.equals(kwoTradeOrder.getChargeType(), 1)) {
+                        consumePrepaidDto.setTradeAmount(NumberUtil.mul(kwoTradeOrder.getLoadAmount(), unitPrice));
+                    } else {
+                        consumePrepaidDto.setTradeAmount(NumberUtil.mul(kwoTradeOrder.getUnloadAmount(), unitPrice));
+                    }
+                    walletAgentDto2.setRemark("贸易订单:" + walletAgentDto2.getOrderNo());
+                    try {
+                        paymentFeignService.batchUpdateAgentBalance(List.of(walletAgentDto, walletAgentDto2));
+                    } catch (Exception e) {
+                        log.error("代理费结算错误 {}", e.getMessage());
+                    }
+                }
+
             }
         }
 

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

@@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo;
 import com.sckw.core.web.response.BaseResult;
 import com.sckw.core.web.response.result.PageDataResult;
 import com.sckw.payment.api.model.TradeEntInfoResVo;
+import com.sckw.payment.api.model.feign.WalletAgentDto;
 import com.sckw.payment.pojo.vo.req.ReceivedCallbackDto;
 import com.sckw.payment.pojo.vo.req.WalletAgentManualDto;
 import com.sckw.payment.pojo.vo.req.WalletAgentPayDto;
@@ -16,11 +17,7 @@ import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -64,10 +61,30 @@ public class WalletAgentController {
         return walletAgentService.manualEntry(manualDto);
     }
 
+    @Operation(summary = "代理,冻结、解冻、等消费")
+    @PostMapping("/updateAgentBalance")
+    public BaseResult<Object> updateAgentBalance(@RequestBody @Validated WalletAgentDto agentDto) {
+        return walletAgentService.updateAgentBalance(agentDto);
+    }
+
+    @Operation(summary = "代理,冻结、解冻、等消费")
+    @PostMapping("/batchUpdateAgentBalance")
+    public BaseResult<Object> batchUpdateAgentBalance(@RequestBody @Validated List<WalletAgentDto> agentDto) {
+        return walletAgentService.batchUpdateAgentBalance(agentDto);
+    }
+
+    @Operation(summary = "初始化代理清单")
+    @PostMapping("/initAgentBalance")
+    public BaseResult<Boolean> initAgentBalance(@RequestBody @Validated WalletAgentDto agentDto) {
+        return walletAgentService.initAgentBalance(agentDto);
+    }
+
     @Operation(summary = "代理费到账回调接口")
     @PostMapping("/receivedCallback")
     public BaseResult<Object> receivedCallback(@RequestBody @Validated ReceivedCallbackDto receivedCallbackDto) {
         walletAgentService.receivedCallback(receivedCallbackDto);
         return BaseResult.success();
     }
+
+
 }

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

@@ -39,7 +39,7 @@ public class WalletAgentRecordController {
 
     @Operation(summary = "查询历史支付记录信息")
     @GetMapping("/get")
-    public BaseResult<List<WalletAgentRecordRes>> getPay(@RequestParam("agentId") Long agentId) {
-        return walletAgentService.getPayList(agentId);
+    public BaseResult<List<WalletAgentRecordRes>> getPay(@RequestParam("agentId") Long agentId, @RequestParam(value = "status", required = false) Integer status) {
+        return walletAgentService.getPayList(agentId, status);
     }
 }

+ 16 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletPrepaidController.java

@@ -31,11 +31,12 @@ import java.util.List;
 @Tag(name = "待履约/预付清单")
 @RestController
 @RequestMapping("/walletPrepaid")
-public class WalletPrepaidController  {
+public class WalletPrepaidController {
 
 
     @Autowired
     private IWalletPrepaidService walletPrepaidService;
+
     /**
      * BI大屏预付余额:系统内所有供应商的待履约金额汇总
      */
@@ -45,6 +46,7 @@ public class WalletPrepaidController  {
         BigDecimal summary = walletPrepaidService.selectAllSupplierPrepaidSummary();
         return BaseResult.success(summary);
     }
+
     /**
      * 查询财务报表数据
      */
@@ -140,6 +142,19 @@ public class WalletPrepaidController  {
         return BaseResult.success();
     }
 
+    /**
+     * 预付清单冻结、解冻、消费接口
+     *
+     * @param prepaidDto
+     * @return
+     */
+    @Operation(summary = "预付清单冻结、解冻、消费接口")
+    @PostMapping("/batchUpdatePrepaidBalance")
+    BaseResult<Boolean> batchUpdatePrepaidBalance(@RequestBody List<WalletPrepaidDto> prepaidDto) {
+        walletPrepaidService.batchUpdatePrepaidBalance(prepaidDto);
+        return BaseResult.success();
+    }
+
     /**
      * 根据当前企业id查询采购合同对方企业id列表
      */

+ 5 - 5
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/entity/WalletAgentBalance.java

@@ -73,17 +73,17 @@ public class WalletAgentBalance extends BaseEntity {
     private BigDecimal tradeAmount;
 
     /**
-     * 预付余额
+     * 待收/待付代理费
      */
     @TableField(value = "pre_balance")
-    @Schema(description="预付余额")
+    @Schema(description="待收/待付代理费")
     private BigDecimal preBalance;
 
     /**
-     * 交易中金额
+     * 付款中金额
      */
     @TableField(value = "trading_amount")
-    @Schema(description="交易中金额")
+    @Schema(description="付款中金额")
     private BigDecimal tradingAmount;
 
     /**
@@ -106,4 +106,4 @@ public class WalletAgentBalance extends BaseEntity {
     @TableField(value = "remark")
     @Schema(description="备注")
     private String remark;
-}
+}

+ 21 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentManualDto.java

@@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotNull;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @Data
 public class WalletAgentManualDto {
@@ -14,9 +15,28 @@ public class WalletAgentManualDto {
     private Long tradeEntId;
 
     @Schema(description = "金额")
-    @NotNull
+    @NotNull(message = "金额不能为空")
     @DecimalMin(value = "0.01", message = "金额必须大于0")
     private BigDecimal amount;
+    /**
+     * 1 待付代理费
+     * 2 付款中金额
+     */
+    @Schema(description = "录入账户")
+    @NotNull(message = "录入账户不能为空")
+    private Integer accountType;
+    /**
+     * 1-增加 2-减少
+     */
+    @Schema(description = "资金方向")
+    @NotNull(message = "资金方向不能为空")
+    private Integer amountType;
+
+    /**
+     * 凭证文件地址
+     */
+    @Schema(description = "凭证文件地址")
+    private List<String> voucherFiles;
 
     @Schema(description = "备注")
     private String remark;

+ 2 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/IWalletPrepaidService.java

@@ -107,4 +107,6 @@ public interface IWalletPrepaidService {
     void exportFinancialReport(WalletPrepaidBalanceQuery query, HttpServletResponse response);
 
     List<TradeEntInfoResVo> queryPrepaidTradeEntIds();
+
+    void batchUpdatePrepaidBalance(List<WalletPrepaidDto> prepaidDto);
 }

+ 7 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletService.java

@@ -40,9 +40,11 @@ import com.sckw.payment.pojo.vo.WalletVo;
 import com.sckw.payment.pojo.vo.req.CreateUserReq;
 import com.sckw.payment.pojo.vo.req.WalletPayableQuery;
 import com.sckw.payment.pojo.vo.req.WalletPrepaidQuery;
+import com.sckw.payment.pojo.vo.res.WalletAgentSummary;
 import com.sckw.payment.pojo.vo.res.WalletPayableSummary;
 import com.sckw.payment.pojo.vo.res.WalletPrepaidSummary;
 import com.sckw.payment.pojo.vo.res.WalletSummary;
+import com.sckw.payment.service.impl.WalletAgentService;
 import com.sckw.redis.config.RedisLockUtil;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.EntCacheResDto;
@@ -89,6 +91,8 @@ public class WalletService {
     private RemoteFileService remoteFileService;
     @Resource
     private KwpWalletSplitMapper kwpWalletSplitMapper;
+    @Resource
+    private WalletAgentService walletAgentService;
 
     /**
      * @return
@@ -328,7 +332,7 @@ public class WalletService {
             WalletVo bean = BeanUtil.toBean(one, WalletVo.class);
 
             WalletSummary summary = new WalletSummary();
-            String entTypes = LoginEntHolder.get().getEntTypes();
+            String entTypes = LoginEntHolder.getEntTypes();
             WalletPrepaidQuery prepaidQuery = new WalletPrepaidQuery();
             prepaidQuery.setCurEntId(LoginEntHolder.getEntId());
             if (entTypes.contains(String.valueOf(EntTypeEnum.SUPPLIER.getCode()))) {
@@ -343,6 +347,8 @@ public class WalletService {
                 summary.setPreTradingAmountTotal(prepaidSummary.getTradingAmountTotal());
             }
 
+            WalletAgentSummary walletAgentSummary = walletAgentService.queryAgentSummary();
+            summary.setAgentAmount(walletAgentSummary.getPreBalanceTotal());
 
             WalletPayableQuery payableQuery = new WalletPayableQuery();
             payableQuery.setCurEntId(LoginEntHolder.getEntId());

+ 158 - 61
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/impl/WalletAgentService.java

@@ -1,5 +1,7 @@
 package com.sckw.payment.service.impl;
 
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -12,34 +14,21 @@ import com.sckw.core.utils.PageUtils;
 import com.sckw.core.web.context.LoginEntHolder;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.BaseResult;
+import com.sckw.payment.api.model.TradeEntInfoResVo;
+import com.sckw.payment.api.model.dto.common.R;
+import com.sckw.payment.api.model.feign.WalletAgentDto;
 import com.sckw.payment.config.ApplicationProperties;
-import com.sckw.payment.entity.WalletAgent;
-import com.sckw.payment.entity.WalletAgentBalance;
-import com.sckw.payment.entity.WalletAgentRecord;
-import com.sckw.payment.entity.KwpWallet;
+import com.sckw.payment.entity.*;
 import com.sckw.payment.enums.ExecutionStatusEnum;
 import com.sckw.payment.enums.OrderTypeEnum;
 import com.sckw.payment.enums.PayStatusEnum;
-import com.sckw.payment.mapper.WalletAgentMapper;
-import com.sckw.payment.mapper.WalletAgentBalanceMapper;
-import com.sckw.payment.mapper.WalletAgentRecordMapper;
-import com.sckw.payment.mapper.KwpWalletMapper;
+import com.sckw.payment.enums.TransactionTypeEnum;
+import com.sckw.payment.mapper.*;
 import com.sckw.payment.pojo.dto.PayDto;
 import com.sckw.payment.pojo.vo.PayRes;
-import com.sckw.payment.pojo.vo.req.ReceivedCallbackDto;
-import com.sckw.payment.pojo.vo.req.WalletAgentManualDto;
-import com.sckw.payment.pojo.vo.req.WalletAgentBalanceQuery;
-import com.sckw.payment.pojo.vo.req.WalletAgentPayDto;
-import com.sckw.payment.pojo.vo.req.WalletAgentQuery;
-import com.sckw.payment.pojo.vo.req.WalletAgentRecordQuery;
-import com.sckw.payment.pojo.vo.res.WalletAgentBalanceRes;
-import com.sckw.payment.pojo.vo.res.WalletAgentRecordRes;
-import com.sckw.payment.pojo.vo.res.WalletAgentRes;
-import com.sckw.payment.pojo.vo.res.WalletAgentSummary;
-import com.sckw.payment.pojo.vo.res.WalletPayAddRes;
+import com.sckw.payment.pojo.vo.req.*;
+import com.sckw.payment.pojo.vo.res.*;
 import com.sckw.payment.service.PayXwService;
-import com.sckw.payment.api.model.dto.common.R;
-import com.sckw.payment.api.model.TradeEntInfoResVo;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.EntCacheResDto;
 import jakarta.annotation.Resource;
@@ -47,6 +36,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
@@ -54,12 +44,7 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -76,7 +61,8 @@ public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAge
 
     @Autowired
     private WalletAgentBalanceMapper walletAgentBalanceMapper;
-
+    @Autowired
+    private WalletBusinessFileMapper businessFileMapper;
     @Autowired
     private PayXwService payXwService;
 
@@ -423,56 +409,89 @@ public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAge
         return pageInfo;
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public BaseResult<Object> manualEntry(WalletAgentManualDto manualDto) {
-        if (!isProxyEnt()) {
-            return BaseResult.failed("非代理企业不可人工录入");
-        }
+        //供应商才能人工录入。
         Long curEntId = LoginEntHolder.getEntId();
+
         WalletAgent walletAgent = baseMapper.selectOne(Wrappers.lambdaQuery(WalletAgent.class)
                 .eq(WalletAgent::getDelFlag, 0)
-                .eq(WalletAgent::getAgtEntId, curEntId)
-                .eq(WalletAgent::getSupEntId, manualDto.getTradeEntId())
+                .eq(WalletAgent::getAgtEntId, manualDto.getTradeEntId())
+                .eq(WalletAgent::getSupEntId, curEntId)
                 .last("limit 1"));
+
+
         if (walletAgent == null) {
-            return BaseResult.failed("代理费清单不存在");
-        }
-        if (walletAgent.getPreBalance() == null || walletAgent.getPreBalance().compareTo(manualDto.getAmount()) < 0) {
-            return BaseResult.failed("金额不能大于待收代理费");
+            walletAgent = new WalletAgent();
+            if (Objects.equals(manualDto.getAccountType(), 1)) {
+                walletAgent.setPreBalance(manualDto.getAmount());
+            } else {
+                walletAgent.setTradingAmount(manualDto.getAmount());
+            }
+            walletAgent.setAgtEntId(manualDto.getTradeEntId());
+            walletAgent.setSupEntId(curEntId);
+            walletAgent.setStatus(0);
+            walletAgent.setRemark("");
+            walletAgent.setCreateBy(LoginUserHolder.getUserId());
+            walletAgent.setCreateTime(LocalDateTime.now());
+            walletAgent.setUpdateBy(LoginUserHolder.getUserId());
+            walletAgent.setUpdateTime(LocalDateTime.now());
+            walletAgent.setDelFlag(0);
+            baseMapper.insert(walletAgent);
+        } else {
+            BigDecimal newPre;
+            if (Objects.equals(manualDto.getAccountType(), 1)) { //待付代理费
+                if (Objects.equals(manualDto.getAmountType(), 1)) {
+                    newPre = walletAgent.getPreBalance().add(manualDto.getAmount());
+                    walletAgent.setPreBalance(newPre);
+                } else {
+                    newPre = walletAgent.getPreBalance().subtract(manualDto.getAmount());
+                    walletAgent.setPreBalance(newPre);
+                }
+            } else { //付款中金额
+                if (Objects.equals(manualDto.getAmountType(), 1)) {
+                    newPre = walletAgent.getTradingAmount().add(manualDto.getAmount());
+                    walletAgent.setTradingAmount(newPre);
+                } else {
+                    newPre = walletAgent.getTradingAmount().subtract(manualDto.getAmount());
+                    walletAgent.setTradingAmount(newPre);
+                }
+            }
+            baseMapper.updateById(walletAgent);
         }
 
-        String orderNo = "M" + System.currentTimeMillis();
-
-        BigDecimal newPre = walletAgent.getPreBalance().subtract(manualDto.getAmount());
-        walletAgent.setPreBalance(newPre);
-        baseMapper.updateById(walletAgent);
 
         WalletAgentBalance balance = new WalletAgentBalance();
-        balance.setOrderNo(orderNo);
+        balance.setOrderNo(IdUtil.getSnowflakeNextIdStr());
         balance.setOrderType(OrderTypeEnum.PAYMENT_ORDER.getCode());
         balance.setAgtEntId(walletAgent.getAgtEntId());
         balance.setSupEntId(walletAgent.getSupEntId());
         balance.setTradeType(4);
         balance.setTradeAmount(manualDto.getAmount());
-        balance.setPreBalance(newPre);
+        balance.setPreBalance(walletAgent.getPreBalance());
         balance.setTradingAmount(walletAgent.getTradingAmount());
         balance.setStatus(ExecutionStatusEnum.SUCCESS.getCode());
         balance.setRemark(manualDto.getRemark());
         balance.setDelFlag(0);
         walletAgentBalanceMapper.insert(balance);
 
-        WalletAgentRecord record = new WalletAgentRecord();
-        record.setAgentId(walletAgent.getId());
-        record.setOrderNo(orderNo);
-        record.setPrepaidAmount(manualDto.getAmount());
-        record.setReceivedAmount(manualDto.getAmount());
-        record.setStatus(PayStatusEnum.PAID.getCode());
-        record.setData("");
-        record.setRemark(manualDto.getRemark());
-        record.setDelFlag(0);
-        walletAgentRecordMapper.insert(record);
+        //3.保存凭证相关文件
+        List<String> voucherFiles = manualDto.getVoucherFiles();
+        if (!CollectionUtils.isEmpty(voucherFiles)) {
+            voucherFiles.forEach(e -> {
+                WalletBusinessFile file = new WalletBusinessFile();
+                file.setBusinessId(balance.getId());
+                file.setFilePath(e);
+                file.setCreateBy(LoginUserHolder.getUserId());
+                file.setCreateTime(LocalDateTime.now());
+                businessFileMapper.insert(file);
+            });
+        }
+
         return BaseResult.success();
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public BaseResult<WalletPayAddRes> pay(WalletAgentPayDto payDto) {
         if (isProxyEnt()) {
             return BaseResult.failed("代理企业不可发起代理费付款");
@@ -579,6 +598,7 @@ public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAge
         return BaseResult.success(walletPayAddRes);
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public void receivedCallback(ReceivedCallbackDto receivedCallbackDto) {
         WalletAgentRecord record = walletAgentRecordMapper.selectOne(Wrappers.lambdaQuery(WalletAgentRecord.class)
                 .eq(WalletAgentRecord::getOrderNo, receivedCallbackDto.getPayOrderNo())
@@ -635,7 +655,7 @@ public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAge
     }
 
     private boolean isProxyEnt() {
-        String entTypes = LoginEntHolder.get().getEntTypes();
+        String entTypes = LoginEntHolder.getEntTypes();
         return entTypes != null && entTypes.contains(String.valueOf(EntTypeEnum.PROXY.getCode()));
     }
 
@@ -708,7 +728,7 @@ public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAge
         return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
     }
 
-    public BaseResult<List<WalletAgentRecordRes>> getPayList(Long agentId) {
+    public BaseResult<List<WalletAgentRecordRes>> getPayList(Long agentId, Integer status) {
         if (agentId == null) {
             return BaseResult.success(new ArrayList<>());
         }
@@ -716,14 +736,10 @@ public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAge
         if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
             return BaseResult.success(new ArrayList<>());
         }
-        Long curEntId = LoginEntHolder.getEntId();
-        if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
-            return BaseResult.failed("无权限查看该支付记录");
-        }
-
         LambdaQueryWrapper<WalletAgentRecord> wrapper = Wrappers.lambdaQuery(WalletAgentRecord.class)
                 .eq(WalletAgentRecord::getDelFlag, 0)
                 .eq(WalletAgentRecord::getAgentId, agentId)
+                .eq(Objects.nonNull(status),WalletAgentRecord::getStatus, status)
                 .orderByDesc(WalletAgentRecord::getId);
         List<WalletAgentRecord> list = walletAgentRecordMapper.selectList(wrapper);
         if (CollectionUtils.isEmpty(list)) {
@@ -751,4 +767,85 @@ public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAge
 
         return BaseResult.success(resList);
     }
+
+    @Transactional(rollbackFor = Exception.class)
+    public BaseResult<Object> updateAgentBalance(WalletAgentDto agentDto) {
+        WalletAgent existedAgent = baseMapper.selectOne(Wrappers.lambdaQuery(WalletAgent.class)
+                .eq(WalletAgent::getAgtEntId, agentDto.getAgtEntId())
+                .eq(WalletAgent::getSupEntId, agentDto.getSupEntId())
+        );
+        if (Objects.isNull(existedAgent)) {
+            throw new BusinessException("代理清单不存在");
+        }
+
+        //待付运费清单处理
+        if (Objects.equals(agentDto.getTradeType(), TransactionTypeEnum.FREEZE.getCode())) {
+            //冻结
+            if (agentDto.getTradeAmount() == null) {
+                throw new BusinessException("交易金额不能为空");
+            }
+            existedAgent.setTradingAmount(existedAgent.getTradingAmount().add(agentDto.getTradeAmount()));
+        } else if (Objects.equals(agentDto.getTradeType(), TransactionTypeEnum.UNFREEZE.getCode())) {
+            WalletAgentBalance walletAgentBalance = walletAgentBalanceMapper.selectOne(Wrappers.lambdaQuery(WalletAgentBalance.class)
+                    .eq(WalletAgentBalance::getAgtEntId, agentDto.getAgtEntId())
+                    .eq(WalletAgentBalance::getSupEntId, agentDto.getSupEntId())
+                    .eq(StrUtil.isNotBlank(agentDto.getOrderNo()), WalletAgentBalance::getOrderNo, agentDto.getOrderNo())
+            );
+            if (walletAgentBalance == null) {
+                throw new BusinessException("代理费解冻异常,代理费冻结记录不存在");
+            }
+            existedAgent.setTradingAmount(existedAgent.getTradingAmount().subtract(agentDto.getTradeAmount()));
+        } else if (Objects.equals(agentDto.getTradeType(), TransactionTypeEnum.CONSUME.getCode())) {
+            //消费
+            if (agentDto.getTradeAmount() == null) {
+                throw new BusinessException("交易金额不能为空");
+            }
+            existedAgent.setPreBalance(existedAgent.getPreBalance().add(agentDto.getTradeAmount()));
+        } else {
+            //其他
+            throw new BusinessException("交易类型不支持");
+        }
+
+        baseMapper.updateById(existedAgent);
+        WalletAgentBalance prepaidBalance = new WalletAgentBalance();
+        prepaidBalance.setOrderNo(agentDto.getOrderNo());
+        prepaidBalance.setOrderType(agentDto.getOrderType());
+        prepaidBalance.setAgtEntId(agentDto.getAgtEntId());
+        prepaidBalance.setSupEntId(agentDto.getSupEntId());
+        prepaidBalance.setTradeType(agentDto.getTradeType());
+        prepaidBalance.setTradeAmount(agentDto.getTradeAmount());
+        prepaidBalance.setPreBalance(existedAgent.getPreBalance());
+        prepaidBalance.setTradingAmount(existedAgent.getTradingAmount());
+        prepaidBalance.setFile("");
+        prepaidBalance.setStatus(0);
+        prepaidBalance.setRemark("");
+        walletAgentBalanceMapper.insert(prepaidBalance);
+        return BaseResult.success(true);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public BaseResult<Boolean> initAgentBalance(WalletAgentDto agentDto) {
+        WalletAgent walletAgent = baseMapper.selectOne(Wrappers.lambdaQuery(WalletAgent.class)
+                .eq(WalletAgent::getAgtEntId, agentDto.getAgtEntId())
+                .eq(WalletAgent::getSupEntId, agentDto.getSupEntId())
+        );
+        if (Objects.isNull(walletAgent)) {
+            WalletAgent walletAgent1 = new WalletAgent();
+            walletAgent1.setAgtEntId(agentDto.getAgtEntId());
+            walletAgent1.setSupEntId(agentDto.getSupEntId());
+            walletAgent1.setPreBalance(BigDecimal.ZERO);
+            walletAgent1.setTradingAmount(BigDecimal.ZERO);
+            walletAgent1.setStatus(0);
+            baseMapper.insert(walletAgent1);
+        }
+        return BaseResult.success(true);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public BaseResult<Object> batchUpdateAgentBalance(List<WalletAgentDto> agentDto) {
+        for (WalletAgentDto walletAgentDto : agentDto) {
+            updateAgentBalance(walletAgentDto);
+        }
+        return null;
+    }
 }

+ 8 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/impl/WalletPrepaidServiceImpl.java

@@ -618,4 +618,12 @@ public class WalletPrepaidServiceImpl implements IWalletPrepaidService {
 
         return remoteContractService.queryPrepaidTradeEntIds(queryFeignDto);
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void batchUpdatePrepaidBalance(List<WalletPrepaidDto> prepaidDto) {
+        for (WalletPrepaidDto walletPrepaidDto : prepaidDto) {
+            updatePrepaidBalance(walletPrepaidDto);
+        }
+    }
 }