|
@@ -136,8 +136,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
if (studentId == null) {
|
|
|
throw new BizException("请指定学员");
|
|
|
}
|
|
|
-
|
|
|
+ List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
+ Map<Integer, String> integerStringMap = getMap("goods", "id_", "type_", goodsIds, Integer.class, String.class);
|
|
|
goodsSellDtos.forEach(e->{
|
|
|
+ e.setGoodsType(integerStringMap.get(e.getGoodsId()));
|
|
|
if(StringUtils.isNotEmpty(e.getComplementGoodsIdList())){
|
|
|
e.setGoodsSellDtos(goodsService.queryGoodsSellDtos(e.getComplementGoodsIdList()));
|
|
|
}
|
|
@@ -163,7 +165,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
studentGoodsSell.setCooperationOrganId(musicGroup.getCooperationOrganId());
|
|
|
}
|
|
|
}
|
|
|
- List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
|
|
|
Map<Integer, BigDecimal> map = getMap("goods", "id_", "market_price_", goodsIds, Integer.class, BigDecimal.class);
|
|
|
for (GoodsSellDto goodsSellDto : goodsSellDtos) {
|
|
@@ -748,15 +749,16 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(goodsJson, GoodsSellDto.class);
|
|
|
//用户选择的商品
|
|
|
Map<Integer, List<GoodsSellDto>> collect = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
- List<Integer> goodsId = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
-
|
|
|
List<Integer> goodsIds = new ArrayList<>();
|
|
|
goodsSellDtos.forEach(e->{
|
|
|
for (int i = 0; i < e.getGoodsNum(); i++) {
|
|
|
goodsIds.add(e.getGoodsId());
|
|
|
}
|
|
|
});
|
|
|
- AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(orderByOrderNo.getPaymentChannel()), orderByOrderNo.getMerNos());
|
|
|
+ AccountType accountType = AccountType.INTERNAL;
|
|
|
+ if(StringUtils.isNotEmpty(orderByOrderNo.getPaymentChannel())){
|
|
|
+ accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(orderByOrderNo.getPaymentChannel()), orderByOrderNo.getMerNos());
|
|
|
+ }
|
|
|
//实际扣减的库存商品
|
|
|
List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
|
|
|
Map<String, BigDecimal> costMap = new HashMap<>(2);
|
|
@@ -787,7 +789,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
//获取组合商品列表
|
|
|
List<SellOrder> orderList = sellOrderList.stream().filter(sellOrder -> sellOrder.getParentGoodsId() != null).collect(Collectors.toList());
|
|
|
- for (SellOrder sellOrder : orderList) {
|
|
|
+ Map<Integer, List<SellOrder>> orderListMap = orderList.stream().collect(Collectors.groupingBy(SellOrder::getParentGoodsId));
|
|
|
+ //获取组合商品实际销售价,和单个商品总和价
|
|
|
+ for (Integer integer : orderListMap.keySet()) {
|
|
|
+ SellOrder sellOrder = orderListMap.get(integer).get(0);
|
|
|
//获取组合商品销售总价
|
|
|
GoodsSellDto goodsSellDto = collect.get(sellOrder.getParentGoodsId()).get(0);
|
|
|
BigDecimal parentTotalGoodsPrice = goodsSellDto.getTotalGoodsPrice();
|
|
@@ -803,21 +808,32 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
parentGoodsCutTotalPriceMap.put(sellOrder.getParentGoodsId(),totalGoodsPrice.subtract(parentTotalGoodsPrice));
|
|
|
}
|
|
|
}
|
|
|
- noAmount:for (SellOrder sellOrder : orderList) {
|
|
|
- GoodsSellDto goodsSellDto = collect.get(sellOrder.getParentGoodsId()).get(0);
|
|
|
- List<GoodsSellDto> goodsSellDtoList = goodsSellDto.getGoodsSellDtos();
|
|
|
- BigDecimal addTotalPrice = parentGoodsAddTotalPriceMap.get(sellOrder.getParentGoodsId());
|
|
|
+ //分配组合商品的中单个商品的价格
|
|
|
+ noFreeAmount:for (Integer parentGoodsId : orderListMap.keySet()) {
|
|
|
+
|
|
|
+ BigDecimal addTotalPrice = parentGoodsAddTotalPriceMap.get(parentGoodsId);
|
|
|
usableParentGoodsAddTotalPrice = addTotalPrice;
|
|
|
- BigDecimal cutTotalPrice = parentGoodsCutTotalPriceMap.get(sellOrder.getParentGoodsId());
|
|
|
+ BigDecimal cutTotalPrice = parentGoodsCutTotalPriceMap.get(parentGoodsId);
|
|
|
usableParentGoodsCutTotalPrice = cutTotalPrice;
|
|
|
- for (int i = 0; i < goodsSellDtoList.size(); i++) {
|
|
|
- GoodsSellDto sellDto = goodsSellDtoList.get(i);
|
|
|
+
|
|
|
+ //获取组合商品销售总价
|
|
|
+ GoodsSellDto goodsSellDto = collect.get(parentGoodsId).get(0);
|
|
|
+ BigDecimal divide = goodsSellDto.getTotalGoodsPrice();
|
|
|
+
|
|
|
+ //获取子商品明细map
|
|
|
+ List<GoodsSellDto> sellDtos = goodsSellDto.getGoodsSellDtos();
|
|
|
+ Map<Integer, List<GoodsSellDto>> subGoodsMap = sellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
+
|
|
|
+ List<SellOrder> sellOrders = orderListMap.get(parentGoodsId);
|
|
|
+ for (int i = 0; i < sellOrders.size(); i++) {
|
|
|
+ SellOrder sellOrder = sellOrders.get(i);
|
|
|
+ GoodsSellDto sellDto = subGoodsMap.get(sellOrder.getGoodsId()).get(0);
|
|
|
//获取比例
|
|
|
- BigDecimal ratioAmount = sellDto.getTotalGoodsPrice().divide(goodsSellDto.getTotalGoodsPrice(), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal ratioAmount = sellDto.getTotalGoodsPrice().divide(divide, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
if(addTotalPrice.doubleValue() > 0l){
|
|
|
//如果是最后一件商品
|
|
|
- if(i == goodsId.size() - 1){
|
|
|
+ if(i == sellOrders.size() - 1){
|
|
|
sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(usableParentGoodsAddTotalPrice));
|
|
|
}else {
|
|
|
//获取分配的附加
|
|
@@ -825,9 +841,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(multiply));
|
|
|
usableParentGoodsAddTotalPrice = usableParentGoodsAddTotalPrice.subtract(multiply);
|
|
|
}
|
|
|
+ sellDto.setGoodsPrice(sellDto.getTotalGoodsPrice());
|
|
|
}else if(cutTotalPrice.doubleValue() > 0l){
|
|
|
//如果是最后一件商品
|
|
|
- if(i == goodsId.size() - 1){
|
|
|
+ if(i == sellOrders.size() - 1){
|
|
|
sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(usableParentGoodsCutTotalPrice));
|
|
|
}else {
|
|
|
//获取分配的组合减免金额
|
|
@@ -835,12 +852,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(multiply));
|
|
|
usableParentGoodsCutTotalPrice = usableParentGoodsCutTotalPrice.subtract(multiply);
|
|
|
}
|
|
|
+ sellDto.setGoodsPrice(sellDto.getTotalGoodsPrice());
|
|
|
}else {
|
|
|
- continue noAmount;
|
|
|
+ continue noFreeAmount;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
for (int i = 0; i < sellOrderList.size(); i++) {
|
|
|
SellOrder sellOrder = sellOrderList.get(i);
|
|
|
Integer e = null;
|
|
@@ -850,17 +867,27 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
e = sellOrder.getGoodsId();
|
|
|
}
|
|
|
GoodsSellDto goodsSellDto = collect.get(e).get(0);
|
|
|
+ List<GoodsSellDto> sellDtos = goodsSellDto.getGoodsSellDtos();
|
|
|
+ if(sellDtos != null && sellDtos.size() > 0){
|
|
|
+ Map<Integer, List<GoodsSellDto>> map = sellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
+ goodsSellDto = map.get(sellOrder.getGoodsId()).get(0);
|
|
|
+ }
|
|
|
sellOrder.setOrganId(orderByOrderNo.getOrganId());
|
|
|
sellOrder.setTransNo(orderByOrderNo.getTransNo());
|
|
|
sellOrder.setOrderId(orderByOrderNo.getId());
|
|
|
sellOrder.setOrderNo(orderByOrderNo.getOrderNo());
|
|
|
+ Goods goods = goodsService.get(e);
|
|
|
+ costMap.put("sellCost", goods.getDiscountPrice());
|
|
|
+ if (goods.getAgreeCostPrice() != null) {
|
|
|
+ costMap.put("SellCost2", goods.getAgreeCostPrice());
|
|
|
+ }
|
|
|
goodsSellDto.setTotalGoodsPrice(goodsSellDto.getGoodsPrice().multiply(new BigDecimal(sellOrder.getNum())));
|
|
|
//获取比例
|
|
|
BigDecimal ratioAmount = goodsSellDto.getTotalGoodsPrice().divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
//如果有减免金额
|
|
|
if(marketAmount.doubleValue() > 0l){
|
|
|
//如果是最后一件商品
|
|
|
- if(i == goodsId.size() - 1){
|
|
|
+ if(i == sellOrderList.size() - 1){
|
|
|
goodsSellDto.setTotalGoodsPrice(goodsSellDto.getTotalGoodsPrice().subtract(usableMarketAmount));
|
|
|
}else {
|
|
|
//获取分配的减免金额
|
|
@@ -876,7 +903,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
}else {
|
|
|
//如果是最后一件商品
|
|
|
- if(i == goodsId.size() - 1){
|
|
|
+ if(i == sellOrderList.size() - 1){
|
|
|
sellOrder.setActualAmount(usableAmount);
|
|
|
sellOrder.setBalanceAmount(usableBalance);
|
|
|
}else {
|
|
@@ -892,12 +919,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
}
|
|
|
sellOrder.setExpectAmount(sellOrder.getActualAmount().add(sellOrder.getBalanceAmount()));
|
|
|
-// sellOrder.setSellCost(goods.getDiscountPrice());
|
|
|
sellOrder.setSellCost2(JSONObject.toJSONString(costMap));
|
|
|
sellOrder.setType(SellTypeEnum.valueOf(goodsSellDto.getGoodsType()));
|
|
|
- sellOrder.setGoodsId(e);
|
|
|
+ sellOrder.setGoodsId(sellOrder.getGoodsId());
|
|
|
sellOrder.setGoodsName(goodsSellDto.getGoodsName());
|
|
|
- sellOrder.setNum(goodsSellDto.getGoodsNum());
|
|
|
sellOrder.setUserId(studentGoodsSell.getUserId());
|
|
|
sellOrder.setPaymentChannel(orderByOrderNo.getPaymentChannel());
|
|
|
sellOrder.setMerNo(orderByOrderNo.getMerNos());
|