|  | @@ -28,6 +28,7 @@ import com.ym.mec.util.collection.MapUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.http.HttpUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.string.MessageFormatter;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
	
		
			
				|  | @@ -41,6 +42,7 @@ import org.springframework.transaction.annotation.Propagation;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.interceptor.TransactionAspectSupport;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.time.*;
 | 
	
		
			
				|  |  |  import java.time.format.DateTimeFormatter;
 | 
	
	
		
			
				|  | @@ -3010,6 +3012,24 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          classGroup.setCreateTime(now);
 | 
	
		
			
				|  |  |          classGroup.setUpdateTime(now);
 | 
	
		
			
				|  |  |          classGroupDao.insert(classGroup);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        //使用优惠券
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(),amount,true);
 | 
	
		
			
				|  |  | +        amount = studentPaymentOrder.getActualAmount();
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setUserId(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +        String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_BUY);
 | 
	
		
			
				|  |  | +        if (practiceGroupBuyParams.isRenew()) {
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_RENEW);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setVersion(0);
 | 
	
		
			
				|  |  | +        studentPaymentOrderService.insert(studentPaymentOrder);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //创建班级老师关联记录
 | 
	
		
			
				|  |  |          ClassGroupTeacherMapper classGroupTeacherMapper = new ClassGroupTeacherMapper();
 | 
	
	
		
			
				|  | @@ -3097,7 +3117,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |              courseScheduleStudentPayment.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  |              courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
 | 
	
		
			
				|  |  |              courseScheduleStudentPayment.setUserId(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | -            courseScheduleStudentPayment.setExpectPrice(studentSingleCourseCost);
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setExpectPrice(oneMonthPrice);
 | 
	
		
			
				|  |  |              courseScheduleStudentPayment.setActualPrice(studentSingleCourseCost);
 | 
	
		
			
				|  |  |              courseScheduleStudentPayment.setOriginalPrice(studentSingleCourseOriginalCost);
 | 
	
		
			
				|  |  |              courseScheduleStudentPayment.setClassGroupId(classGroup.getId());
 | 
	
	
		
			
				|  | @@ -3136,24 +3156,6 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return BaseController.failed(HttpStatus.FOUND, errMessage);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //使用优惠券
 | 
	
		
			
				|  |  | -        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(),amount,true);
 | 
	
		
			
				|  |  | -        amount = studentPaymentOrder.getActualAmount();
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setUserId(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | -        String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_BUY);
 | 
	
		
			
				|  |  | -        if (practiceGroupBuyParams.isRenew()) {
 | 
	
		
			
				|  |  | -            studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_RENEW);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setExpectAmount(amount);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount());
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setVersion(0);
 | 
	
		
			
				|  |  | -        studentPaymentOrderService.insert(studentPaymentOrder);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          BigDecimal balance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |          if (practiceGroupBuyParams.isUseBalancePayment() || studentPaymentOrder.getExpectAmount().doubleValue() == 0) {
 | 
	
	
		
			
				|  | @@ -4560,14 +4562,40 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  | -    public HttpResponseResult cancelWaitPayOrder(Integer userId, Integer groupId) {
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public HttpResponseResult cancelWaitPayOrder(Integer userId, Integer groupId) throws Exception {
 | 
	
		
			
				|  |  |          PracticeGroup practiceGroup = practiceGroupDao.get(groupId.longValue());
 | 
	
		
			
				|  |  |          if (practiceGroup.getGroupStatus().equals(GroupStatusEnum.LOCK)) {
 | 
	
		
			
				|  |  |              groupService.deleteGroupOtherInfo(groupId.toString(), GroupType.PRACTICE);
 | 
	
		
			
				|  |  |              practiceGroup.setGroupStatus(GroupStatusEnum.CANCEL);
 | 
	
		
			
				|  |  |              practiceGroup.setMemo("用户手动取消");
 | 
	
		
			
				|  |  |              practiceGroupDao.update(practiceGroup);
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +			// 判断是否存在支付中的记录
 | 
	
		
			
				|  |  | +			List<StudentPaymentOrder> list = studentPaymentOrderService.queryByCondition(GroupType.PRACTICE, groupId + "", userId, DealStatusEnum.ING,
 | 
	
		
			
				|  |  | +					OrderTypeEnum.PRACTICE_GROUP_BUY);
 | 
	
		
			
				|  |  | +			
 | 
	
		
			
				|  |  | +			if (list.size() > 0) {
 | 
	
		
			
				|  |  | +				StudentPaymentOrder applyOrder = list.get(list.size() - 1);
 | 
	
		
			
				|  |  | +				// 查询订单状态
 | 
	
		
			
				|  |  | +				PayStatus payStatus = studentPaymentOrderService.queryPayStatus(applyOrder.getPaymentChannel(), applyOrder.getOrderNo(), applyOrder.getTransNo());
 | 
	
		
			
				|  |  | +				if(payStatus == PayStatus.SUCCESSED){
 | 
	
		
			
				|  |  | +					throw new BizException("订单已支付成功,请勿重复支付");
 | 
	
		
			
				|  |  | +				}/*else if(payStatus == PayStatus.PAYING){
 | 
	
		
			
				|  |  | +					throw new BizException("订单还在交易中,请稍后重试");
 | 
	
		
			
				|  |  | +				}*/
 | 
	
		
			
				|  |  | +				//处理关闭订单
 | 
	
		
			
				|  |  | +				applyOrder.setStatus(DealStatusEnum.CLOSE);
 | 
	
		
			
				|  |  | +				applyOrder.setMemo("主动关闭订单");
 | 
	
		
			
				|  |  | +				if (applyOrder.getBalancePaymentAmount() != null && applyOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  | +					sysUserCashAccountService.updateBalance(applyOrder.getUserId(), applyOrder.getBalancePaymentAmount(),
 | 
	
		
			
				|  |  | +							PlatformCashAccountDetailTypeEnum.REFUNDS, "购买网管课支付失败");
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				studentPaymentOrderService.update(applyOrder);
 | 
	
		
			
				|  |  | +				sysCouponCodeService.quit(applyOrder.getCouponCodeId());
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +    		
 | 
	
		
			
				|  |  | +    		
 | 
	
		
			
				|  |  |          } else if (practiceGroup.getGroupStatus().equals(GroupStatusEnum.NORMAL)) {
 | 
	
		
			
				|  |  |              return BaseController.failed(HttpStatus.CREATED, "该订单已经支付成功");
 | 
	
		
			
				|  |  |          } else if (practiceGroup.getGroupStatus().equals(GroupStatusEnum.CANCEL)) {
 |