|
@@ -24,6 +24,7 @@ import com.ym.mec.im.ImFeignService;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
+
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -894,11 +895,17 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void enableBuyVipGroup(Integer vipGroupId) {
|
|
|
+ public void enableBuyVipGroup(Integer vipGroupId, Integer userId) {
|
|
|
if (Objects.isNull(vipGroupId)){
|
|
|
throw new BizException("请指定VIP课");
|
|
|
}
|
|
|
VipGroup vipGroup = get(vipGroupId.longValue());
|
|
|
+ if(Objects.nonNull(vipGroup.getStudentIdList())){
|
|
|
+ Set<Integer> userIds = Arrays.asList(vipGroup.getStudentIdList().split(",")).stream().mapToInt(Integer::parseInt).boxed().collect(Collectors.toSet());
|
|
|
+ if(!userIds.contains(userId)){
|
|
|
+ throw new BizException("您无法购买此课程");
|
|
|
+ }
|
|
|
+ }
|
|
|
List<CourseSchedule> courseSchedules = JSON.parseArray(vipGroup.getCourseSchedulesJson(),CourseSchedule.class);
|
|
|
courseScheduleService.checkNewCourseSchedules(courseSchedules,false);
|
|
|
}
|
|
@@ -982,7 +989,7 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public Map buyVipGroup(VipGroupBuyParamsDto vipGroupBuyParams) throws Exception {
|
|
|
+ public Map buyVipGroup(VipGroupBuyParamsDto vipGroupBuyParams) {
|
|
|
SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
if(user == null){
|
|
|
throw new BizException("用户信息获取失败");
|
|
@@ -1009,20 +1016,16 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- StudentPaymentOrder oldOrder = studentPaymentOrderDao.findNotFailedOrderByStudentVipGroup(vipGroupBuyParams.getVipGroupId(),
|
|
|
+ List<StudentPaymentOrder> oldOrders = studentPaymentOrderDao.findNotFailedOrderByStudentVipGroup(vipGroupBuyParams.getVipGroupId(),
|
|
|
user.getId());
|
|
|
+ Map<DealStatusEnum, Long> statusCountMap = oldOrders.stream().collect(Collectors.groupingBy(StudentPaymentOrder::getStatus, Collectors.counting()));
|
|
|
|
|
|
- if(Objects.nonNull(oldOrder)&&oldOrder.getStatus().equals(DealStatusEnum.SUCCESS)){
|
|
|
+ if(Objects.nonNull(statusCountMap.get(DealStatusEnum.SUCCESS))&&statusCountMap.get(DealStatusEnum.SUCCESS)>0){
|
|
|
if("36".equals(user.getOrganId())){
|
|
|
throw new BizException("您已预约过此课程");
|
|
|
}
|
|
|
throw new BizException("您已购买过此课程");
|
|
|
- }else if(Objects.nonNull(oldOrder)&&oldOrder.getStatus().equals(DealStatusEnum.ING)){
|
|
|
- if("36".equals(user.getOrganId())){
|
|
|
- throw new BizException("您已预约过此课程,请等待处理结果");
|
|
|
- }
|
|
|
- throw new BizException("您有处理中的订单,请等待处理结果");
|
|
|
- }else{
|
|
|
+ }else if(CollectionUtils.isEmpty(oldOrders)||Objects.isNull(statusCountMap.get(DealStatusEnum.ING))){
|
|
|
if(classGroup.getStudentNum()>=classGroup.getExpectStudentNum()){
|
|
|
throw new BizException("该课程人数已达上限");
|
|
|
}
|
|
@@ -1090,7 +1093,7 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
|
|
|
return result;
|
|
|
}else{
|
|
|
if (userCashAccount.getBalance().doubleValue() > 0) {
|
|
|
- sysUserCashAccountService.updateBalance(user.getId(), userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团续费");
|
|
|
+ sysUserCashAccountService.updateBalance(user.getId(), userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "VIP课购买");
|
|
|
amount = amount.subtract(userCashAccount.getBalance());
|
|
|
studentPaymentOrder.setActualAmount(amount);
|
|
|
studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
|
|
@@ -1166,11 +1169,17 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
|
|
|
if(!isOk){
|
|
|
updateVipGroupStudentNumAndStatus(vipGroupId,classGroup,-1,false);
|
|
|
classGroupStudentMapperDao.deleteStudentByMusicGroupId(vipGroupId.toString(),userId);
|
|
|
+ if (studentPaymentOrder.getBalancePaymentAmount().doubleValue() > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(userId, studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS,
|
|
|
+ "VIP课购买失败");
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- updateVipGroupStudentNumAndStatus(vipGroupId, classGroup,0,true);
|
|
|
+ if(classGroup.getDelFlag()==1){
|
|
|
+ updateVipGroupStudentNumAndStatus(vipGroupId, classGroup,0,true);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error("小课[{}]开课失败:{}",vipGroupId,e.getCause());
|
|
|
}
|