|
|
@@ -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) {
|