|
|
@@ -22,11 +22,16 @@ import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.AlipayOrderDonReq;
|
|
|
import com.cyksj.model.request.GoodsWholesaleOrderPayReq;
|
|
|
import com.cyksj.model.request.OrderAttach;
|
|
|
+import com.cyksj.model.views.GoodsWholesaleOrderDonView;
|
|
|
+import com.cyksj.model.views.GoodsWholesaleUserDepositView;
|
|
|
import com.cyksj.service.order.GoodsWholesalePayService;
|
|
|
import com.cyksj.service.order.OrderRefundService;
|
|
|
import com.cyksj.service.pay.AliPayCommonService;
|
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.param.Operator;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -75,6 +80,8 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
|
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
@Override
|
|
|
public GoodsWholesaleOrderDon unifiedPay(GoodsWholesaleOrderPayReq payReq) throws Exception {
|
|
|
Long userId = payReq.getUserId();
|
|
|
@@ -96,7 +103,6 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
if (selectCount > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("已有待支付订单");
|
|
|
}
|
|
|
- BigDecimal singlePrice = getNeedPaySinglePrice(payReq.getNum(), goodsWholesale, userIdList);
|
|
|
GoodsDonSku sku = skuMapper.selectById(goodsWholesale.getSkuId());
|
|
|
if (sku == null) {
|
|
|
throw BusinessRuntimeException.getInstance("规格不存在");
|
|
|
@@ -104,23 +110,16 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
if (!sku.getStatus()) {
|
|
|
throw BusinessRuntimeException.getInstance("规格已下架");
|
|
|
}
|
|
|
+ GoodsWholesaleOrderDon orderDon = new GoodsWholesaleOrderDon();
|
|
|
+ //设置订单金额
|
|
|
+ getNeedPaySinglePrice(orderDon, sku, payReq.getNum(), goodsWholesale, userIdList);
|
|
|
User user = userMapper.selectById(userId);
|
|
|
- //是否交过押金
|
|
|
- GoodsWholesaleUserDeposit deposit = depositMapper.selectOne(Wrappers.lambdaQuery(GoodsWholesaleUserDeposit.class)
|
|
|
- .in(GoodsWholesaleUserDeposit::getUserId, userIdList)
|
|
|
- .last("limit 1"));
|
|
|
- //未支付押金 或批发数量未达到且已退款 使用规格单价
|
|
|
- if (deposit == null || (!deposit.getIsGoal() && deposit.getStatus() == GoodsWholesaleUserDeposit.Status.refund)) {
|
|
|
- singlePrice = sku.getPrice();
|
|
|
- }
|
|
|
BigDecimal balance = payReq.getBalance();
|
|
|
- GoodsWholesaleOrderDon orderDon = new GoodsWholesaleOrderDon();
|
|
|
orderDon.setUserId(userId);
|
|
|
orderDon.setGoodsId(goodsWholesale.getGoodsId());
|
|
|
orderDon.setSkuId(goodsWholesale.getSkuId());
|
|
|
//批发id
|
|
|
orderDon.setPid(id);
|
|
|
- orderDon.setMoney(BigDecimal.valueOf(payReq.getNum()).multiply(singlePrice));
|
|
|
String orderNo = SEQUENCE.nextId().toString();
|
|
|
orderDon.setOrderNo(orderNo);
|
|
|
orderDon.setStatus(GoodsWholesaleOrderDon.Status.noPayment);
|
|
|
@@ -364,19 +363,14 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
public Object getOrderStatus(Long userId, Integer type, Long orderId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
if (type == 1) {
|
|
|
- GoodsWholesaleUserDeposit goodsWholesaleUserDeposit = depositMapper.selectOne(Wrappers.lambdaQuery(GoodsWholesaleUserDeposit.class)
|
|
|
- .in(GoodsWholesaleUserDeposit::getUserId, userIdList)
|
|
|
- .eq(GoodsWholesaleUserDeposit::getId, orderId)
|
|
|
- .last("limit 1"));
|
|
|
- if (goodsWholesaleUserDeposit != null) {
|
|
|
- goodsWholesaleUserDeposit.setIsDeposit(true);
|
|
|
+ GoodsWholesaleUserDepositView goodsWholesaleUserDepositView = beanSearcher.searchFirst(GoodsWholesaleUserDepositView.class, MapUtils.builder().field(GoodsWholesaleUserDepositView::getUserId, userIdList).op(Operator.InList).build());
|
|
|
+ if (goodsWholesaleUserDepositView != null) {
|
|
|
+ goodsWholesaleUserDepositView.setIsDeposit(true);
|
|
|
}
|
|
|
- return goodsWholesaleUserDeposit;
|
|
|
+ return goodsWholesaleUserDepositView;
|
|
|
}
|
|
|
- GoodsWholesaleOrderDon orderDon = goodsWholesaleOrderDonMapper.selectOne(Wrappers.lambdaQuery(GoodsWholesaleOrderDon.class)
|
|
|
- .in(GoodsWholesaleOrderDon::getUserId, userIdList)
|
|
|
- .eq(GoodsWholesaleOrderDon::getId, orderId)
|
|
|
- .last("limit 1"));
|
|
|
+ GoodsWholesaleOrderDonView orderDon = beanSearcher.searchFirst(GoodsWholesaleOrderDonView.class, MapUtils.builder().field(GoodsWholesaleOrderDonView::getUserId, userIdList).op(Operator.InList)
|
|
|
+ .field(GoodsWholesaleOrderDonView::getOrderId, orderId).build());
|
|
|
if (orderDon != null) {
|
|
|
orderDon.setIsDeposit(false);
|
|
|
}
|
|
|
@@ -420,26 +414,53 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private BigDecimal getNeedPaySinglePrice(Integer thisPayNum, GoodsWholesale goodsWholesale, List<Long> userIdList) throws Exception {
|
|
|
+ private void getNeedPaySinglePrice(GoodsWholesaleOrderDon orderDon, GoodsDonSku sku, Integer thisPayNum, GoodsWholesale goodsWholesale, List<Long> userIdList) throws Exception {
|
|
|
+ //是否交过押金
|
|
|
+ GoodsWholesaleUserDeposit deposit = depositMapper.selectOne(Wrappers.lambdaQuery(GoodsWholesaleUserDeposit.class)
|
|
|
+ .in(GoodsWholesaleUserDeposit::getUserId, userIdList)
|
|
|
+ .last("limit 1"));
|
|
|
+ //未支付押金 或批发数量未达到且已退款 使用规格单价
|
|
|
+ if (deposit == null || (!deposit.getIsGoal() && deposit.getStatus() == GoodsWholesaleUserDeposit.Status.refund)) {
|
|
|
+ orderDon.setMoney(BigDecimal.valueOf(thisPayNum).multiply(sku.getPrice()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
String configStr = goodsWholesale.getConfig();
|
|
|
List<GoodsWholesale.GoodsWholesaleConfig> configs = Jsons.parseList(configStr, GoodsWholesale.GoodsWholesaleConfig.class);
|
|
|
+ List<GoodsWholesale.GoodsWholesaleConfig> allConfigs = configs;
|
|
|
GoodsWholesale.GoodsWholesaleConfig firstConfig = configs.get(0);
|
|
|
GoodsWholesale.GoodsWholesaleConfig endConfig = configs.get(configs.size() - 1);
|
|
|
- Integer endPayNum = goodsWholesaleOrderDonMapper.getUserWholesaleNumByUserIds(userIdList, goodsWholesale.getSkuId()) + thisPayNum;
|
|
|
+ Integer hasPaidNum = goodsWholesaleOrderDonMapper.getUserWholesaleNumByUserIds(userIdList, goodsWholesale.getSkuId());
|
|
|
+ Integer endPayNum = hasPaidNum + thisPayNum;
|
|
|
//移除第一档
|
|
|
configs.remove(firstConfig);
|
|
|
//移除倒数第一档
|
|
|
configs.remove(endConfig);
|
|
|
//未超过第一档
|
|
|
if (endPayNum <= firstConfig.getEnd()) {
|
|
|
- return firstConfig.getSingle();
|
|
|
+ orderDon.setMoney(BigDecimal.valueOf(thisPayNum).multiply(firstConfig.getSingle()));
|
|
|
+ return;
|
|
|
}
|
|
|
- if (endPayNum >= endConfig.getStart()) {
|
|
|
- return endConfig.getSingle();
|
|
|
+ //超过最后
|
|
|
+ if (hasPaidNum >= endConfig.getStart()) {
|
|
|
+ orderDon.setMoney(BigDecimal.valueOf(thisPayNum).multiply(endConfig.getSingle()));
|
|
|
+ return;
|
|
|
}
|
|
|
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();
|
|
|
+ GoodsWholesale.GoodsWholesaleConfig finalLevel = first.get();
|
|
|
+
|
|
|
+ //之前的
|
|
|
+ List<GoodsWholesale.GoodsWholesaleConfig> before = allConfigs.stream().filter(config -> config.getEnd() < finalLevel.getStart() && config.getEnd() > hasPaidNum).collect(Collectors.toList());
|
|
|
+ BigDecimal finalPayMoney = BigDecimal.ZERO;
|
|
|
+ Integer finalLevelPayNum = endPayNum;
|
|
|
+ for (GoodsWholesale.GoodsWholesaleConfig goodsWholesaleConfig : before) {
|
|
|
+ Integer thisLevelPayNum = goodsWholesaleConfig.getEnd() - hasPaidNum;
|
|
|
+ finalPayMoney = finalPayMoney.add(BigDecimal.valueOf(thisLevelPayNum).add(goodsWholesaleConfig.getSingle()));
|
|
|
+ finalLevelPayNum -= thisLevelPayNum;
|
|
|
+ }
|
|
|
+ if (finalLevelPayNum > 0) {
|
|
|
+ finalPayMoney = finalPayMoney.add(BigDecimal.valueOf(finalLevelPayNum).add(finalLevel.getSingle()));
|
|
|
+ }
|
|
|
+ orderDon.setMoney(finalPayMoney);
|
|
|
}
|
|
|
|
|
|
/**
|