|
@@ -50,6 +50,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
@Autowired
|
|
|
+ private SysPaymentConfigService sysPaymentConfigService;
|
|
|
+ @Autowired
|
|
|
private MusicGroupDao musicGroupDao;
|
|
|
@Autowired
|
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
@@ -134,6 +136,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
if (studentId == null) {
|
|
|
throw new BizException("请指定学员");
|
|
|
}
|
|
|
+
|
|
|
+ goodsSellDtos.forEach(e->{
|
|
|
+ if(StringUtils.isNotEmpty(e.getComplementGoodsIdList())){
|
|
|
+ e.setGoodsSellDtos(goodsService.queryGoodsSellDtos(e.getComplementGoodsIdList()));
|
|
|
+ }
|
|
|
+ });
|
|
|
studentDao.lockUser(studentId);
|
|
|
SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
|
//如果教务老师为空,代表学员自己创建的订单
|
|
@@ -738,6 +746,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(orderNo);
|
|
|
String goodsJson = studentGoodsSell.getGoodsJson();
|
|
|
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());
|
|
|
|
|
@@ -747,34 +756,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
goodsIds.add(e.getGoodsId());
|
|
|
}
|
|
|
});
|
|
|
- List<GoodsSellDto> goodsSellDtoList = new ArrayList<>();
|
|
|
- //扣减库存
|
|
|
- List<GoodsProcurement> goodsBatchNoDtos = goodsService.subtractStock(goodsIds, AccountType.EXTERNAL);
|
|
|
-
|
|
|
- Map<String, List<GoodsProcurement>> listMap = goodsBatchNoDtos.stream().collect(Collectors.groupingBy(GoodsProcurement::getBatchNo));
|
|
|
- Set<String> listMapKeys = listMap.keySet();
|
|
|
- listMapKeys.forEach(e->{
|
|
|
- listMap.get(e).forEach(z->{
|
|
|
- GoodsSellDto goodsSellDto1 = collect.get(z.getGoodsId()).get(0);
|
|
|
- GoodsSellDto goodsSellDto = new GoodsSellDto();
|
|
|
- if(StringUtils.isEmpty(z.getBatchNo())){
|
|
|
- goodsSellDto.setGoodsNum(1);
|
|
|
- goodsSellDto.setTotalGoodsPrice(goodsSellDto1.getGoodsPrice());
|
|
|
- goodsSellDto.setGoodsPrice(goodsSellDto1.getGoodsPrice());
|
|
|
- goodsSellDto.setGoodsId(goodsSellDto1.getGoodsId());
|
|
|
- goodsSellDto.setGoodsName(goodsSellDto1.getGoodsName());
|
|
|
- goodsSellDto.setGoodsType(goodsSellDto1.getGoodsType());
|
|
|
- goodsSellDto.setImage(goodsSellDto1.getImage());
|
|
|
- }else {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- List<Goods> goodsByIds = goodsService.findGoodsByIds(StringUtils.join(goodsId, ","));
|
|
|
- Map<Integer, List<Goods>> goodsMap = goodsByIds.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
+ AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(orderByOrderNo.getPaymentChannel()), orderByOrderNo.getMerNos());
|
|
|
+ //实际扣减的库存商品
|
|
|
+ List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
|
|
|
Map<String, BigDecimal> costMap = new HashMap<>(2);
|
|
|
- List<SellOrder> sellOrders = new ArrayList<>();
|
|
|
BigDecimal balancePaymentAmount = orderByOrderNo.getBalancePaymentAmount();
|
|
|
//可用余额
|
|
|
BigDecimal usableBalance = balancePaymentAmount;
|
|
@@ -783,6 +768,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
BigDecimal usableMarketAmount = marketAmount;
|
|
|
//包含减免余额的总金额
|
|
|
BigDecimal totalAmount = goodsSellDtos.stream().map(e -> e.getTotalGoodsPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //组合商品减免金额
|
|
|
+ Map<Integer,BigDecimal> parentGoodsCutTotalPriceMap = new HashMap<>();
|
|
|
+ //组合商品附加金额
|
|
|
+ Map<Integer,BigDecimal> parentGoodsAddTotalPriceMap = new HashMap<>();
|
|
|
//应付总额
|
|
|
BigDecimal totalActual = totalAmount.subtract(marketAmount);
|
|
|
//可用应付
|
|
@@ -791,23 +780,83 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
BigDecimal realityAmount = totalActual.subtract(usableBalance);
|
|
|
//可用实付总额
|
|
|
BigDecimal usableAmount = realityAmount;
|
|
|
- for (int i = 0; i < goodsId.size(); i++) {
|
|
|
- Integer e = goodsId.get(i);
|
|
|
- GoodsSellDto goodsSellDto = collect.get(e).get(0);
|
|
|
- Goods goods = goodsMap.get(e).get(0);
|
|
|
+ //可用组合商品总减免金额
|
|
|
+ BigDecimal usableParentGoodsCutTotalPrice;
|
|
|
+ //可用组合商品总附加金额
|
|
|
+ BigDecimal usableParentGoodsAddTotalPrice;
|
|
|
+
|
|
|
+ //获取组合商品列表
|
|
|
+ List<SellOrder> orderList = sellOrderList.stream().filter(sellOrder -> sellOrder.getParentGoodsId() != null).collect(Collectors.toList());
|
|
|
+ for (SellOrder sellOrder : orderList) {
|
|
|
+ //获取组合商品销售总价
|
|
|
+ GoodsSellDto goodsSellDto = collect.get(sellOrder.getParentGoodsId()).get(0);
|
|
|
+ BigDecimal parentTotalGoodsPrice = goodsSellDto.getTotalGoodsPrice();
|
|
|
+ BigDecimal totalGoodsPrice = BigDecimal.ZERO;
|
|
|
+ //获取单个商品销售总价
|
|
|
+ for (GoodsSellDto sellDto : goodsSellDto.getGoodsSellDtos()) {
|
|
|
+ totalGoodsPrice = totalGoodsPrice.add(sellDto.getTotalGoodsPrice());
|
|
|
+ }
|
|
|
+ //如果组合价大于预计总价
|
|
|
+ if (parentTotalGoodsPrice.compareTo(totalGoodsPrice) == 1){
|
|
|
+ parentGoodsAddTotalPriceMap.put(sellOrder.getParentGoodsId(),parentTotalGoodsPrice.subtract(totalGoodsPrice));
|
|
|
+ }else if(parentTotalGoodsPrice.compareTo(totalGoodsPrice) == -1){//小于
|
|
|
+ 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());
|
|
|
+ usableParentGoodsAddTotalPrice = addTotalPrice;
|
|
|
+ BigDecimal cutTotalPrice = parentGoodsCutTotalPriceMap.get(sellOrder.getParentGoodsId());
|
|
|
+ usableParentGoodsCutTotalPrice = cutTotalPrice;
|
|
|
+ for (int i = 0; i < goodsSellDtoList.size(); i++) {
|
|
|
+ GoodsSellDto sellDto = goodsSellDtoList.get(i);
|
|
|
+ //获取比例
|
|
|
+ BigDecimal ratioAmount = sellDto.getTotalGoodsPrice().divide(goodsSellDto.getTotalGoodsPrice(), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ if(addTotalPrice.doubleValue() > 0l){
|
|
|
+ //如果是最后一件商品
|
|
|
+ if(i == goodsId.size() - 1){
|
|
|
+ sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(usableParentGoodsAddTotalPrice));
|
|
|
+ }else {
|
|
|
+ //获取分配的附加
|
|
|
+ BigDecimal multiply = ratioAmount.multiply(addTotalPrice).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(multiply));
|
|
|
+ usableParentGoodsAddTotalPrice = usableParentGoodsAddTotalPrice.subtract(multiply);
|
|
|
+ }
|
|
|
+ }else if(cutTotalPrice.doubleValue() > 0l){
|
|
|
+ //如果是最后一件商品
|
|
|
+ if(i == goodsId.size() - 1){
|
|
|
+ sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(usableParentGoodsCutTotalPrice));
|
|
|
+ }else {
|
|
|
+ //获取分配的组合减免金额
|
|
|
+ BigDecimal multiply = ratioAmount.multiply(cutTotalPrice).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(multiply));
|
|
|
+ usableParentGoodsCutTotalPrice = usableParentGoodsCutTotalPrice.subtract(multiply);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ continue noAmount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- costMap.put("sellCost", goods.getDiscountPrice());
|
|
|
- if (goods.getAgreeCostPrice() != null) {
|
|
|
- costMap.put("SellCost2", goods.getAgreeCostPrice());
|
|
|
+ for (int i = 0; i < sellOrderList.size(); i++) {
|
|
|
+ SellOrder sellOrder = sellOrderList.get(i);
|
|
|
+ Integer e = null;
|
|
|
+ if(sellOrder.getParentGoodsId() != null){
|
|
|
+ e = sellOrder.getParentGoodsId();
|
|
|
+ }else {
|
|
|
+ e = sellOrder.getGoodsId();
|
|
|
}
|
|
|
- SellOrder sellOrder = new SellOrder();
|
|
|
+ GoodsSellDto goodsSellDto = collect.get(e).get(0);
|
|
|
sellOrder.setOrganId(orderByOrderNo.getOrganId());
|
|
|
sellOrder.setTransNo(orderByOrderNo.getTransNo());
|
|
|
sellOrder.setOrderId(orderByOrderNo.getId());
|
|
|
sellOrder.setOrderNo(orderByOrderNo.getOrderNo());
|
|
|
+ goodsSellDto.setTotalGoodsPrice(goodsSellDto.getGoodsPrice().multiply(new BigDecimal(sellOrder.getNum())));
|
|
|
//获取比例
|
|
|
BigDecimal ratioAmount = goodsSellDto.getTotalGoodsPrice().divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
-
|
|
|
//如果有减免金额
|
|
|
if(marketAmount.doubleValue() > 0l){
|
|
|
//如果是最后一件商品
|
|
@@ -815,7 +864,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
goodsSellDto.setTotalGoodsPrice(goodsSellDto.getTotalGoodsPrice().subtract(usableMarketAmount));
|
|
|
}else {
|
|
|
//获取分配的减免金额
|
|
|
- BigDecimal multiply = ratioAmount.multiply(usableMarketAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal multiply = ratioAmount.multiply(marketAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
goodsSellDto.setTotalGoodsPrice(goodsSellDto.getTotalGoodsPrice().subtract(multiply));
|
|
|
usableMarketAmount = usableMarketAmount.subtract(multiply);
|
|
|
}
|
|
@@ -843,11 +892,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
}
|
|
|
sellOrder.setExpectAmount(sellOrder.getActualAmount().add(sellOrder.getBalanceAmount()));
|
|
|
- sellOrder.setSellCost(goods.getDiscountPrice());
|
|
|
+// sellOrder.setSellCost(goods.getDiscountPrice());
|
|
|
sellOrder.setSellCost2(JSONObject.toJSONString(costMap));
|
|
|
- sellOrder.setType(SellTypeEnum.valueOf(goods.getType().getCode()));
|
|
|
+ sellOrder.setType(SellTypeEnum.valueOf(goodsSellDto.getGoodsType()));
|
|
|
sellOrder.setGoodsId(e);
|
|
|
- sellOrder.setGoodsName(goods.getName());
|
|
|
+ sellOrder.setGoodsName(goodsSellDto.getGoodsName());
|
|
|
sellOrder.setNum(goodsSellDto.getGoodsNum());
|
|
|
sellOrder.setUserId(studentGoodsSell.getUserId());
|
|
|
sellOrder.setPaymentChannel(orderByOrderNo.getPaymentChannel());
|
|
@@ -855,10 +904,9 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
sellOrder.setSellTime(orderByOrderNo.getPayTime());
|
|
|
sellOrder.setEduTeacherId(studentGoodsSell.getTeacherId());
|
|
|
sellOrder.setCooperationOrganId(studentGoodsSell.getCooperationOrganId());
|
|
|
- sellOrders.add(sellOrder);
|
|
|
}
|
|
|
- if(sellOrders.size() > 0){
|
|
|
- sellOrderService.batchInsert(sellOrders);
|
|
|
+ if(sellOrderList.size() > 0){
|
|
|
+ sellOrderService.batchInsert(sellOrderList);
|
|
|
}
|
|
|
}
|
|
|
|