|  | @@ -4,6 +4,7 @@ import static com.ym.mec.biz.dal.entity.ApprovalStatus.PROCESSING;
 | 
	
		
			
				|  |  |  import static com.ym.mec.biz.dal.enums.DealStatusEnum.CLOSE;
 | 
	
		
			
				|  |  |  import static com.ym.mec.biz.dal.enums.DealStatusEnum.ING;
 | 
	
		
			
				|  |  |  import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
 | 
	
		
			
				|  |  | +import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.*;
 | 
	
		
			
				|  |  |  import static com.ym.mec.biz.dal.enums.PaymentStatusEnum.YES;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.io.IOException;
 | 
	
	
		
			
				|  | @@ -21,6 +22,8 @@ import java.util.Objects;
 | 
	
		
			
				|  |  |  import java.util.Set;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
	
		
			
				|  | @@ -74,18 +77,6 @@ import com.ym.mec.biz.dal.dao.SysConfigDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.TeacherAttendanceDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.TeacherDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.BasicUserDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.CloseMusicGroupDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.CourseScheduleTeachersDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.HighClassGroupDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.MusicCardDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.MusicGroupBasicDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.RegisterPayDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.SporadicPayDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.StudentApplyInstrumentDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.SubFeeSettingDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.SubjectRegisterDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.UpdateExpectedNumDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.ApprovalStatus;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.ChargeType;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.ClassGroup;
 | 
	
	
		
			
				|  | @@ -152,29 +143,6 @@ import com.ym.mec.biz.dal.enums.YesOrNoEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.page.MusicGroupQueryInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.page.MusicMemberQueryInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.event.source.GroupEventSource;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.ClassGroupService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.ClassGroupStudentMapperService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.CloudTeacherOrderService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.ContractService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.GoodsService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.ImGroupMemberService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.ImGroupService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.ImUserFriendService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.MusicGroupPaymentCalenderService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.MusicGroupService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.MusicGroupSubjectGoodsGroupService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.PayService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.StudentPaymentOrderService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.StudentRegistrationService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.StudentService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.SysConfigService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.SysMessageService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.SysUserCashAccountDetailService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.SysUserCashAccountService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.ImGroupMember;
 | 
	
	
		
			
				|  | @@ -352,6 +320,9 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private StudentService studentService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysCouponCodeService sysCouponCodeService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private SimpleDateFormat sdf_ymd = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private SimpleDateFormat sdf_hms = new SimpleDateFormat("HH:mm:ss");
 | 
	
	
		
			
				|  | @@ -2360,7 +2331,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |      				for (StudentPaymentOrderDetail detail : orderDetailList) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      					// 退乐器费用
 | 
	
		
			
				|  |  | -    					if (returnFeeDto.getIsReturnMusicalFee() && detail.getType() == OrderDetailTypeEnum.MUSICAL) {
 | 
	
		
			
				|  |  | +    					if (returnFeeDto.getIsReturnMusicalFee() && detail.getType() == MUSICAL) {
 | 
	
		
			
				|  |  |      						amount = amount.add(detail.getPrice()).subtract(detail.getRemitFee());
 | 
	
		
			
				|  |  |      						
 | 
	
		
			
				|  |  |      						StudentInstrument studentMaintenance = studentInstrumentDao.getStudentMaintenance(userId, musicGroupId);
 | 
	
	
		
			
				|  | @@ -2372,7 +2343,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      					// 退教辅费用
 | 
	
		
			
				|  |  |      					if (returnFeeDto.getIsReturnAccessoriesFee()
 | 
	
		
			
				|  |  | -    							&& (detail.getType() == OrderDetailTypeEnum.ACCESSORIES || detail.getType() == OrderDetailTypeEnum.TEACHING)) {
 | 
	
		
			
				|  |  | +    							&& (detail.getType() == ACCESSORIES || detail.getType() == TEACHING)) {
 | 
	
		
			
				|  |  |      						amount = amount.add(detail.getPrice()).subtract(detail.getRemitFee());
 | 
	
		
			
				|  |  |      					}
 | 
	
		
			
				|  |  |      				}
 | 
	
	
		
			
				|  | @@ -2682,7 +2653,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |  				for (StudentPaymentOrderDetail detail : orderDetailList) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  					// 退乐器费用
 | 
	
		
			
				|  |  | -					if (isRefundInstrumentFee && detail.getType() == OrderDetailTypeEnum.MUSICAL) {
 | 
	
		
			
				|  |  | +					if (isRefundInstrumentFee && detail.getType() == MUSICAL) {
 | 
	
		
			
				|  |  |  						amount = amount.add(detail.getPrice()).subtract(detail.getRemitFee());
 | 
	
		
			
				|  |  |  						
 | 
	
		
			
				|  |  |  						StudentInstrument studentMaintenance = studentInstrumentDao.getStudentMaintenance(userId, musicGroupId);
 | 
	
	
		
			
				|  | @@ -2694,7 +2665,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  					// 退教辅费用
 | 
	
		
			
				|  |  |  					if (isRefundTeachingAssistantsFee
 | 
	
		
			
				|  |  | -							&& (detail.getType() == OrderDetailTypeEnum.ACCESSORIES || detail.getType() == OrderDetailTypeEnum.TEACHING)) {
 | 
	
		
			
				|  |  | +							&& (detail.getType() == ACCESSORIES || detail.getType() == TEACHING)) {
 | 
	
		
			
				|  |  |  						amount = amount.add(detail.getPrice()).subtract(detail.getRemitFee());
 | 
	
		
			
				|  |  |  					}
 | 
	
		
			
				|  |  |  				}
 | 
	
	
		
			
				|  | @@ -2730,7 +2701,9 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public Map renew(Long calenderId, Integer userId, boolean isUseBalancePayment) throws Exception {
 | 
	
		
			
				|  |  | +    public Map renew(RenewParamDto renewParamDto) throws Exception {
 | 
	
		
			
				|  |  | +        Long calenderId = renewParamDto.getCalenderId();
 | 
	
		
			
				|  |  | +        Integer userId = renewParamDto.getUserId();
 | 
	
		
			
				|  |  |          MusicGroupPaymentCalender calender = musicGroupPaymentCalenderDao.get(calenderId);
 | 
	
		
			
				|  |  |          if (calender == null) {
 | 
	
		
			
				|  |  |              throw new BizException("缴费项目不存在");
 | 
	
	
		
			
				|  | @@ -2755,12 +2728,12 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |                  		throw new BizException("订单还在交易中,请稍后重试");
 | 
	
		
			
				|  |  |                  	}
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                
 | 
	
		
			
				|  |  |                  oldStudentPaymentOrder.setStatus(CLOSE);
 | 
	
		
			
				|  |  |                  studentPaymentOrderService.update(oldStudentPaymentOrder);
 | 
	
		
			
				|  |  |                  if (oldStudentPaymentOrder.getBalancePaymentAmount() != null && oldStudentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  |                      sysUserCashAccountService.updateBalance(oldStudentPaymentOrder.getUserId(), oldStudentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                sysCouponCodeService.quit(oldStudentPaymentOrder.getCouponCodeId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
	
	
		
			
				|  | @@ -2768,7 +2741,9 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |          BigDecimal amount = calenderDetail.getExpectAmount().add(calenderDetail.getExpectMemberAmount());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Date date = new Date();
 | 
	
		
			
				|  |  | -        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  | +        //使用优惠券
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(renewParamDto.getCouponIdList(),amount);
 | 
	
		
			
				|  |  | +        amount = studentPaymentOrder.getActualAmount();
 | 
	
		
			
				|  |  |          studentPaymentOrder.setGroupType(GroupType.MUSIC);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setUserId(userId);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setOrderNo(orderNo);
 | 
	
	
		
			
				|  | @@ -2778,8 +2753,6 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |  		} else {
 | 
	
		
			
				|  |  |  			studentPaymentOrder.setType(OrderTypeEnum.RENEW);
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setExpectAmount(amount);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setActualAmount(amount);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setMusicGroupId(calender.getMusicGroupId());
 | 
	
		
			
				|  |  |          studentPaymentOrder.setBatchNo(calender.getId() + "");
 | 
	
	
		
			
				|  | @@ -2814,19 +2787,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |      		cloudTeacherOrderService.insert(cloudTeacherOrder);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        /*ArrayList<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
 | 
	
		
			
				|  |  | -        StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
 | 
	
		
			
				|  |  | -        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.COURSE);
 | 
	
		
			
				|  |  | -        studentPaymentOrderDetail.setPrice(amount);
 | 
	
		
			
				|  |  | -        studentPaymentOrderDetail.setCreateTime(date);
 | 
	
		
			
				|  |  | -        studentPaymentOrderDetail.setUpdateTime(date);
 | 
	
		
			
				|  |  | -        studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  | -        studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);*/
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          BigDecimal balance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -        if (isUseBalancePayment || amount.doubleValue() == 0) {
 | 
	
		
			
				|  |  | +        if (renewParamDto.getUseBalancePayment() || amount.doubleValue() == 0) {
 | 
	
		
			
				|  |  |              SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
 | 
	
		
			
				|  |  |              if (userCashAccount == null) {
 | 
	
		
			
				|  |  |                  throw new BizException("用户账户找不到");
 | 
	
	
		
			
				|  | @@ -3047,7 +3009,17 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              if (paymentOrderDetails.size() > 0) {
 | 
	
		
			
				|  |  | -                studentPaymentOrderDetailService.batchAdd(paymentOrderDetails);
 | 
	
		
			
				|  |  | +                studentPaymentOrderDetailService.batchAdd(paymentOrderDetails,studentPaymentOrder.getCouponRemitFee());
 | 
	
		
			
				|  |  | +                //获取实际支付课程费用
 | 
	
		
			
				|  |  | +                courseFee = paymentOrderDetails.stream().filter(e->e.getType() != MUSICAL && e.getType() != ACCESSORIES
 | 
	
		
			
				|  |  | +                        && e.getType() != TEACHING && e.getType() != OTHER && e.getType() != DEGREE_REGISTRATION
 | 
	
		
			
				|  |  | +                        && e.getType() != MAINTENANCE && e.getType() != CLOUD_TEACHER && e.getType() != CLOUD_TEACHER_PLUS).map(t -> t.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | +                //获取云教练订单费用
 | 
	
		
			
				|  |  | +                if(cloudTeacherOrder != null){
 | 
	
		
			
				|  |  | +                    BigDecimal cloudTeacherFee = paymentOrderDetails.stream().filter(e->e.getType() == CLOUD_TEACHER).map(t -> t.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | +                    cloudTeacherOrder.setAmount(cloudTeacherFee);
 | 
	
		
			
				|  |  | +                    cloudTeacherOrderService.update(cloudTeacherOrder);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              //缴费
 |