|  | @@ -3,24 +3,38 @@ package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  | +import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | +import com.ym.mec.auth.api.enums.YesOrNoEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.SysConfigDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.TeacherDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.TempDirectorTrainingCampDetailDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.TempDirectorTrainingCamp;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.TempDirectorTrainingCampDetail;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.wrapper.TempDirectorTrainingCampDetailWrapper;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.SmsCodeService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.TempDirectorTrainingCampDetailService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.TempDirectorTrainingCampService;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.controller.BaseController;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.service.IdGeneratorService;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  | +import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.redisson.api.RBucket;
 | 
	
		
			
				|  |  | +import org.redisson.api.RedissonClient;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | +import org.springframework.http.HttpStatus;
 | 
	
		
			
				|  |  | +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.Objects;
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.text.MessageFormat;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service("tempDirectorTrainingCampDetailService")
 | 
	
		
			
				|  |  |  public class TempDirectorTrainingCampDetailServiceImpl extends ServiceImpl<TempDirectorTrainingCampDetailDao, TempDirectorTrainingCampDetail> implements TempDirectorTrainingCampDetailService {
 | 
	
	
		
			
				|  | @@ -31,17 +45,31 @@ public class TempDirectorTrainingCampDetailServiceImpl extends ServiceImpl<TempD
 | 
	
		
			
				|  |  |      private SmsCodeService smsCodeService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      private TempDirectorTrainingCampService tempDirectorTrainingCampService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private RedissonClient redissonClient;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private StudentPaymentOrderService studentPaymentOrderService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private IdGeneratorService idGeneratorService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private TeacherDao teacherDao;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private SysUserFeignService sysUserFeignService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private SysConfigDao sysConfigDao;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private PayService payService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private SysUserCashAccountService sysUserCashAccountService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public TempDirectorTrainingCampDetailDao getDao() {
 | 
	
		
			
				|  |  |          return this.baseMapper;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public void applyCamp(TempDirectorTrainingCampDetailWrapper.ApplyCamp applyCamp) {
 | 
	
		
			
				|  |  | -        Date now = new Date();
 | 
	
		
			
				|  |  | -        TempDirectorTrainingCamp trainingCamp = tempDirectorTrainingCampService.getById(applyCamp.getTempDirectorTrainingCampId());
 | 
	
		
			
				|  |  | +    private void checkTraining(Date now,TempDirectorTrainingCamp trainingCamp){
 | 
	
		
			
				|  |  |          if(Objects.isNull(trainingCamp)){
 | 
	
		
			
				|  |  |              throw new BizException("训练营信息不存在");
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -53,15 +81,30 @@ public class TempDirectorTrainingCampDetailServiceImpl extends ServiceImpl<TempD
 | 
	
		
			
				|  |  |              String dateToString = DateUtil.dateToString(trainingCamp.getApplyStartDate(), DateUtil.DATE_FORMAT_MIN);
 | 
	
		
			
				|  |  |              throw new BizException(dateToString + "开启报名,感谢您的关注");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public Integer applyCamp(TempDirectorTrainingCampDetailWrapper.ApplyCamp applyCamp) {
 | 
	
		
			
				|  |  | +        Date now = new Date();
 | 
	
		
			
				|  |  | +        TempDirectorTrainingCamp trainingCamp = tempDirectorTrainingCampService.getById(applyCamp.getTempDirectorTrainingCampId());
 | 
	
		
			
				|  |  | +        this.checkTraining(now,trainingCamp);
 | 
	
		
			
				|  |  |          if(!smsCodeService.verifyValidCode(applyCamp.getMobile(), applyCamp.getAuthCode())){
 | 
	
		
			
				|  |  |              throw new BizException("验证码校验失败");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        String lockKey = applyCamp.getTempDirectorTrainingCampId() + applyCamp.getMobile() + applyCamp.getCardNo();
 | 
	
		
			
				|  |  | +        String submitLockKey = MessageFormat.format("apply_director_camp_lock:{0}", lockKey);
 | 
	
		
			
				|  |  | +        // 数据重复提交校验
 | 
	
		
			
				|  |  | +        RBucket<Object> bucket = redissonClient.getBucket(submitLockKey);
 | 
	
		
			
				|  |  | +        if (!bucket.trySet(lockKey, 5L, TimeUnit.SECONDS)) {
 | 
	
		
			
				|  |  | +            throw new BizException("请勿重复提交");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          //根据身份证号获取信息
 | 
	
		
			
				|  |  |          TempDirectorTrainingCampDetail byCardNo = this.lambdaQuery().eq(TempDirectorTrainingCampDetail::getCardNo, applyCamp.getCardNo())
 | 
	
		
			
				|  |  |                  .eq(TempDirectorTrainingCampDetail::getTempDirectorTrainingCampId, applyCamp.getTempDirectorTrainingCampId())
 | 
	
		
			
				|  |  |                  .last("LIMIT 1").one();
 | 
	
		
			
				|  |  |          if(Objects.nonNull(byCardNo) && !StringUtils.equals(byCardNo.getMobile(),applyCamp.getMobile())){
 | 
	
		
			
				|  |  | +            redissonClient.getBucket(submitLockKey).delete();
 | 
	
		
			
				|  |  |              throw new BizException("该身份证已报名");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //根据手机号获取信息
 | 
	
	
		
			
				|  | @@ -69,6 +112,8 @@ public class TempDirectorTrainingCampDetailServiceImpl extends ServiceImpl<TempD
 | 
	
		
			
				|  |  |                  .eq(TempDirectorTrainingCampDetail::getTempDirectorTrainingCampId, applyCamp.getTempDirectorTrainingCampId())
 | 
	
		
			
				|  |  |                  .last("LIMIT 1").one();
 | 
	
		
			
				|  |  |          if(Objects.nonNull(byMobile) && !StringUtils.equals(byMobile.getCardNo(),applyCamp.getCardNo())){
 | 
	
		
			
				|  |  | +            // 删除缓存锁
 | 
	
		
			
				|  |  | +            redissonClient.getBucket(submitLockKey).delete();
 | 
	
		
			
				|  |  |              throw new BizException("该手机号已报名");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          TempDirectorTrainingCampDetail entity = JSONObject.parseObject(JSONObject.toJSONString(applyCamp),TempDirectorTrainingCampDetail.class);
 | 
	
	
		
			
				|  | @@ -77,7 +122,183 @@ public class TempDirectorTrainingCampDetailServiceImpl extends ServiceImpl<TempD
 | 
	
		
			
				|  |  |          }else if (Objects.nonNull(byMobile)){
 | 
	
		
			
				|  |  |              entity.setId(byMobile.getId());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        //获取老师信息
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserFeignService.queryUserByMobile(entity.getMobile());
 | 
	
		
			
				|  |  | +        if(Objects.isNull(sysUser) || sysUser.getId() == null){
 | 
	
		
			
				|  |  | +            //注册用户信息
 | 
	
		
			
				|  |  | +            sysUser = new SysUser();
 | 
	
		
			
				|  |  | +            sysUser.setUserType("TEACHER");
 | 
	
		
			
				|  |  | +            sysUser.setUsername(applyCamp.getUsername());
 | 
	
		
			
				|  |  | +            sysUser.setPhone(applyCamp.getMobile());
 | 
	
		
			
				|  |  | +            sysUser.setOrganId(43);
 | 
	
		
			
				|  |  | +            sysUser.setTenantId(1);
 | 
	
		
			
				|  |  | +            sysUser.setIdCardNo(applyCamp.getCardNo());
 | 
	
		
			
				|  |  | +            int phoneStrLen = sysUser.getPhone().length();
 | 
	
		
			
				|  |  | +            sysUser.setPassword(new BCryptPasswordEncoder().encode("gym" + sysUser.getPhone().substring(phoneStrLen - 4, phoneStrLen)));
 | 
	
		
			
				|  |  | +            teacherDao.addSysUser(sysUser);
 | 
	
		
			
				|  |  | +            //添加用户现金账户
 | 
	
		
			
				|  |  | +            sysUserCashAccountService.insert(new SysUserCashAccount(sysUser.getId(), "CNY"));
 | 
	
		
			
				|  |  | +            //注册老师信息
 | 
	
		
			
				|  |  | +            Teacher teacher = new Teacher();
 | 
	
		
			
				|  |  | +            teacher.setId(sysUser.getId());
 | 
	
		
			
				|  |  | +            teacher.setOrganId(43);
 | 
	
		
			
				|  |  | +            teacher.setTenantId(1);
 | 
	
		
			
				|  |  | +            teacher.setDelFlag(YesOrNoEnum.NO);
 | 
	
		
			
				|  |  | +            teacherDao.insert(teacher);
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  | +            if (sysUser.getUserType().contains("SCHOOL")) {
 | 
	
		
			
				|  |  | +                throw new BizException("用户已存在学校账户");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Teacher teacher = teacherDao.get(sysUser.getId());
 | 
	
		
			
				|  |  | +            if(Objects.isNull(teacher)){
 | 
	
		
			
				|  |  | +                //注册老师信息
 | 
	
		
			
				|  |  | +                teacher = new Teacher();
 | 
	
		
			
				|  |  | +                teacher.setId(sysUser.getId());
 | 
	
		
			
				|  |  | +                teacher.setOrganId(43);
 | 
	
		
			
				|  |  | +                teacher.setTenantId(1);
 | 
	
		
			
				|  |  | +                teacher.setDelFlag(YesOrNoEnum.NO);
 | 
	
		
			
				|  |  | +                teacherDao.insert(teacher);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            sysUser.setUserType(sysUser.getUserType() + ",TEACHER");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          this.saveOrUpdate(entity);
 | 
	
		
			
				|  |  | +        // 删除缓存锁
 | 
	
		
			
				|  |  | +        redissonClient.getBucket(submitLockKey).delete();
 | 
	
		
			
				|  |  | +        return entity.getId();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public HttpResponseResult pay(TempDirectorTrainingCampDetailWrapper.PayDto payDto) throws Exception {
 | 
	
		
			
				|  |  | +        Integer tempDirectorTrainingCampDetailId = payDto.getTempDirectorTrainingCampDetailId();
 | 
	
		
			
				|  |  | +        TempDirectorTrainingCampDetail campDetail = this.lambdaQuery().eq(TempDirectorTrainingCampDetail::getId, tempDirectorTrainingCampDetailId)
 | 
	
		
			
				|  |  | +                .last("LIMIT 1 FOR UPDATE").one();
 | 
	
		
			
				|  |  | +        if(Objects.isNull(campDetail)){
 | 
	
		
			
				|  |  | +            throw new BizException("报名信息不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(StringUtils.equals(campDetail.getPaymentStatus(),"PAID")){
 | 
	
		
			
				|  |  | +            throw new BizException("您已缴费请勿重复支付");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Date now = new Date();
 | 
	
		
			
				|  |  | +        TempDirectorTrainingCamp trainingCamp = tempDirectorTrainingCampService.getById(campDetail.getTempDirectorTrainingCampId());
 | 
	
		
			
				|  |  | +        this.checkTraining(now,trainingCamp);
 | 
	
		
			
				|  |  | +        List<StudentPaymentOrder> studentPaymentOrders = studentPaymentOrderService.queryByCondition(GroupType.SPORADIC,
 | 
	
		
			
				|  |  | +                tempDirectorTrainingCampDetailId.toString(),
 | 
	
		
			
				|  |  | +                campDetail.getUserId(),
 | 
	
		
			
				|  |  | +                DealStatusEnum.ING,
 | 
	
		
			
				|  |  | +                OrderTypeEnum.DIRECTOR_TRAINING_CAMP);
 | 
	
		
			
				|  |  | +        if(CollectionUtils.isNotEmpty(studentPaymentOrders)){
 | 
	
		
			
				|  |  | +            HttpResponseResult result = studentPaymentOrderService.checkRepeatPay(studentPaymentOrders.get(0), payDto.getRepeatPay());
 | 
	
		
			
				|  |  | +            if (result.getCode() != 200) {
 | 
	
		
			
				|  |  | +                return result;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Date nowDate = new Date();
 | 
	
		
			
				|  |  | +        String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
	
		
			
				|  |  | +        //获取收费项价格
 | 
	
		
			
				|  |  | +        BigDecimal money;
 | 
	
		
			
				|  |  | +        if(trainingCamp.getBirdPrice() != null && trainingCamp.getBirdPriceEndDate() != null && trainingCamp.getBirdPriceEndDate().after(now)){
 | 
	
		
			
				|  |  | +            money = trainingCamp.getBirdPrice();
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  | +            money = trainingCamp.getCurrentPrice();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(money.compareTo(payDto.getAmount()) != 0){
 | 
	
		
			
				|  |  | +            throw new BizException("活动信息变更,请重新下单");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Integer userId = campDetail.getUserId();
 | 
	
		
			
				|  |  | +        Teacher teacher = teacherDao.get(userId);
 | 
	
		
			
				|  |  | +        String channelType = "";
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setUserId(userId);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setGroupType(GroupType.SPORADIC);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setType(OrderTypeEnum.DIRECTOR_TRAINING_CAMP);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setExpectAmount(money);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setActualAmount(money);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setBalancePaymentAmount(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setMusicGroupId(payDto.getTempDirectorTrainingCampDetailId().toString());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setOrganId(teacher.getOrganId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setRoutingOrganId(teacher.getOrganId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setVersion(0);
 | 
	
		
			
				|  |  | +        studentPaymentOrderService.insert(studentPaymentOrder);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
 | 
	
		
			
				|  |  | +        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.DIRECTOR_TRAINING_CAMP);
 | 
	
		
			
				|  |  | +        studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount());
 | 
	
		
			
				|  |  | +        studentPaymentOrderDetail.setRemitFee(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +        studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  | +        studentPaymentOrderDetail.setCreateTime(nowDate);
 | 
	
		
			
				|  |  | +        studentPaymentOrderDetail.setUpdateTime(nowDate);
 | 
	
		
			
				|  |  | +        studentPaymentOrderDetailDao.insert(studentPaymentOrderDetail);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (money.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 BaseController.failed(HttpStatus.CREATED, notifyMap,"恭喜您,支付成功!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String baseApiUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Map payMap = payService.getPayMap(
 | 
	
		
			
				|  |  | +                money,
 | 
	
		
			
				|  |  | +                BigDecimal.ZERO,
 | 
	
		
			
				|  |  | +                orderNo,
 | 
	
		
			
				|  |  | +                baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
 | 
	
		
			
				|  |  | +                "乐队指导训练营报名",
 | 
	
		
			
				|  |  | +                "乐队指导训练营报名",
 | 
	
		
			
				|  |  | +                teacher.getOrganId(),
 | 
	
		
			
				|  |  | +                "directorTrainingCamp"
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setOrganId(teacher.getOrganId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setUpdateTime(nowDate);
 | 
	
		
			
				|  |  | +        studentPaymentOrderService.update(studentPaymentOrder);
 | 
	
		
			
				|  |  | +        return BaseController.succeed(payMap);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
 | 
	
		
			
				|  |  | +        int updateCount = studentPaymentOrderService.update(studentPaymentOrder);
 | 
	
		
			
				|  |  | +        if (updateCount <= 0) {
 | 
	
		
			
				|  |  | +            throw new BizException("订单更新失败");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(DealStatusEnum.SUCCESS.equals(studentPaymentOrder.getStatus())){
 | 
	
		
			
				|  |  | +            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetail(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  | +            BigDecimal additionCoursePrice = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +            if(!org.springframework.util.CollectionUtils.isEmpty(orderDetails)){
 | 
	
		
			
				|  |  | +                additionCoursePrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(additionCoursePrice.compareTo(BigDecimal.ZERO)>0){
 | 
	
		
			
				|  |  | +                sysUserCashAccountService.appendCourseBalance(studentPaymentOrder.getUserId(), additionCoursePrice, PlatformCashAccountDetailTypeEnum.RECHARGE, "2020考级报名");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        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, "支付失败-退回");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        TempDirectorTrainingCampDetail campDetail = this.getById(studentPaymentOrder.getMusicGroupId());
 | 
	
		
			
				|  |  | +        campDetail.setPaymentAmount(studentPaymentOrder.getActualAmount());
 | 
	
		
			
				|  |  | +        campDetail.setPaymentDate(studentPaymentOrder.getPayTime());
 | 
	
		
			
				|  |  | +        switch (studentPaymentOrder.getStatus()){
 | 
	
		
			
				|  |  | +            case SUCCESS:
 | 
	
		
			
				|  |  | +                campDetail.setPaymentStatus("PAID");
 | 
	
		
			
				|  |  | +                break;
 | 
	
		
			
				|  |  | +            case FAILED:
 | 
	
		
			
				|  |  | +            case CLOSE:
 | 
	
		
			
				|  |  | +                campDetail.setPaymentStatus("NO");
 | 
	
		
			
				|  |  | +                break;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return true;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 |