|
|
@@ -74,7 +74,7 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
private UserBenefitsService userBenefitsService;
|
|
|
|
|
|
@Override
|
|
|
- public GoodsWholesaleOrderDon unifiedPay(GoodsWholesaleOrderPayReq payReq) {
|
|
|
+ public GoodsWholesaleOrderDon unifiedPay(GoodsWholesaleOrderPayReq payReq) throws Exception {
|
|
|
Long userId = payReq.getUserId();
|
|
|
Long id = payReq.getId();
|
|
|
GoodsWholesale goodsWholesale = goodsWholesaleMapper.selectById(id);
|
|
|
@@ -94,7 +94,7 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
if (selectCount > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("已有待支付订单");
|
|
|
}
|
|
|
- BigDecimal singlePrice = goodsWholesale.getSingle();
|
|
|
+ BigDecimal singlePrice = getNeedPaySinglePrice(payReq.getNum(), goodsWholesale, userIdList);
|
|
|
GoodsDonSku sku = skuMapper.selectById(goodsWholesale.getSkuId());
|
|
|
if (sku == null) {
|
|
|
throw BusinessRuntimeException.getInstance("规格不存在");
|
|
|
@@ -122,7 +122,6 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
goodsWholesaleOrderDonMapper.insert(orderDon);
|
|
|
return orderDon;
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public AliPayParams aliPayWholesale(AlipayOrderDonReq re, String productCode, String qrPayMode) throws Exception {
|
|
|
if (!re.getIsDeposit()) {
|
|
|
@@ -206,7 +205,7 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
//直接买到最高
|
|
|
Integer priceDifferNum = null;
|
|
|
BigDecimal differPrice = null;
|
|
|
- if (payNum > endConfig.getEnd()) {
|
|
|
+ if (payNum >= endConfig.getStart()) {
|
|
|
//将之前的全部返还余额差价
|
|
|
priceDifferNum = endConfig.getStart() - 1;
|
|
|
if (goodsWholesaleUserReturnRecord != null) {
|
|
|
@@ -215,18 +214,16 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
}
|
|
|
differPrice = endConfig.getSingle().subtract(firstConfig.getSingle());
|
|
|
}
|
|
|
- if (goodsWholesaleUserReturnRecord != null) {
|
|
|
+ if (goodsWholesaleUserReturnRecord != null && priceDifferNum == null) {
|
|
|
//寻找符合条件的目前挡位的配置
|
|
|
- Optional<GoodsWholesale.GoodsWholesaleConfig> first = configs.stream().filter(config -> config.getStart() < goodsWholesaleUserReturnRecord.getNum() && config.getEnd() > goodsWholesaleUserReturnRecord.getNum()).collect(Collectors.toList()).stream().findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- GoodsWholesale.GoodsWholesaleConfig thisLevel = first.get();
|
|
|
- log.info("目前批发挡位设置是start:{} ======> end:{}", thisLevel.getStart(), thisLevel.getEnd());
|
|
|
- priceDifferNum = thisLevel.getStart() - 1;
|
|
|
- if (goodsWholesaleUserReturnRecord != null) {
|
|
|
- priceDifferNum = priceDifferNum - goodsWholesaleUserReturnRecord.getNum();
|
|
|
- }
|
|
|
- differPrice = thisLevel.getSingle().subtract(firstConfig.getSingle());
|
|
|
+ Optional<GoodsWholesale.GoodsWholesaleConfig> first = configs.stream().filter(config -> config.getStart() <= goodsWholesaleUserReturnRecord.getNum() && config.getEnd() >= goodsWholesaleUserReturnRecord.getNum()).collect(Collectors.toList()).stream().findFirst();
|
|
|
+ GoodsWholesale.GoodsWholesaleConfig thisLevel = first.get();
|
|
|
+ log.info("目前批发挡位设置是start:{} ======> end:{}", thisLevel.getStart(), thisLevel.getEnd());
|
|
|
+ priceDifferNum = thisLevel.getStart() - 1;
|
|
|
+ if (goodsWholesaleUserReturnRecord != null) {
|
|
|
+ priceDifferNum = priceDifferNum - goodsWholesaleUserReturnRecord.getNum();
|
|
|
}
|
|
|
+ differPrice = thisLevel.getSingle().subtract(firstConfig.getSingle());
|
|
|
}
|
|
|
if (priceDifferNum != null && differPrice != null) {
|
|
|
BigDecimal returnBalance = differPrice.multiply(BigDecimal.valueOf(priceDifferNum));
|
|
|
@@ -378,4 +375,27 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private BigDecimal getNeedPaySinglePrice(Integer thisPayNum, GoodsWholesale goodsWholesale, List<Long> userIdList) throws Exception {
|
|
|
+ String configStr = goodsWholesale.getConfig();
|
|
|
+ List<GoodsWholesale.GoodsWholesaleConfig> configs = Jsons.parseList(configStr, GoodsWholesale.GoodsWholesaleConfig.class);
|
|
|
+ GoodsWholesale.GoodsWholesaleConfig firstConfig = configs.get(0);
|
|
|
+ GoodsWholesale.GoodsWholesaleConfig endConfig = configs.get(configs.size() - 1);
|
|
|
+ Integer endPayNum = goodsWholesaleOrderDonMapper.getUserWholesaleNumByUserIds(userIdList) + thisPayNum;
|
|
|
+ //移除第一档
|
|
|
+ configs.remove(firstConfig);
|
|
|
+ //移除倒数第一档
|
|
|
+ configs.remove(endConfig);
|
|
|
+ //未超过第一档
|
|
|
+ if (endPayNum <= firstConfig.getEnd()) {
|
|
|
+ return firstConfig.getSingle();
|
|
|
+ }
|
|
|
+ if (endPayNum >= endConfig.getStart()) {
|
|
|
+ return endConfig.getSingle();
|
|
|
+ }
|
|
|
+ Optional<GoodsWholesale.GoodsWholesaleConfig> first = configs.stream().filter(config -> config.getStart() <= endPayNum && config.getEnd() >= endPayNum).collect(Collectors.toList()).stream().findFirst();
|
|
|
+ GoodsWholesale.GoodsWholesaleConfig thisLevel = first.get();
|
|
|
+ return thisLevel.getSingle();
|
|
|
+ }
|
|
|
+
|
|
|
}
|