Просмотр исходного кода

结算-物流运费相关除新增确认"线下付款"外开发完成

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

+ 10 - 6
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/KwpSettlementOfflineController.java

@@ -1,6 +1,7 @@
 package com.sckw.payment.controller;
 
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.payment.model.vo.req.OfflinePaymentReq;
 import com.sckw.payment.model.vo.req.SettlementOfflineReq;
 import com.sckw.payment.model.vo.req.SettlementReq;
 import com.sckw.payment.service.KwpSettlementOfflineService;
@@ -8,6 +9,8 @@ import jakarta.annotation.Resource;
 import jakarta.validation.Valid;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
+
 /**
  * 结算-线下记录(交易订单结算/物流订单结算)
  *
@@ -33,9 +36,10 @@ public class KwpSettlementOfflineController {
         return HttpResult.ok(kwpSettlementOfflineService.detailLogisticsCollection(id));
     }
 
-    @GetMapping(name = "物流-线下付款(运费收款)记录-新增", path = "confirmLogisticsCollection")
-    public HttpResult confirmLogisticsCollection(@RequestParam("id") Long id, @RequestParam("price") Float price) {
-        return HttpResult.ok(kwpSettlementOfflineService.confirmLogisticsCollection(id, price));
+    @PostMapping(name = "物流-线下付款(运费收款)记录-新增", path = "confirmLogisticsCollection")
+//    public HttpResult confirmLogisticsCollection(@RequestParam("id") Long id, @RequestParam("price") BigDecimal price, @RequestParam("url") String url) {
+    public HttpResult confirmLogisticsCollection(@RequestBody @Valid OfflinePaymentReq offlinePaymentReq) {
+        return HttpResult.ok(kwpSettlementOfflineService.confirmLogisticsCollection(offlinePaymentReq));
     }
 
 
@@ -46,9 +50,9 @@ 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));
+    @GetMapping(name = "交易-线下付款(销售收款)记录-新增", path = "confirmTradeCollection")
+    public HttpResult confirmTradeCollection(@RequestParam("id") Long id, @RequestParam("price") Float price) {
+        return HttpResult.ok(kwpSettlementOfflineService.confirmTradeCollection(id, price));
     }
 
 }

+ 18 - 72
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/KwpSettlementOffline.java

@@ -4,14 +4,17 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+
 import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
 
 /**
  * 线下结算记录(交易订单结算/物流订单结算)
+ *
  * @author xucaiqin
  * @date 2023-07-10 16:42:19
  */
