|  | @@ -13,7 +13,9 @@ import com.ym.mec.biz.service.SysUserCashAccountService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.constant.CommonConstants;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.controller.BaseController;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  | +import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.http.HttpStatus;
 | 
	
	
		
			
				|  | @@ -31,6 +33,7 @@ import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.IdGeneratorService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.collection.MapUtil;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
	
		
			
				|  | @@ -273,10 +276,11 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
 | 
	
		
			
				|  |  |          if(amount.compareTo(degreeRegistration.getPrice())!=0){
 | 
	
		
			
				|  |  |              throw new BizException("商品价格不符");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        Integer userId = degreeRegistration.getUserId();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          OrderTypeEnum type = OrderTypeEnum.DEGREE_REGISTRATION;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Integer userId = degreeRegistration.getUserId();
 | 
	
		
			
				|  |  |          String channelType = "";
 | 
	
		
			
				|  |  |          StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  |          studentPaymentOrder.setUserId(userId);
 | 
	
	
		
			
				|  | @@ -284,7 +288,30 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
 | 
	
		
			
				|  |  |          studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setType(type);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setExpectAmount(amount);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setActualAmount(amount);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        if(degreeRegistration.isUseBalance()){
 | 
	
		
			
				|  |  | +        	SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
 | 
	
		
			
				|  |  | +            if (userCashAccount == null) {
 | 
	
		
			
				|  |  | +                throw new BizException("用户账户找不到");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            BigDecimal deductBalance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +            if (userCashAccount.getBalance().subtract(amount).doubleValue() >= 0) {
 | 
	
		
			
				|  |  | +                // 更新订单信息
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setActualAmount(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setBalancePaymentAmount(amount);
 | 
	
		
			
				|  |  | +                deductBalance = amount;
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setPaymentChannel("BALANCE");
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setActualAmount(amount.subtract(userCashAccount.getBalance()));
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
 | 
	
		
			
				|  |  | +                deductBalance = userCashAccount.getBalance();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            amount = amount.subtract(deductBalance);
 | 
	
		
			
				|  |  | +            sysUserCashAccountService.updateBalance(userId, deductBalance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "考级报名");
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setActualAmount(amount);
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setBalancePaymentAmount(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setClassGroupId(degreeRegistration.getId());
 | 
	
		
			
				|  |  |          if(Objects.nonNull(degreeRegistration.getSporadicId())){
 | 
	
	
		
			
				|  | @@ -565,6 +592,12 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
 | 
	
		
			
				|  |  | +            if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  | +                sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "支付失败-退回");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          if(Objects.isNull(studentPaymentOrder.getClassGroupId())){
 | 
	
		
			
				|  |  |              return true;
 | 
	
		
			
				|  |  |          }
 |