|
|
@@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@@ -3687,7 +3688,8 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
}
|
|
|
PracticeGroup practiceGroup = practiceGroupDao.get(Long.valueOf(order.getMusicGroupId()));
|
|
|
if (order.getStatus().equals(DealStatusEnum.SUCCESS)) {
|
|
|
- studentPaymentOrderService.activityGive(practiceGroup.getVipGroupActivityId(),order.getUserId(),order.getId());
|
|
|
+ Integer activityUserMapperId = studentPaymentOrderService.activityGive(practiceGroup.getVipGroupActivityId(), order.getUserId(), order.getId(), null, practiceGroup.getId());
|
|
|
+ practiceGroup.setActivityUserMapperId(activityUserMapperId);
|
|
|
courseScheduleDao.updateGroupCourseLock(order.getMusicGroupId(), GroupType.PRACTICE, 0);
|
|
|
} else {
|
|
|
if (Objects.nonNull(order.getBalancePaymentAmount()) && order.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
@@ -4736,4 +4738,139 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
courseScheduleService.checkNewCourseSchedules(courseSchedules, false,false);
|
|
|
return BaseController.succeed(applyBaseInfo.getAuditStatus().getCode());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public Object buyTeacherPracticeGroup(PracticeGroupBuyParamsDto practiceGroupBuyParams) throws Exception {
|
|
|
+ SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
+ if(user == null){
|
|
|
+ throw new BizException("用户信息获取失败");
|
|
|
+ }
|
|
|
+ ClassGroup classGroup = classGroupDao.findByMusicGroupAndType(practiceGroupBuyParams.getPracticeGroupId().toString(),ClassGroupTypeEnum.PRACTICE.getCode());
|
|
|
+
|
|
|
+ classGroup = classGroupDao.lockClassGroup(classGroup.getId());
|
|
|
+
|
|
|
+ if(Objects.isNull(classGroup)){
|
|
|
+ throw new BizException("课程信息错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ Date date=new Date();
|
|
|
+
|
|
|
+ PracticeGroup practiceGroup = practiceGroupDao.get(practiceGroupBuyParams.getPracticeGroupId());
|
|
|
+
|
|
|
+ if(classGroup.getStudentNum() > 0){
|
|
|
+ int i = studentPaymentOrderDao.countGroupOrderWithoutFailed(practiceGroupBuyParams.getPracticeGroupId().toString(),GroupType.PRACTICE);
|
|
|
+ if(i <= 0){
|
|
|
+ throw new BizException("该课程已经无法通过购买加入,请联系教务老师!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ VipGroupActivity vipGroupActivity = null;
|
|
|
+ if(Objects.nonNull(practiceGroup.getVipGroupActivityId())){
|
|
|
+ vipGroupActivity = vipGroupActivityDao.get(practiceGroup.getVipGroupActivityId().intValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Objects.nonNull(vipGroupActivity) && Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes()) && vipGroupActivity.getStudentMaxUsedTimes() != -1){
|
|
|
+ int useNum = activityUserMapperDao.countActivityBuyNum(vipGroupActivity.getId(),user.getId());
|
|
|
+ if(useNum >= vipGroupActivity.getStudentMaxUsedTimes()){
|
|
|
+ throw new BizException("您已超过该活动购买次数限制", vipGroupActivity.getStudentMaxUsedTimes());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(practiceGroup.getPaymentExpireDate().before(date)){
|
|
|
+ throw new BizException("该课程已结束报名!");
|
|
|
+ }
|
|
|
+ if(practiceGroup.getStudentId() != user.getId()){
|
|
|
+ throw new BizException("您无法购买此课程");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CourseSchedule> courseSchedules = JSON.parseArray(practiceGroup.getCourseScheduleJson(),CourseSchedule.class);
|
|
|
+ courseScheduleService.checkNewCourseSchedules(courseSchedules,false,false);
|
|
|
+
|
|
|
+ StudentPaymentOrder studentPaymentOrder=sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(),practiceGroup.getTotalPrice(),true);
|
|
|
+ studentPaymentOrder.setUserId(user.getId());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.PRACTICE);
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_BUY);
|
|
|
+ studentPaymentOrder.setMusicGroupId(practiceGroup.getId().toString());
|
|
|
+ studentPaymentOrder.setClassGroupId(classGroup.getId());
|
|
|
+ studentPaymentOrder.setOrganId(practiceGroup.getOrganId());
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+ studentPaymentOrderDao.insert(studentPaymentOrder);
|
|
|
+
|
|
|
+ BigDecimal amount=studentPaymentOrder.getActualAmount();
|
|
|
+ BigDecimal balance = BigDecimal.ZERO;
|
|
|
+ if(practiceGroupBuyParams.isUseBalancePayment() || amount.doubleValue() == 0){
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(user.getId());
|
|
|
+ if(userCashAccount == null){
|
|
|
+ throw new BizException("用户账户找不到");
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
+ if(userCashAccount.getBalance().subtract(amount).doubleValue() >= 0){
|
|
|
+ studentPaymentRouteOrderService.addRouteOrder(orderNo, practiceGroup.getOrganId(), practiceGroup.getTotalPrice());
|
|
|
+ // 更新订单信息
|
|
|
+ studentPaymentOrder.setActualAmount(new BigDecimal(0));
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(amount);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrder.setOrganId(practiceGroup.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(practiceGroup.getOrganId());
|
|
|
+
|
|
|
+ this.orderCallback(studentPaymentOrder);
|
|
|
+
|
|
|
+ sysUserCashAccountService.updateBalance(user.getId(), amount.negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"网管课购买");
|
|
|
+
|
|
|
+ Map<String,Object> result=new HashMap<>();
|
|
|
+ result.put("orderNo",studentPaymentOrder.getOrderNo());
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }else{
|
|
|
+ if (userCashAccount.getBalance().doubleValue() > 0) {
|
|
|
+ balance = userCashAccount.getBalance();
|
|
|
+ sysUserCashAccountService.updateBalance(user.getId(), balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "网管课购买");
|
|
|
+ amount = amount.subtract(userCashAccount.getBalance());
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
|
|
|
+ } else {
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!"36".equals(user.getOrganId())){
|
|
|
+ try {
|
|
|
+ contractService.register(user.getId(),user.getRealName(),user.getIdCardNo(),user.getPhone());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("[{}]小课购买协议生成错误:{}", practiceGroup.getId(), e.getCause());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
+ //分类费用 course,instrument,accessories,other
|
|
|
+ Map<String, BigDecimal> classFee = new HashMap<>();
|
|
|
+ classFee.put("course",amount);
|
|
|
+ classFee.put("instrument",BigDecimal.ZERO);
|
|
|
+ classFee.put("accessories",BigDecimal.ZERO);
|
|
|
+ classFee.put("other",BigDecimal.ZERO);
|
|
|
+ Map<String,Object> payMap = payService.getPayMap(
|
|
|
+ amount,
|
|
|
+ balance,
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl+"/api-student/studentOrder/notify",
|
|
|
+ baseApiUrl+"/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
+ "网管课购买",
|
|
|
+ practiceGroup.getName(),
|
|
|
+ practiceGroup.getOrganId(),
|
|
|
+ "practiceBuy"
|
|
|
+ );
|
|
|
+
|
|
|
+ studentPaymentOrder.setOrganId(practiceGroup.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(practiceGroup.getOrganId());
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ return payMap;
|
|
|
+ }
|
|
|
}
|