|  | @@ -45,6 +45,8 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |  	private VipGroupDefaultClassesUnitPriceDao vipGroupDefaultClassesUnitPriceDao;
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private VipGroupActivityDao vipGroupActivityDao;
 | 
	
		
			
				|  |  | +	@Autowired
 | 
	
		
			
				|  |  | +	private VipGroupCategoryDao vipGroupCategoryDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysUserFeignService sysUserFeignService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
	
		
			
				|  | @@ -53,6 +55,12 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |      private StudentPaymentOrderDao studentPaymentOrderDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private StudentVipGroupPaymentDao studentVipGroupPaymentDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +	private StudentApplyRefundsDao studentApplyRefundsDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +	private SysUserCashAccountDao sysUserCashAccountDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +	private SysUserCashAccountDetailDao sysUserCashAccountDetailDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public BaseDAO<Long, VipGroup> getDAO() {
 | 
	
	
		
			
				|  | @@ -78,7 +86,9 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |          VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupApplyBaseInfo().getVipGroupActivityId().intValue());
 | 
	
		
			
				|  |  |  		VipGroupApplyBaseInfoDto vipGroupApplyBaseInfoDto=vipGroup.getVipGroupApplyBaseInfo();
 | 
	
		
			
				|  |  |  		vipGroupDao.insert(vipGroupApplyBaseInfoDto);
 | 
	
		
			
				|  |  | +		VipGroupCategory vipGroupCategory = vipGroupCategoryDao.get(vipGroup.getVipGroupApplyBaseInfo().getVipGroupCategoryId().intValue());
 | 
	
		
			
				|  |  |  		ClassGroup classGroup=new ClassGroup();
 | 
	
		
			
				|  |  | +		classGroup.setExpectStudentNum(vipGroupCategory.getStudentNum());
 | 
	
		
			
				|  |  |  		classGroup.setName(vipGroupApplyBaseInfoDto.getName());
 | 
	
		
			
				|  |  |  		classGroup.setExpectStudentNum(vipGroupApplyBaseInfoDto.getExpectStudentNum());
 | 
	
		
			
				|  |  |  		classGroup.setType(ClassGroupTypeEnum.VIP);
 | 
	
	
		
			
				|  | @@ -207,14 +217,13 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |              throw new BizException("该课程已结束报名!");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupActivityId().intValue());
 | 
	
		
			
				|  |  |          StudentPaymentOrder studentPaymentOrder=new StudentPaymentOrder();
 | 
	
		
			
				|  |  |          studentPaymentOrder.setUserId(user.getId());
 | 
	
		
			
				|  |  |          String orderNo=StringUtils.join(new String[]{user.getId().toString(),String.valueOf(System.currentTimeMillis())});
 | 
	
		
			
				|  |  |          studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setExpectAmount(countVipGroupPredictFee(vipGroup));
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setExpectAmount(countVipGroupPredictFee(vipGroup,vipGroup.getOnlineClassesUnitPrice(),vipGroup.getOfflineClassesUnitPrice()));
 | 
	
		
			
				|  |  |          if(vipGroupActivity.getType()==VipGroupActivityTypeEnum.DISCOUNT){
 | 
	
		
			
				|  |  |              studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount().multiply(new BigDecimal(vipGroupActivity.getAttribute1())));
 | 
	
		
			
				|  |  |          }else{
 | 
	
	
		
			
				|  | @@ -227,10 +236,21 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          StudentVipGroupPayment studentVipGroupPayment=new StudentVipGroupPayment();
 | 
	
		
			
				|  |  |          studentVipGroupPayment.setUserId(user.getId());
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setMusicGroupId(vipGroup.getId().toString());
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setClassGroupId(vipGroupClassGroupMapper.getClassGroupId());
 | 
	
		
			
				|  |  | +		studentVipGroupPayment.setVipGroupId(vipGroup.getId());
 | 
	
		
			
				|  |  | +		studentVipGroupPayment.setClassGroupId(vipGroupClassGroupMapper.getClassGroupId());
 | 
	
		
			
				|  |  |          studentVipGroupPayment.setStudentPaymentOrderId(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  |          studentVipGroupPaymentDao.insert(studentVipGroupPayment);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		ClassGroup classGroup = classGroupDao.get(vipGroupClassGroupMapper.getClassGroupId());
 | 
	
		
			
				|  |  | +		int classStudents = classGroupDao.countClassStudent(vipGroupClassGroupMapper.getClassGroupId().longValue());
 | 
	
		
			
				|  |  | +		if(classGroup.getExpectStudentNum()==classStudents){
 | 
	
		
			
				|  |  | +			vipGroup.setStatus(VipGroupStatusEnum.FINISH);
 | 
	
		
			
				|  |  | +			vipGroupDao.update(vipGroup);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		classGroup.setStudentNum(classGroup.getStudentNum()+1);
 | 
	
		
			
				|  |  | +		classGroupDao.update(classGroup);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		//生成回调地址
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -238,15 +258,72 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |       * @Date: 2019/10/2
 | 
	
		
			
				|  |  |       * 计算VIP课程预计收费
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private BigDecimal countVipGroupPredictFee(VipGroup vipGroup){
 | 
	
		
			
				|  |  | -        VipGroupDefaultClassesUnitPrice vipGroupDefaultClassesUnitPrice = vipGroupDefaultClassesUnitPriceDao.getByVipGroup(vipGroup.getId());
 | 
	
		
			
				|  |  | +    private BigDecimal countVipGroupPredictFee(VipGroup vipGroup,BigDecimal onlineClassesUnitPrice,BigDecimal offlineClassesUnitPrice){
 | 
	
		
			
				|  |  |          BigDecimal offlineClassNum=new BigDecimal(vipGroup.getOfflineClassesNum());
 | 
	
		
			
				|  |  |          BigDecimal onlineClassNum=new BigDecimal(vipGroup.getOnlineClassesNum());
 | 
	
		
			
				|  |  | -        BigDecimal onlineVipGroupCharge = vipGroupDefaultClassesUnitPrice.getOnlineClassesUnitPrice().multiply(onlineClassNum);
 | 
	
		
			
				|  |  | -        BigDecimal offlineVipGroupCharge = vipGroupDefaultClassesUnitPrice.
 | 
	
		
			
				|  |  | -                getOfflineClassesUnitPrice().
 | 
	
		
			
				|  |  | -                multiply(offlineClassNum);
 | 
	
		
			
				|  |  | +        BigDecimal onlineVipGroupCharge = onlineClassesUnitPrice.multiply(onlineClassNum);
 | 
	
		
			
				|  |  | +        BigDecimal offlineVipGroupCharge = offlineClassesUnitPrice.multiply(offlineClassNum);
 | 
	
		
			
				|  |  |          return onlineVipGroupCharge.add(offlineVipGroupCharge);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public void orderCallback(String callbackParams) {
 | 
	
		
			
				|  |  | +		/*
 | 
	
		
			
				|  |  | +		根据回调信息调整订单状态及vip课程状态等相关信息
 | 
	
		
			
				|  |  | +		 */
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public void applyRefund(Long vipGroupId,Long studentId) {
 | 
	
		
			
				|  |  | +    	if(null==studentId){
 | 
	
		
			
				|  |  | +    		studentId=sysUserFeignService.queryUserInfo().getId().longValue();
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		StudentApplyRefunds studentApplyRefunds=new StudentApplyRefunds();
 | 
	
		
			
				|  |  | +		StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.findByStudentVipGroup(vipGroupId,studentId);
 | 
	
		
			
				|  |  | +		VipGroup vipGroup=vipGroupDao.get(vipGroupId);
 | 
	
		
			
				|  |  | +		//剩余课时数
 | 
	
		
			
				|  |  | +		Map surplusClassTimes=MapUtil.convertMybatisMap(vipGroupDao.countSurplusClassTimes(vipGroupId));
 | 
	
		
			
				|  |  | +		studentApplyRefunds.setExpectAmount(countVipGroupPredictFee(vipGroup,
 | 
	
		
			
				|  |  | +				new BigDecimal(surplusClassTimes.get(TeachModeEnum.ONLINE.getMsg()).toString()),
 | 
	
		
			
				|  |  | +				new BigDecimal(surplusClassTimes.get(TeachModeEnum.OFFLINE.getMsg()).toString())));
 | 
	
		
			
				|  |  | +		studentApplyRefunds.setStatus(AuditStatusEnum.ING);
 | 
	
		
			
				|  |  | +		String orderNo=StringUtils.join(new String[]{studentId.toString(),String.valueOf(System.currentTimeMillis())});
 | 
	
		
			
				|  |  | +		studentApplyRefunds.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | +		studentApplyRefunds.setOrigPaymentOrderId(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  | +		studentApplyRefunds.setUserId(studentId.intValue());
 | 
	
		
			
				|  |  | +		studentApplyRefundsDao.insert(studentApplyRefunds);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public void applyRefundAudit(StudentApplyRefunds studentApplyRefunds) {
 | 
	
		
			
				|  |  | +		StudentApplyRefunds oldStudentApplyRefunds=studentApplyRefundsDao.get(studentApplyRefunds.getId());
 | 
	
		
			
				|  |  | +		oldStudentApplyRefunds.setStatus(studentApplyRefunds.getStatus());
 | 
	
		
			
				|  |  | +		if(null==studentApplyRefunds.getActualAmount()){
 | 
	
		
			
				|  |  | +			oldStudentApplyRefunds.setActualAmount(oldStudentApplyRefunds.getExpectAmount());
 | 
	
		
			
				|  |  | +		}else{
 | 
	
		
			
				|  |  | +			oldStudentApplyRefunds.setActualAmount(studentApplyRefunds.getActualAmount());
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		oldStudentApplyRefunds.setRemark(studentApplyRefunds.getRemark());
 | 
	
		
			
				|  |  | +		studentApplyRefundsDao.update(oldStudentApplyRefunds);
 | 
	
		
			
				|  |  | +		switch (studentApplyRefunds.getStatus()){
 | 
	
		
			
				|  |  | +			case PASS:
 | 
	
		
			
				|  |  | +				sysUserCashAccountDao.incrAccount(oldStudentApplyRefunds.getUserId(),oldStudentApplyRefunds.getActualAmount());
 | 
	
		
			
				|  |  | +				SysUserCashAccount sysUserCashAccount = sysUserCashAccountDao.get(studentApplyRefunds.getId().intValue());
 | 
	
		
			
				|  |  | +				SysUserCashAccountDetail sysUserCashAccountDetail=new SysUserCashAccountDetail();
 | 
	
		
			
				|  |  | +				sysUserCashAccountDetail.setUserId(studentApplyRefunds.getUserId());
 | 
	
		
			
				|  |  | +				sysUserCashAccountDetail.setType(PlatformCashAccountDetailTypeEnum.REFUNDS);
 | 
	
		
			
				|  |  | +				sysUserCashAccountDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +				sysUserCashAccountDetail.setAmount(oldStudentApplyRefunds.getActualAmount());
 | 
	
		
			
				|  |  | +				sysUserCashAccountDetail.setBalance(sysUserCashAccount.getBalance());
 | 
	
		
			
				|  |  | +				sysUserCashAccountDetail.setAttribute(oldStudentApplyRefunds.getId().toString());
 | 
	
		
			
				|  |  | +				sysUserCashAccountDetailDao.insert(sysUserCashAccountDetail);
 | 
	
		
			
				|  |  | +				break;
 | 
	
		
			
				|  |  | +			case REJECT:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				break;
 | 
	
		
			
				|  |  | +			default:
 | 
	
		
			
				|  |  | +				throw new BizException("审核状态错误!");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  }
 |