|
|
@@ -1,5 +1,6 @@
|
|
|
package com.cyksj.service.order.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
@@ -91,6 +92,8 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
|
|
|
private final GoodsDonMapper goodsDonMapper;
|
|
|
|
|
|
+ private final GoodsWholesaleUserSkuPayRecordMapper goodsWholesaleUserSkuPayRecordMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public GoodsWholesaleOrderDon unifiedPay(GoodsWholesaleOrderPayReq payReq) throws Exception {
|
|
|
Long userId = payReq.getUserId();
|
|
|
@@ -144,6 +147,11 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
}
|
|
|
orderDon.setType(GoodsWholesaleOrderDon.Type.ALI_PAY);
|
|
|
goodsWholesaleOrderDonMapper.insert(orderDon);
|
|
|
+ //是否需要记录差价
|
|
|
+ if (orderDon.getIsRecordDiffer()) {
|
|
|
+ //记录此时购买该级别的数量 返差价
|
|
|
+ recordUserPaySkuDifferPrice(orderDon);
|
|
|
+ }
|
|
|
//已支付回调
|
|
|
if (orderDon.getStatus() == GoodsWholesaleOrderDon.Status.hasPayment) {
|
|
|
//处理批发订单回调
|
|
|
@@ -151,6 +159,19 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
}
|
|
|
return orderDon;
|
|
|
}
|
|
|
+
|
|
|
+ private void recordUserPaySkuDifferPrice(GoodsWholesaleOrderDon orderDon) {
|
|
|
+ GoodsWholesaleUserSkuPayRecord skuPayRecord = new GoodsWholesaleUserSkuPayRecord();
|
|
|
+ skuPayRecord.setSkuId(orderDon.getSkuId());
|
|
|
+ skuPayRecord.setGoodsId(orderDon.getGoodsId());
|
|
|
+ skuPayRecord.setNum(orderDon.getNum());
|
|
|
+ BigDecimal totalMoney = orderDon.getMoney().add(Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO));
|
|
|
+ BigDecimal single = totalMoney.divide(BigDecimal.valueOf(orderDon.getNum()));
|
|
|
+ skuPayRecord.setSingle(single);
|
|
|
+ skuPayRecord.setOrderId(orderDon.getId());
|
|
|
+ goodsWholesaleUserSkuPayRecordMapper.insert(skuPayRecord);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public AliPayParams aliPayWholesale(AlipayOrderDonReq re, String productCode, String qrPayMode) throws Exception {
|
|
|
if (re.getIsDeposit()) {
|
|
|
@@ -239,15 +260,16 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
//最高
|
|
|
if (payNum >= endConfig.getStart()) {
|
|
|
BigDecimal returnBalance = BigDecimal.ZERO;
|
|
|
- for (GoodsWholesale.GoodsWholesaleConfig config : configs) {
|
|
|
- Integer thisPayNum;
|
|
|
- if (config.getStart().intValue() == firstConfig.getStart().intValue()) {
|
|
|
- thisPayNum = config.getEnd();
|
|
|
- } else {
|
|
|
- thisPayNum = config.getEnd() - config.getStart() + 1;
|
|
|
- }
|
|
|
- BigDecimal differPrice = config.getSingle().subtract(endConfig.getSingle());
|
|
|
- returnBalance = returnBalance.add(BigDecimal.valueOf(thisPayNum).multiply(differPrice));
|
|
|
+ List<GoodsWholesaleUserSkuPayRecord> userHasPaySkuDifferRecord = goodsWholesaleUserSkuPayRecordMapper.selectUserHasPaySkuDifferRecord(userIdList, skuId);
|
|
|
+ if (CollUtil.isEmpty(userHasPaySkuDifferRecord)) {
|
|
|
+ log.info("用户:{}无skuId:{}返差价的数量", orderDon.getUserId(), orderDon.getSkuId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BigDecimal endConfigSingle = endConfig.getSingle();
|
|
|
+ for (GoodsWholesaleUserSkuPayRecord skuPayRecord : userHasPaySkuDifferRecord) {
|
|
|
+ Integer num = skuPayRecord.getNum();
|
|
|
+ BigDecimal thisLevelSingle = skuPayRecord.getSingle();
|
|
|
+ returnBalance = returnBalance.add(thisLevelSingle.subtract(endConfigSingle).multiply(BigDecimal.valueOf(num)));
|
|
|
}
|
|
|
try {
|
|
|
log.info("用户:{}批发返skuId:{}差价", orderDon.getUserId(), skuId);
|
|
|
@@ -440,7 +462,7 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
}
|
|
|
GoodsWholesale.GoodsWholesaleConfig endConfig = configs.get(configs.size() - 1);
|
|
|
//超过最后
|
|
|
- if (hasPaidNum >= endConfig.getStart()) {
|
|
|
+ if (endPayNum >= endConfig.getStart()) {
|
|
|
orderDon.setMoney(BigDecimal.valueOf(thisPayNum).multiply(endConfig.getSingle()));
|
|
|
return;
|
|
|
}
|
|
|
@@ -448,23 +470,29 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
throw BusinessRuntimeException.getInstance("您已超过购买该规格批发数量");
|
|
|
}
|
|
|
Optional<GoodsWholesale.GoodsWholesaleConfig> first = configs.stream().filter(config -> config.getStart() <= endPayNum && config.getEnd() >= endPayNum).collect(Collectors.toList()).stream().findFirst();
|
|
|
- GoodsWholesale.GoodsWholesaleConfig finalLevel = first.get();
|
|
|
-
|
|
|
- //之前的
|
|
|
- List<GoodsWholesale.GoodsWholesaleConfig> before = configs.stream().filter(config -> config.getEnd() < finalLevel.getStart() && config.getEnd() > hasPaidNum).collect(Collectors.toList());
|
|
|
- BigDecimal finalPayMoney = BigDecimal.ZERO;
|
|
|
- Integer finalLevelPayNum = thisPayNum;
|
|
|
- Integer beforeHasPayNum = hasPaidNum;
|
|
|
- for (GoodsWholesale.GoodsWholesaleConfig goodsWholesaleConfig : before) {
|
|
|
- Integer thisLevelPayNum = goodsWholesaleConfig.getEnd() - beforeHasPayNum;
|
|
|
- beforeHasPayNum = goodsWholesaleConfig.getEnd();
|
|
|
- finalPayMoney = finalPayMoney.add(BigDecimal.valueOf(thisLevelPayNum).multiply(goodsWholesaleConfig.getSingle()));
|
|
|
- finalLevelPayNum -= thisLevelPayNum;
|
|
|
- }
|
|
|
- if (finalLevelPayNum > 0) {
|
|
|
- finalPayMoney = finalPayMoney.add(BigDecimal.valueOf(finalLevelPayNum).multiply(finalLevel.getSingle()));
|
|
|
- }
|
|
|
- orderDon.setMoney(finalPayMoney);
|
|
|
+ GoodsWholesale.GoodsWholesaleConfig thisLevel = first.get();
|
|
|
+ BigDecimal single = thisLevel.getSingle();
|
|
|
+ BigDecimal needPayMoney = BigDecimal.valueOf(thisPayNum).multiply(single);
|
|
|
+ orderDon.setMoney(needPayMoney);
|
|
|
+ //是否需要记录差价
|
|
|
+ orderDon.setIsRecordDiffer(true);
|
|
|
+
|
|
|
+
|
|
|
+// //之前的
|
|
|
+// List<GoodsWholesale.GoodsWholesaleConfig> before = configs.stream().filter(config -> config.getEnd() < finalLevel.getStart() && config.getEnd() > hasPaidNum).collect(Collectors.toList());
|
|
|
+// BigDecimal finalPayMoney = BigDecimal.ZERO;
|
|
|
+// Integer finalLevelPayNum = thisPayNum;
|
|
|
+// Integer beforeHasPayNum = hasPaidNum;
|
|
|
+// for (GoodsWholesale.GoodsWholesaleConfig goodsWholesaleConfig : before) {
|
|
|
+// Integer thisLevelPayNum = goodsWholesaleConfig.getEnd() - beforeHasPayNum;
|
|
|
+// beforeHasPayNum = goodsWholesaleConfig.getEnd();
|
|
|
+// finalPayMoney = finalPayMoney.add(BigDecimal.valueOf(thisLevelPayNum).multiply(goodsWholesaleConfig.getSingle()));
|
|
|
+// finalLevelPayNum -= thisLevelPayNum;
|
|
|
+// }
|
|
|
+// if (finalLevelPayNum > 0) {
|
|
|
+// finalPayMoney = finalPayMoney.add(BigDecimal.valueOf(finalLevelPayNum).multiply(finalLevel.getSingle()));
|
|
|
+// }
|
|
|
+// orderDon.setMoney(finalPayMoney);
|
|
|
}
|
|
|
|
|
|
/**
|