|  | @@ -1,6 +1,5 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.entity.SysUser;
 | 
	
	
		
			
				|  | @@ -93,7 +92,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private RedisCache<String, Object> redisCache;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private SellOrderDao sellOrderDao;
 | 
	
		
			
				|  |  | +    private SellOrderService sellOrderService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public BaseDAO<Long, StudentRegistration> getDAO() {
 | 
	
	
		
			
				|  | @@ -279,7 +278,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  | -    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, List<CourseFormDto> courseForms,BigDecimal remitFee,BigDecimal courseRemitFee) throws Exception {
 | 
	
		
			
				|  |  | +    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, List<CourseFormDto> courseForms, BigDecimal remitFee, BigDecimal courseRemitFee) throws Exception {
 | 
	
		
			
				|  |  |          Date date = new Date();
 | 
	
		
			
				|  |  |          StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  |          studentPaymentOrder.setUserId(studentRegistration.getUserId());
 | 
	
	
		
			
				|  | @@ -411,7 +410,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  | -    public StudentPaymentOrder reAddOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId, StudentPaymentOrder oldOrder, List<CourseFormDto> courseForms,BigDecimal remitFee,BigDecimal courseRemitFee) {
 | 
	
		
			
				|  |  | +    public StudentPaymentOrder reAddOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId, StudentPaymentOrder oldOrder, List<CourseFormDto> courseForms, BigDecimal remitFee, BigDecimal courseRemitFee) {
 | 
	
		
			
				|  |  |          //关闭老订单
 | 
	
		
			
				|  |  |          oldOrder.setStatus(DealStatusEnum.CLOSE);
 | 
	
		
			
				|  |  |          studentPaymentOrderService.update(oldOrder);
 | 
	
	
		
			
				|  | @@ -899,79 +898,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |              //销售订单详情
 | 
	
		
			
				|  |  |              List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.getOrderDetail(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  |              if (orderDetails.size() > 0) {
 | 
	
		
			
				|  |  | -                List<SellOrder> sellOrders = new ArrayList<>();
 | 
	
		
			
				|  |  | -                //总余额支付
 | 
	
		
			
				|  |  | -                BigDecimal totalBalance = studentPaymentOrder.getBalancePaymentAmount() != null ? studentPaymentOrder.getBalancePaymentAmount() : BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -                //总价格
 | 
	
		
			
				|  |  | -                BigDecimal totalPrice = studentPaymentOrder.getExpectAmount();
 | 
	
		
			
				|  |  | -                //商品总付款
 | 
	
		
			
				|  |  | -                BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | -                //商品销售占的余额
 | 
	
		
			
				|  |  | -                BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice,2,BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                int i = 1;
 | 
	
		
			
				|  |  | -                BigDecimal detailRouteBalance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -                for (StudentPaymentOrderDetail orderDetail : orderDetails) {
 | 
	
		
			
				|  |  | -                    BigDecimal detailBalance = orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice,2,BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -                    if(i == orderDetails.size()){
 | 
	
		
			
				|  |  | -                        detailBalance = detailTotalBalance.subtract(detailRouteBalance);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    detailRouteBalance = detailRouteBalance.add(detailBalance);
 | 
	
		
			
				|  |  | -                    i++;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    if (orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) && orderDetail.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
 | 
	
		
			
				|  |  | -                        continue;
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    BigDecimal goodsTotalPrice = orderDetail.getGoodsList().stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | -                    BigDecimal routePrice = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -                    BigDecimal routeBalance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -                    int j = 1;
 | 
	
		
			
				|  |  | -                    for (Goods goods : orderDetail.getGoodsList()) {
 | 
	
		
			
				|  |  | -                        BigDecimal expectAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -                        BigDecimal balance = goods.getGroupPurchasePrice().multiply(detailBalance).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -                        if(j==orderDetail.getGoodsList().size()){
 | 
	
		
			
				|  |  | -                            expectAmount  = orderDetail.getPrice().subtract(routePrice);
 | 
	
		
			
				|  |  | -                            balance  = orderDetail.getPrice().subtract(routeBalance);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        routePrice = routePrice.add(expectAmount);
 | 
	
		
			
				|  |  | -                        routeBalance = routeBalance.add(balance);
 | 
	
		
			
				|  |  | -                        j++;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                        SellOrder sellOrder = new SellOrder();
 | 
	
		
			
				|  |  | -                        Map<String, BigDecimal> CostMap = new HashMap<>();
 | 
	
		
			
				|  |  | -                        CostMap.put("sellCost",goods.getDiscountPrice());
 | 
	
		
			
				|  |  | -                        if(goods.getAgreeCostPrice() != null){
 | 
	
		
			
				|  |  | -                            CostMap.put("SellCost2",goods.getAgreeCostPrice());
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        sellOrder.setOrganId(studentPaymentOrder.getOrganId());
 | 
	
		
			
				|  |  | -                        sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
 | 
	
		
			
				|  |  | -                        sellOrder.setTransNo(studentPaymentOrder.getTransNo());
 | 
	
		
			
				|  |  | -                        sellOrder.setOrderId(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  | -                        sellOrder.setOrderNo(studentPaymentOrder.getOrderNo());
 | 
	
		
			
				|  |  | -                        sellOrder.setActualAmount(expectAmount.subtract(balance));
 | 
	
		
			
				|  |  | -                        sellOrder.setBalanceAmount(balance);
 | 
	
		
			
				|  |  | -                        sellOrder.setExpectAmount(expectAmount);
 | 
	
		
			
				|  |  | -                        sellOrder.setSellCost(goods.getDiscountPrice());
 | 
	
		
			
				|  |  | -                        sellOrder.setSellCost2(JSON.toJSONString(CostMap));
 | 
	
		
			
				|  |  | -                        sellOrder.setNum(1);
 | 
	
		
			
				|  |  | -                        sellOrder.setUserId(studentPaymentOrder.getUserId());
 | 
	
		
			
				|  |  | -                        sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
 | 
	
		
			
				|  |  | -                        sellOrder.setMerNo(studentPaymentOrder.getMerNos());
 | 
	
		
			
				|  |  | -                        sellOrder.setSellTime(studentPaymentOrder.getCreateTime());
 | 
	
		
			
				|  |  | -                        sellOrder.setCreateIme(new Date());
 | 
	
		
			
				|  |  | -                        sellOrder.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | -                        if (goods.getType().equals(GoodsType.INSTRUMENT)) {
 | 
	
		
			
				|  |  | -                            sellOrder.setType(SellTypeEnum.INSTRUMENT);
 | 
	
		
			
				|  |  | -                        } else if (goods.getType().equals(GoodsType.ACCESSORIES)) {
 | 
	
		
			
				|  |  | -                            sellOrder.setType(SellTypeEnum.ACCESSORIES);
 | 
	
		
			
				|  |  | -                        } else {
 | 
	
		
			
				|  |  | -                            sellOrder.setType(SellTypeEnum.OTHER);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        sellOrders.add(sellOrder);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                sellOrderDao.batchInsert(sellOrders);
 | 
	
		
			
				|  |  | +                sellOrderService.addOrderDetail2SellOrder(orderDetails, studentPaymentOrder,musicGroup);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              //三方乐团不发送缴费通知
 |