@@ -20,6 +23,9 @@ import lombok.ToString;
 @ToString
 @TableName(value = "kwp_settlement_offline")
 public class KwpSettlementOffline {
+    /**
+     * 主键
+     */
     @TableId(value = "id", type = IdType.INPUT)
     private Long id;
 
@@ -36,52 +42,16 @@ public class KwpSettlementOffline {
     private Long settlementId;
 
     /**
-     * 收款企业id
-     */
-    @TableField(value = "coll_ent_id")
-    private Long collEntId;
-
-    /**
-     * 收款企业名称
-     */
-    @TableField(value = "coll_firm_name")
-    private String collFirmName;
-
-    /**
-     * 收款金额
-     */
-    @TableField(value = "coll_price")
-    private BigDecimal collPrice;
-
-    /**
-     * 预计收款日期
-     */
-    @TableField(value = "coll_time")
-    private LocalDateTime collTime;
-
-    /**
-     * 收款确认人
-     */
-    @TableField(value = "coll_user_id")
-    private Long collUserId;
-
-    /**
-     * 收款附件
-     */
-    @TableField(value = "coll_urls")
-    private String collUrls;
-
-    /**
-     * 付款企业id
+     * 结算单类型 1-物流 2-贸易
      */
-    @TableField(value = "pay_ent_id")
-    private Long payEntId;
+    @TableField(value = "order_type")
+    private Integer orderType;
 
     /**
-     * 付款企业名称
+     * 付款日期
      */
-    @TableField(value = "pay_firm_name")
-    private String payFirmName;
+    @TableField(value = "pay_time")
+    private LocalDateTime payTime;
 
     /**
      * 付款金额
@@ -90,33 +60,26 @@ public class KwpSettlementOffline {
     private BigDecimal payPrice;
 
     /**
-     * 付款日期
-     */
-    @TableField(value = "pay_time")
-    private LocalDateTime payTime;
-
-    /**
-     * 付款确认人
+     * 待付金额
      */
-    @TableField(value = "pay_user_id")
-    private Long payUserId;
+    @TableField(value = "topay_price")
+    private BigDecimal topayPrice;
 
     /**
      * 付款附件
      */
-    @TableField(value = "pay_urls")
-    private String payUrls;
+    @TableField(value = "url")
+    private String url;
 
     /**
      * 备注
      */
-    @TableField(value = "remark")
     private String remark;
 
     /**
      * 状态:0正常/1锁定
      */
-    @TableField(value = "`status`")
+    @TableField(value = "status")
     private Integer status;
 
     /**
@@ -149,22 +112,5 @@ public class KwpSettlementOffline {
     @TableField(value = "del_flag")
     private Integer delFlag;
 
-    /**
-     * 结算单类型 1-物流 2-贸易
-     */
-    @TableField(value = "order_type")
-    private Integer orderType;
-
-    /**
-     * 待付金额
-     */
-    @TableField(value = "topay_price")
-    private BigDecimal topayPrice;
-
-    /**
-     * 付款附件
-     */
-    @TableField(value = "url")
-    private String url;
 
 }

+ 4 - 4
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/constant/SettlementWalletPayTypeEnum.java → sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/constant/SettlementPayTypeEnum.java

@@ -5,15 +5,15 @@ package com.sckw.payment.model.constant;
  * @author Aick Spt
  * @date 2023-07-20 08:35
  */
-public enum SettlementWalletPayTypeEnum {
+public enum SettlementPayTypeEnum {
     ADVANCE_PAYMENT(1, "预付款"),
-    CASH_ON_DELIVERY(2, "货到付款");
-//    OFFLINE_PAYMENT(3, "线下付款");
+    CASH_ON_DELIVERY(2, "货到付款"),
+    OFFLINE_PAYMENT(3, "线下付款");
 
     private int status;
     private String desc;
 
-    SettlementWalletPayTypeEnum(int status, String desc) {
+    SettlementPayTypeEnum(int status, String desc) {
         this.status = status;
         this.desc = desc;
     }

+ 34 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/req/OfflinePaymentReq.java

@@ -0,0 +1,34 @@
+package com.sckw.payment.model.vo.req;
+
+import com.sckw.core.model.vo.BasePara;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.Setter;
+
+import java.io.Serial;
+import java.math.BigDecimal;
+
+/**
+ * @author Aick Spt
+ * @date 2023-07-27 19:52
+ */
+@Getter
+@Setter
+public class OfflinePaymentReq extends BasePara {
+
+    @Serial
+    private static final long serialVersionUID = -4568239842231210898L;
+
+    @NotBlank
+    private String id;
+
+    @NotNull
+    private BigDecimal price;
+
+    @NotBlank
+    private String url;
+
+
+}

+ 11 - 2
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementLogisticsService.java

@@ -2,6 +2,7 @@ package com.sckw.payment.service;
 
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.payment.dao.KwpSettlementLogisticsMapper;
 import com.sckw.payment.model.KwpSettlementLogistics;
@@ -161,7 +162,11 @@ public class KwpSettlementLogisticsService {
      * @date 2023-07-24 16:22
      */
     public SettlementLogisticsDto detailCollection(Long id) {
-        return settlementLogisticsMapper.detailCollection(id);
+        SettlementLogisticsDto settlementLogisticsDto = settlementLogisticsMapper.detailCollection(id);
+        if (settlementLogisticsDto == null) {
+            throw new BusinessException("查无数据");
+        }
+        return settlementLogisticsDto;
     }
 
     /**
@@ -171,7 +176,11 @@ public class KwpSettlementLogisticsService {
      * @date 2023-07-24 16:24
      */
     public SettlementLogisticsDto detailPayment(Long id) {
-        return settlementLogisticsMapper.detailPayment(id);
+        SettlementLogisticsDto settlementLogisticsDto = settlementLogisticsMapper.detailPayment(id);
+        if (settlementLogisticsDto == null) {
+            throw new BusinessException("查无数据");
+        }
+        return settlementLogisticsDto;
     }
 
 

+ 73 - 17
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementOfflineService.java

@@ -2,14 +2,19 @@ package com.sckw.payment.service;
 
 import com.github.pagehelper.PageHelper;
 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.payment.dao.KwpSettlementLogisticsMapper;
 import com.sckw.payment.dao.KwpSettlementOfflineMapper;
+import com.sckw.payment.model.KwpSettlementLogistics;
 import com.sckw.payment.model.KwpSettlementOffline;
-import com.sckw.payment.model.constant.SettlementWalletPayTypeEnum;
+import com.sckw.payment.model.constant.SettlementEnum;
+import com.sckw.payment.model.constant.SettlementOrderTypeEnum;
+import com.sckw.payment.model.dto.SettlementLogisticsDto;
 import com.sckw.payment.model.dto.SettlementOfflineDto;
+import com.sckw.payment.model.vo.req.OfflinePaymentReq;
 import com.sckw.payment.model.vo.req.SettlementOfflineReq;
-import com.sckw.payment.model.vo.req.SettlementReq;
 import com.sckw.payment.model.vo.res.SettlementOfflineVo;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -17,6 +22,8 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -31,8 +38,13 @@ public class KwpSettlementOfflineService {
 
     private final KwpSettlementOfflineMapper settlementOfflineMapper;
 
+    private final KwpSettlementLogisticsService kwpSettlementLogisticsService;
+
+    private final KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
+
     /**
      * 物流-线下付款(运费收款)记录-列表
+     *
      * @author Aick Spt
      * @date 2023-07-26 17:15
      */
@@ -80,30 +92,74 @@ public class KwpSettlementOfflineService {
     /**
      * 物流-线下付款(运费收款)记录-新增
      *
-     * @param id    结算单id
-     * @param price 付款金额
      * @return InsertId
      * @author Aick Spt
      * @date 2023-07-20 14:23
      */
-    public Integer confirmLogisticsCollection(Long id, Float price) {
-        log.info("接收到数据,开始物流-物流-线下付款(运费收款)记录-新增,待完善");
-        //todo 待完善
+    public Integer confirmLogisticsCollection(OfflinePaymentReq offlinePaymentReq) {
+        log.info("接收到数据,开始物流-物流-线下付款(运费收款)记录-新增");
         //先查询出结算单情况
+        Long id = offlinePaymentReq.getIdLong();
+        BigDecimal price = offlinePaymentReq.getPrice();
+        String url = offlinePaymentReq.getUrl();
 
+        SettlementLogisticsDto settlementLogisticsDto = kwpSettlementLogisticsService.detailPayment(id);
+        log.info(String.valueOf(settlementLogisticsDto));
         //检查结算单状态和所差金额
+        if (settlementLogisticsDto == null) {
+            log.error("非法请求,查无数据:" + id);
+            throw new BusinessException("非法请求运费结算参数ID");
+        }
+        if (settlementLogisticsDto.getStatus() == SettlementEnum.ALL_PAYMENT.getStatus()) {
+            log.error("非法请求,该订单已结算完成:" + id);
+            throw new BusinessException("该订单已结算完成,无法操作");
+        }
+        BigDecimal remainingReceivables = settlementLogisticsDto.getTotalPrice();
+        if (settlementLogisticsDto.getActualPrice() != null) {//剩余金额
+            remainingReceivables = settlementLogisticsDto.getTotalPrice().subtract(settlementLogisticsDto.getActualPrice());
+        }
 
-        //对比金额
-
+        if (remainingReceivables.compareTo(price) < 0) {//-1表示小于,0是等于,1是大于
+            log.error("本次结算输入金额比剩余付款金额大:ID:" + id + " 剩余金额:" + remainingReceivables + " 本次输入金额:" + price);
+            throw new BusinessException("参数错误:输入金额过大 " + price + " 剩余金额最大值:" + remainingReceivables);
+        }
         //累加入库结算单
-
-        //新增电子钱包结算记录
-        KwpSettlementOffline kwpSettlementOffline = new KwpSettlementOffline();
-        kwpSettlementOffline.setId(new IdWorker(1).nextId());
-
-        //todo 待完善
-        settlementOfflineMapper.insert(kwpSettlementOffline);
-        return settlementOfflineMapper.confirmLogisticsCollection(id, price);
+        KwpSettlementLogistics settlementLogistics1 = new KwpSettlementLogistics();
+        settlementLogistics1.setId(settlementLogisticsDto.getId());
+        settlementLogistics1.setUpdateTime(LocalDateTime.now());
+        if (remainingReceivables.compareTo(price) == 0) {//全部结算
+            settlementLogistics1.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
+        }
+        if (remainingReceivables.compareTo(price) > 0) {//部分结算
+            settlementLogistics1.setStatus(SettlementEnum.PARTIAL_PAYMENT.getStatus());
+        }
+        BigDecimal actualPrice = settlementLogisticsDto.getActualPrice();
+        settlementLogistics1.setActualPrice((actualPrice == null) ? price : actualPrice.add(price));
+        int upInt = kwpSettlementLogisticsMapper.updateById(settlementLogistics1);
+        if (upInt > 0) {
+            //新增一条线下结算记录
+            //当前剩余金额
+            remainingReceivables = remainingReceivables.subtract(price);
+            //入库
+            KwpSettlementOffline kwpSettlementOffline = new KwpSettlementOffline();
+            kwpSettlementOffline.setId(new IdWorker(1).nextId());
+            kwpSettlementOffline.setEntId(settlementLogisticsDto.getEntId());
+            kwpSettlementOffline.setSettlementId(settlementLogisticsDto.getId());
+            kwpSettlementOffline.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
+            kwpSettlementOffline.setPayTime(LocalDateTime.now());
+            kwpSettlementOffline.setPayPrice(price);
+            kwpSettlementOffline.setTopayPrice(remainingReceivables);
+            kwpSettlementOffline.setUrl(url);
+            kwpSettlementOffline.setRemark("");
+            kwpSettlementOffline.setStatus(1);
+            kwpSettlementOffline.setCreateBy(1L);//todo 待处理明确创建人
+            kwpSettlementOffline.setCreateTime(LocalDateTime.now());
+            kwpSettlementOffline.setUpdateBy(1L);//todo 待处理明确更新人
+            kwpSettlementOffline.setUpdateTime(LocalDateTime.now());
+            kwpSettlementOffline.setDelFlag(0);
+            return settlementOfflineMapper.insert(kwpSettlementOffline);
+        }
+        return null;
     }
 
     public PageRes<SettlementOfflineVo> pageListTradeCollection(SettlementOfflineReq settlementOfflineReq) {

+ 4 - 5
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementWalletService.java

@@ -13,7 +13,7 @@ import com.sckw.payment.model.KwpSettlementTrade;
 import com.sckw.payment.model.KwpSettlementWallet;
 import com.sckw.payment.model.constant.SettlementEnum;
 import com.sckw.payment.model.constant.SettlementOrderTypeEnum;
-import com.sckw.payment.model.constant.SettlementWalletPayTypeEnum;
+import com.sckw.payment.model.constant.SettlementPayTypeEnum;
 import com.sckw.payment.model.constant.WalletChannelEnum;
 import com.sckw.payment.model.dto.SettlementLogisticsDto;
 import com.sckw.payment.model.dto.SettlementTradeDto;
@@ -30,7 +30,6 @@ import org.springframework.util.CollectionUtils;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.List;
-import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
@@ -65,7 +64,7 @@ public class KwpSettlementWalletService {
 //            System.out.println("关键之:" + keywords);
 //        }
         PageHelper.startPage(settlementWalletReq.getPage(), settlementWalletReq.getPageSize());
-        settlementWalletReq.setPayType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());//只筛选 货到付款
+        settlementWalletReq.setPayType(SettlementPayTypeEnum.CASH_ON_DELIVERY.getStatus());//只筛选 货到付款
         List<SettlementWalletDto> settlementWalletLogisticsList = settlementWalletMapper.pageListLogisticsPayment(settlementWalletReq);
 
         if (CollectionUtils.isEmpty(settlementWalletLogisticsList)) {
@@ -158,7 +157,7 @@ public class KwpSettlementWalletService {
             kwpSettlementWallet.setPayTime(LocalDateTime.now());
             kwpSettlementWallet.setPayPrice(price);
             kwpSettlementWallet.setTopayPrice(remainingReceivables);
-            kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
+            kwpSettlementWallet.setType(SettlementPayTypeEnum.CASH_ON_DELIVERY.getStatus());
             kwpSettlementWallet.setRemark("");
             kwpSettlementWallet.setStatus(1);
             kwpSettlementWallet.setCreateBy(1L);//todo 待处理明确创建人
@@ -258,7 +257,7 @@ public class KwpSettlementWalletService {
             kwpSettlementWallet.setPayTime(LocalDateTime.now());
             kwpSettlementWallet.setPayPrice(price);
             kwpSettlementWallet.setTopayPrice(remainingReceivables);
-            kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
+            kwpSettlementWallet.setType(SettlementPayTypeEnum.CASH_ON_DELIVERY.getStatus());
             kwpSettlementWallet.setRemark("");
             kwpSettlementWallet.setStatus(1);
             kwpSettlementWallet.setCreateBy(1L);//todo 待处理明确创建人