|
|
@@ -5,11 +5,18 @@ 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.KwpSettlementTradeMapper;
|
|
|
import com.sckw.payment.dao.KwpSettlementWalletMapper;
|
|
|
+import com.sckw.payment.model.KwpSettlementLogistics;
|
|
|
+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.WalletChannelEnum;
|
|
|
import com.sckw.payment.model.dto.SettlementLogisticsDto;
|
|
|
+import com.sckw.payment.model.dto.SettlementTradeDto;
|
|
|
import com.sckw.payment.model.dto.SettlementWalletDto;
|
|
|
import com.sckw.payment.model.vo.req.SettlementWalletReq;
|
|
|
import com.sckw.payment.model.vo.res.SettlementWalletVo;
|
|
|
@@ -17,8 +24,11 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
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;
|
|
|
@@ -34,8 +44,14 @@ public class KwpSettlementWalletService {
|
|
|
|
|
|
private final KwpSettlementWalletMapper settlementWalletMapper;
|
|
|
|
|
|
+ private final KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
|
|
|
+
|
|
|
private final KwpSettlementLogisticsService kwpSettlementLogisticsService;
|
|
|
|
|
|
+ private final KwpSettlementTradeService kwpSettlementTradeService;
|
|
|
+
|
|
|
+ private final KwpSettlementTradeMapper kwpSettlementTradeMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 物流-电子钱包付款(货到付款)结算记录-列表
|
|
|
*
|
|
|
@@ -91,35 +107,73 @@ public class KwpSettlementWalletService {
|
|
|
* @return InsertId
|
|
|
* @author Aick Spt
|
|
|
* @date 2023-07-20 14:23
|
|
|
+ * <p>
|
|
|
+ * Transactional// isolation:事务的隔离级别,此处使用后端数据库的默认隔离级别, propagation: 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中(常见)。(rollbackFor = Exception.class, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
|
|
|
*/
|
|
|
- public Integer confirmLogisticsPayment(Long id, Float price) {
|
|
|
- log.info("接收到数据,开始物流-电子钱包付款(货到付款)结算记录-新增,待完善");
|
|
|
- //todo 待完善
|
|
|
+ @Transactional
|
|
|
+ public Integer confirmLogisticsPayment(Long id, BigDecimal price) {
|
|
|
//先查询出结算单情况
|
|
|
- SettlementLogisticsDto settlementLogistics = kwpSettlementLogisticsService.detailPayment(id);
|
|
|
- log.info(String.valueOf(settlementLogistics));
|
|
|
+ SettlementLogisticsDto settlementLogisticsDto = kwpSettlementLogisticsService.detailPayment(id);
|
|
|
+ log.info(String.valueOf(settlementLogisticsDto));
|
|
|
//检查结算单状态和所差金额
|
|
|
- if (settlementLogistics == null) {
|
|
|
+ if (settlementLogisticsDto == null) {
|
|
|
log.error("非法请求,查无数据:" + id);
|
|
|
throw new BusinessException("非法请求运费结算参数ID");
|
|
|
}
|
|
|
- if (settlementLogistics.getStatus() == SettlementEnum.ALL_PAYMENT.getStatus()) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
//累加入库结算单
|
|
|
-
|
|
|
- //扣费电子钱包
|
|
|
-
|
|
|
- //新增电子钱包结算记录
|
|
|
- KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
- kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
- //todo 待完善
|
|
|
- settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
- return settlementWalletMapper.confirmLogisticsPayment(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);
|
|
|
+ KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
+ kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
+ kwpSettlementWallet.setEntId(settlementLogisticsDto.getEntId());
|
|
|
+ kwpSettlementWallet.setSettlementId(settlementLogisticsDto.getId());
|
|
|
+ kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
|
|
|
+ kwpSettlementWallet.setChannel(WalletChannelEnum.HF.getStatus());//先用数字默认定义为1
|
|
|
+ kwpSettlementWallet.setPayTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setPayPrice(price);
|
|
|
+ kwpSettlementWallet.setTopayPrice(remainingReceivables);
|
|
|
+ kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.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;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
public PageRes<SettlementWalletVo> pageListTradePayment(SettlementWalletReq settlementWalletReq) {
|
|
|
@@ -151,25 +205,75 @@ public class KwpSettlementWalletService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Integer confirmTradePayment(Long id, Float price) {
|
|
|
- log.info("接收到数据,开始物流-销售-付款确认-(新增电子钱包记录-采购货到付款)-新增,待完善");
|
|
|
- //todo 待完善
|
|
|
+ /**
|
|
|
+ * 销售-付款确认-(新增电子钱包记录-采购货到付款)
|
|
|
+ *
|
|
|
+ * @author Aick Spt
|
|
|
+ * @date 2023-07-27 16:13
|
|
|
+ */
|
|
|
+ public Integer confirmTradePayment(Long id, BigDecimal price) {
|
|
|
//先查询出结算单情况
|
|
|
-
|
|
|
+ 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);
|
|
|
+ }
|
|
|
//累加入库结算单
|
|
|
-
|
|
|
- //扣费电子钱包
|
|
|
-
|
|
|
- //新增电子钱包结算记录
|
|
|
- KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
- kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
- //todo 待完善
|
|
|
- settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
- return settlementWalletMapper.confirmLogisticsPayment(id, price);
|
|
|
+ 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(SettlementWalletPayTypeEnum.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;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
public PageRes<SettlementWalletVo> pageListTradeCollection(SettlementWalletReq settlementWalletReq) {
|