|  | @@ -13,6 +13,9 @@ import java.util.Map;
 | 
	
		
			
				|  |  |  import java.util.Set;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
	
		
			
				|  | @@ -24,58 +27,7 @@ import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.entity.SysUserRole;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.ChargeTypeDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.ClassGroupDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.ClassGroupStudentMapperDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.CooperationOrganDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.CourseScheduleDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.CourseScheduleStudentPaymentDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.CourseScheduleTeacherSalaryDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.EmployeeDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupBuildLogDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupPaymentEntitiesDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupPurchaseListDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupQuitDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupStudentFeeDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupSubjectGoodsGroupDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.MusicGroupSubjectPlanDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.OrganizationDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.SchoolDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.SysConfigDao;
 | 
	
		
			
				|  |  | -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.CourseScheduleTeachersDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.MusicCardDto;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.RegisterPayDto;
 | 
	
		
			
				|  |  | -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.CourseSchedule;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.Goods;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.MusicGroup;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.MusicGroupBuildLog;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.MusicGroupQuit;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.MusicGroupStudentFee;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.MusicGroupSubjectGoodsGroup;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.Organization;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.School;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.StudentRegistration;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.Teacher;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.ClassGroupStudentStatusEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.ClassGroupTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.CourseStatusEnum;
 | 
	
	
		
			
				|  | @@ -218,6 +170,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private StudentRegistrationService studentRegistrationService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | +    private SporadicChargeInfoDao sporadicChargeInfoDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  |      private MusicGroupSubjectGoodsGroupService musicGroupSubjectGoodsGroupService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private GoodsService goodsService;
 | 
	
	
		
			
				|  | @@ -336,6 +290,91 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public Map sporadicPay(SporadicPayDto sporadicPayDto) throws Exception {
 | 
	
		
			
				|  |  | +        //获取收费项价格
 | 
	
		
			
				|  |  | +        SporadicChargeInfo chargeInfo = sporadicChargeInfoDao.get(sporadicPayDto.getSporadicId());
 | 
	
		
			
				|  |  | +        if(chargeInfo == null){
 | 
	
		
			
				|  |  | +            throw new BizException("支付项不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        BigDecimal amount = sporadicPayDto.getAmount();
 | 
	
		
			
				|  |  | +        if(!(amount.compareTo(chargeInfo.getAmount())==0)){
 | 
	
		
			
				|  |  | +            throw new BizException("订单金额异常");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Integer userId = sporadicPayDto.getUserId();
 | 
	
		
			
				|  |  | +        String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
	
		
			
				|  |  | +        String channelType = "";
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setUserId(userId);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setGroupType(GroupType.SPORADIC);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setType(OrderTypeEnum.SPORADIC);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setExpectAmount(amount);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setActualAmount(amount);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setMusicGroupId(sporadicPayDto.getSporadicId().toString());
 | 
	
		
			
				|  |  | +        studentPaymentOrderService.insert(studentPaymentOrder);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setVersion(0);
 | 
	
		
			
				|  |  | +        Date date = new Date();
 | 
	
		
			
				|  |  | +        if(sporadicPayDto.getUseBalancePayment() || amount.doubleValue() == 0){
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setPaymentChannel("BALANCE");
 | 
	
		
			
				|  |  | +            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
 | 
	
		
			
				|  |  | +            if(userCashAccount == null){
 | 
	
		
			
				|  |  | +                throw new BizException("用户账户找不到");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(userCashAccount.getBalance().subtract(amount).doubleValue() > 0){
 | 
	
		
			
				|  |  | +                // 更新订单信息
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setActualAmount(new BigDecimal(0));
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setBalancePaymentAmount(amount);
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setUpdateTime(date);
 | 
	
		
			
				|  |  | +                sysUserCashAccountService.updateBalance(userId, amount.negate(),PlatformCashAccountDetailTypeEnum.SPORADIC,chargeInfo.getTitle());
 | 
	
		
			
				|  |  | +                studentPaymentOrderService.update(studentPaymentOrder);
 | 
	
		
			
				|  |  | +                Map result = new HashMap(1);
 | 
	
		
			
				|  |  | +                result.put("orderNo",orderNo);
 | 
	
		
			
				|  |  | +                return result;
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                if (userCashAccount.getBalance().doubleValue() > 0) {
 | 
	
		
			
				|  |  | +                    sysUserCashAccountService.updateBalance(userId, userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.SPORADIC, chargeInfo.getTitle());
 | 
	
		
			
				|  |  | +                    amount = amount.subtract(userCashAccount.getBalance());
 | 
	
		
			
				|  |  | +                    studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        studentPaymentOrderService.update(studentPaymentOrder);
 | 
	
		
			
				|  |  | +        if(amount.compareTo(BigDecimal.ZERO)==0) {
 | 
	
		
			
				|  |  | +            Map<String, String> notifyMap = new HashMap<>();
 | 
	
		
			
				|  |  | +            notifyMap.put("tradeState", "1");
 | 
	
		
			
				|  |  | +            notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
 | 
	
		
			
				|  |  | +            notifyMap.put("channelType", channelType);
 | 
	
		
			
				|  |  | +            notifyMap.put("orderNo", "");
 | 
	
		
			
				|  |  | +            studentPaymentOrderService.updateOrder(notifyMap);
 | 
	
		
			
				|  |  | +            return notifyMap;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setVersion(studentPaymentOrder.getVersion()+1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 | 
	
		
			
				|  |  | +        Map payMap = payService.getPayMap(
 | 
	
		
			
				|  |  | +                amount,
 | 
	
		
			
				|  |  | +                orderNo,
 | 
	
		
			
				|  |  | +                baseApiUrl+"/api-student/studentOrder/notify",
 | 
	
		
			
				|  |  | +                baseApiUrl+"/#/paymentresult?orderNo=" + orderNo,
 | 
	
		
			
				|  |  | +                chargeInfo.getTitle(),
 | 
	
		
			
				|  |  | +                chargeInfo.getTitle(),
 | 
	
		
			
				|  |  | +                userId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setUpdateTime(date);
 | 
	
		
			
				|  |  | +        studentPaymentOrderService.update(studentPaymentOrder);
 | 
	
		
			
				|  |  | +        return payMap;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |  	public Map pay(RegisterPayDto registerPayDto) throws Exception {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          StudentRegistration studentRegistration = studentRegistrationService.get(registerPayDto.getRegisterId().longValue());
 |