|
|
@@ -2,13 +2,16 @@ package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
|
|
|
import static com.ym.mec.biz.dal.enums.GroupType.GOODS_SELL;
|
|
|
+import static com.ym.mec.biz.dal.enums.GroupType.MUSIC;
|
|
|
import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.*;
|
|
|
import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.ORGAN_SHARE_PROFIT;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -271,7 +274,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
public List<SellOrder> addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails,
|
|
|
StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup,BigDecimal balancePaymentAmount) {
|
|
|
//过去非商品详情
|
|
|
- List<StudentPaymentOrderDetail> goodsOrderDetails = orderDetails.stream().filter(e -> StringUtils.isEmpty(e.getGoodsIdList())).collect(Collectors.toList());
|
|
|
+ List<StudentPaymentOrderDetail> goodsOrderDetails = orderDetails.stream().filter(e -> StringUtils.isNotEmpty(e.getGoodsIdList())).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(goodsOrderDetails)){
|
|
|
throw new BizException("商品详情为空");
|
|
|
}
|
|
|
@@ -289,11 +292,17 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
//剩余待分配现金
|
|
|
BigDecimal subDetailActualAmount = detailTotalPrice.subtract(balancePaymentAmount);
|
|
|
for (int i = 0; i < goodsOrderDetails.size(); i++) {
|
|
|
- StudentPaymentOrderDetail orderDetail = orderDetails.get(i);
|
|
|
+ StudentPaymentOrderDetail orderDetail = goodsOrderDetails.get(i);
|
|
|
//获取支付金额比例
|
|
|
- BigDecimal ratioAmount = orderDetail.getPrice().divide(detailTotalPrice, 6, BigDecimal.ROUND_HALF_UP);
|
|
|
- //获取优惠券金额比例
|
|
|
- BigDecimal ratioCouponAmount = orderDetail.getRemitFee().divide(detailTotalRemitPrice, 6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal ratioAmount = BigDecimal.ZERO;
|
|
|
+ if(detailTotalPrice.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ ratioAmount = orderDetail.getPrice().divide(detailTotalPrice, 6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ BigDecimal ratioCouponAmount = BigDecimal.ZERO;
|
|
|
+ if (detailTotalRemitPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //获取优惠券金额比例
|
|
|
+ ratioCouponAmount = orderDetail.getRemitFee().divide(detailTotalRemitPrice, 6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
//获取分配的余额
|
|
|
BigDecimal detailBalance;
|
|
|
//获取分配的优惠券金额
|
|
|
@@ -319,7 +328,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
subDetailActualAmount = subDetailActualAmount.subtract(detailActualAmount);
|
|
|
}
|
|
|
List<Integer> goodsIds = Arrays.asList(orderDetail.getGoodsIdList().split(",")).stream().map(Integer::parseInt).collect(Collectors.toList());
|
|
|
- sellOrders.addAll(this.initSellOrder(studentPaymentOrder, musicGroup.getId(), goodsIds, null,
|
|
|
+ sellOrders.addAll(this.initSellOrder(studentPaymentOrder, musicGroup.getId(), goodsIds, orderDetail.getKitGroupPurchaseType(),
|
|
|
detailBalance, orderDetail.getPrice(), couponRemitFee, detailActualAmount, false));
|
|
|
}
|
|
|
|
|
|
@@ -552,7 +561,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
public List<OrderCreate.OrderItem> convertMallOrder(List<SellOrder> sellOrderList) {
|
|
|
List<OrderCreate.OrderItem> orderItems = new ArrayList<>();
|
|
|
for (SellOrder e : sellOrderList) {
|
|
|
- List<GoodsSub> list = goodsSubService.lambdaQuery().eq(GoodsSub::getGoodsId, e.getGoodsId()).list();
|
|
|
+ List<GoodsSub> list = goodsSubService.lambdaQuery().eq(GoodsSub::getGoodsId, e.getParentGoodsId()).list();
|
|
|
if(CollectionUtils.isEmpty(list)){
|
|
|
throw new RuntimeException("子商品不存在,请联系管理员");
|
|
|
}
|
|
|
@@ -627,7 +636,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,
|
|
|
- BigDecimal totalBalance, BigDecimal expectTotalAmount, BigDecimal couponRemitAmount, BigDecimal actualTotalAmount,Boolean saveFlag) {
|
|
|
+ BigDecimal totalBalance, BigDecimal expectTotalAmount, BigDecimal couponRemitAmount,
|
|
|
+ BigDecimal actualTotalAmount, Boolean saveFlag) {
|
|
|
//可用优惠券金额
|
|
|
BigDecimal subCouponRemitAmount = couponRemitAmount;
|
|
|
//可用总金额
|
|
|
@@ -649,6 +659,9 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
String skuIds = goodsSubService.lambdaQuery().in(GoodsSub::getGoodsId, goodies.stream().map(Goods::getId).collect(Collectors.toList())).list()
|
|
|
.stream().map(e->e.getSku().toString()).collect(Collectors.joining(","));
|
|
|
paramDto.setSkuStockIds(skuIds);
|
|
|
+ paramDto.setPageSize(1000);
|
|
|
+ paramDto.setPageNum(1);
|
|
|
+ paramDto.setJson(JSON.toJSONString(paramDto));
|
|
|
PageInfo<PmsProductDto> productList = mallFeignService.getProductList(paramDto);
|
|
|
if (org.springframework.util.CollectionUtils.isEmpty(productList.getRows())) {
|
|
|
throw new BizException("商城商品不存在");
|
|
|
@@ -669,7 +682,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
BigDecimal actualAmount;
|
|
|
|
|
|
if (goodsTotalPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- goodsRatioAmount = nowGoods.getGroupPurchasePrice().divide(goodsTotalPrice, 6, RoundingMode.HALF_UP);
|
|
|
+ goodsRatioAmount = order.getGroupType() == MUSIC ?nowGoods.getGroupPurchasePrice():nowGoods.getDiscountPrice()
|
|
|
+ .divide(goodsTotalPrice, 6, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
if(i == goodies.size() - 1){
|
|
|
expectAmount = subExpectTotalAmount;
|
|
|
@@ -695,7 +709,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
//剩余实际金额
|
|
|
BigDecimal subActualAmount = actualAmount;
|
|
|
//租赁、免费的没有销售收入,有销售成本
|
|
|
- if (nowGoods.getType().equals(GoodsType.INSTRUMENT) && (kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.LEASE) || kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.FREE))) {
|
|
|
+ if (nowGoods.getType().equals(GoodsType.INSTRUMENT) && kitGroupPurchaseType != null &&
|
|
|
+ (kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.LEASE) || kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.FREE))) {
|
|
|
goodsBalance = BigDecimal.ZERO;
|
|
|
expectAmount = BigDecimal.ZERO;
|
|
|
}
|
|
|
@@ -768,7 +783,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,Boolean saveFlag) {
|
|
|
+ public List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds,
|
|
|
+ KitGroupPurchaseTypeEnum kitGroupPurchaseType,Boolean saveFlag) {
|
|
|
BigDecimal totalBalance = order.getBalancePaymentAmount();
|
|
|
if (totalBalance == null) {
|
|
|
totalBalance = BigDecimal.ZERO;
|
|
|
@@ -776,7 +792,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
BigDecimal expectTotalAmount = order.getExpectAmount();
|
|
|
BigDecimal couponRemitAmount = order.getCouponRemitFee();
|
|
|
BigDecimal actualTotalAmount = order.getActualAmount();
|
|
|
- return this.initSellOrder(order, musicGroupId, goodsIds, kitGroupPurchaseType, totalBalance, expectTotalAmount, couponRemitAmount, actualTotalAmount,saveFlag==null?true:saveFlag);
|
|
|
+ return this.initSellOrder(order, musicGroupId, goodsIds, kitGroupPurchaseType, totalBalance, expectTotalAmount,
|
|
|
+ couponRemitAmount, actualTotalAmount,saveFlag==null?true:saveFlag);
|
|
|
}
|
|
|
|
|
|
public Map<String, BigDecimal> calcSellAmount(StudentPaymentOrder order,BigDecimal cloudBalanceIncome,BigDecimal cloudIncome) {
|