|
@@ -2391,15 +2391,24 @@ public class ExportServiceImpl implements ExportService {
|
|
|
|
|
|
//按订单详情计算
|
|
|
public void calcOrderDetail(StudentPaymentOrderExportDto basicOrder,List<StudentPaymentOrderDetail> detailList,Map<Integer, String> userFirstVipMap){
|
|
|
+ //排除金额为0的订单详情
|
|
|
+ detailList = detailList.stream().filter(detail -> detail.getPrice().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(detailList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //订单详情去除余额部分
|
|
|
+ calculateOrderDetailActualAmount(basicOrder.getExpectAmount(),basicOrder.getBalancePaymentAmount(),detailList);
|
|
|
+ Consumer<StudentPaymentOrderDetail> con;
|
|
|
if(basicOrder.getServiceAmount().compareTo(BigDecimal.ZERO) > 0){
|
|
|
//计算服务收入
|
|
|
- Consumer<StudentPaymentOrderDetail> con = (orderDetail)->this.setServiceFee(basicOrder,orderDetail,userFirstVipMap);
|
|
|
- detailList.stream().forEach(con);
|
|
|
+ con = (orderDetail)->this.setServiceFee(basicOrder,orderDetail,userFirstVipMap);
|
|
|
}else if(basicOrder.getSaleAmount().compareTo(BigDecimal.ZERO) > 0){
|
|
|
//计算销售收入
|
|
|
- Consumer<StudentPaymentOrderDetail> con = (orderDetail)->this.setSaleFee(basicOrder,orderDetail);
|
|
|
- detailList.stream().forEach(con);
|
|
|
+ con = (orderDetail)->this.setSaleFee(basicOrder,orderDetail);
|
|
|
+ }else {
|
|
|
+ return;
|
|
|
}
|
|
|
+ detailList.stream().forEach(con);
|
|
|
}
|
|
|
|
|
|
//按商品订单计算收入
|
|
@@ -2483,6 +2492,7 @@ public class ExportServiceImpl implements ExportService {
|
|
|
groupTypeConsumerMap.put(GroupType.MUSIC,(orderDto)->orderDto.setMusicGroupCourseFee(orderDto.getMusicGroupCourseFee().add(orderDto.getActualAmount())));
|
|
|
groupTypeConsumerMap.put(GroupType.PRACTICE,(orderDto)->orderDto.setPracticeCourseFee(orderDto.getPracticeCourseFee().add(orderDto.getActualAmount())));
|
|
|
groupTypeConsumerMap.put(GroupType.REPAIR,(orderDto)->orderDto.setRepairFee(orderDto.getRepairFee().add(orderDto.getActualAmount())));
|
|
|
+ groupTypeConsumerMap.put(GroupType.OUTORDER,(orderDto)->orderDto.setOtherFee(orderDto.getOtherFee().add(orderDto.getActualAmount())));
|
|
|
groupTypeConsumerMap.put(GroupType.SPORADIC, this::accept);
|
|
|
if(StringUtils.isEmpty(goodsSellReceiptMerNo)){
|
|
|
goodsSellReceiptMerNo = sysConfigDao.findConfigValue("goodsSellReceiptMerNo");
|
|
@@ -2550,11 +2560,38 @@ public class ExportServiceImpl implements ExportService {
|
|
|
orderDetailTypeServiceConsumerMap.put(OrderDetailTypeEnum.REPAIR,(orderDto, detail) -> orderDto.setRepairFee(orderDto.getRepairFee().add(detail.getPrice())));
|
|
|
}
|
|
|
|
|
|
- public void setServiceFee(StudentPaymentOrderExportDto basicOrder, StudentPaymentOrderDetail orderDetail,Map<Integer, String> userFirstVipMap){
|
|
|
+ //计算订单详情实际支付金额(按比例)
|
|
|
+ public void calculateOrderDetailActualAmount(BigDecimal expectAmount,BigDecimal balance,List<StudentPaymentOrderDetail> detailList){
|
|
|
+ if(balance.compareTo(BigDecimal.ZERO) == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //如果订单有余额,那么按比例排除掉订单详情中的余额,多的部分放在最后一条记录中
|
|
|
+ //比例 = 订单详情金额/订单总金额
|
|
|
+ //实际支付金额 = 订单详情金额 * 比例 保留两位小数,其余舍掉,如果是最后一笔订单详情,将剩余的金额直接赋值给它
|
|
|
+ BigDecimal subTotalAmount = expectAmount.subtract(balance);
|
|
|
+ BigDecimal actualAmount = subTotalAmount;
|
|
|
+ for (int i = 0; i < detailList.size(); i++) {
|
|
|
+ StudentPaymentOrderDetail detail = detailList.get(i);
|
|
|
+ BigDecimal ratio = detail.getPrice().divide(expectAmount,8,BigDecimal.ROUND_DOWN);
|
|
|
+ BigDecimal price = actualAmount.multiply(ratio).setScale(2,BigDecimal.ROUND_DOWN);
|
|
|
+ if(i == detailList.size() - 1){
|
|
|
+ detail.setPrice(subTotalAmount);
|
|
|
+ }else {
|
|
|
+ detail.setPrice(price);
|
|
|
+ }
|
|
|
+ subTotalAmount = subTotalAmount.subtract(price);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setServiceFee(StudentPaymentOrderExportDto basicOrder, StudentPaymentOrderDetail orderDetail,
|
|
|
+ Map<Integer, String> userFirstVipMap){
|
|
|
//分润订单可能多个,必须是指定账户。如果是内部库存转化部分收入为云教练收入
|
|
|
if(basicOrder.getRouteMerNo().equals(goodsSellReceiptMerNo)){
|
|
|
basicOrder.setCloudTeacherFee(basicOrder.getCloudTeacherFee().add(orderDetail.getIncome()));
|
|
|
}else {
|
|
|
+ //如果订单有余额,那么按比例排除掉订单详情中的余额,多的部分放在最后一条记录中
|
|
|
+ //比例 = 订单详情金额/订单总金额
|
|
|
+ //实际支付金额 = 订单详情金额 * 比例 保留两位小数,其余舍掉,如果是最后一笔订单详情,将剩余的金额直接赋值
|
|
|
Optional.ofNullable(orderDetailTypeServiceConsumerMap.get(orderDetail.getType())).ifPresent(consumer -> consumer.accept(basicOrder, orderDetail));
|
|
|
if (orderDetail.getType() == OrderDetailTypeEnum.VIP && basicOrder.getTypeDesc() == null) {
|
|
|
//学员没有历史VIP课程则导出为【VIP课新增】
|