yonge 3 年之前
父节点
当前提交
357e09f748

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/PracticeGroupService.java

@@ -294,7 +294,7 @@ public interface PracticeGroupService extends BaseService<Long, PracticeGroup> {
 	 * @param groupId:
 	 * @return void
 	 */
-	HttpResponseResult cancelWaitPayOrder(Integer userId, Integer groupId);
+	HttpResponseResult cancelWaitPayOrder(Integer userId, Integer groupId) throws Exception;
 
 	/**
 	 * @describe 推送练习报告

+ 49 - 21
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PracticeGroupServiceImpl.java

@@ -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)) {

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponCodeServiceImpl.java

@@ -164,6 +164,7 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
 	@Transactional(rollbackFor = Exception.class)
     public StudentPaymentOrder use(List<Integer> couponIdList, BigDecimal amount,Boolean useFlag) {
 		StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
+		studentPaymentOrder.setExpectAmount(amount);
 		if(couponIdList != null && couponIdList.size() > 0){
 			Date date = new Date();
 			List<SysCouponCodeDto> couponCodeDtoList = sysCouponCodeDao.findByIdList(couponIdList);
@@ -209,7 +210,6 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
 			studentPaymentOrder.setCouponCodeId(StringUtils.join(couponIdList,","));
 			studentPaymentOrder.setCouponRemitFee(faceAmount);
 		}
-		studentPaymentOrder.setExpectAmount(amount);
 		studentPaymentOrder.setActualAmount(amount);
 		return studentPaymentOrder;
     }

+ 3 - 1
mec-student/src/main/java/com/ym/mec/student/controller/PracticeGroupController.java

@@ -23,8 +23,10 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
 import com.yonge.log.model.AuditLogAnnotation;
+
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.util.CollectionUtils;
@@ -423,7 +425,7 @@ public class PracticeGroupController extends BaseController {
     @ApiOperation("取消待支付的订单")
     @PostMapping(value = "/cancelWaitPayOrder")
     @AuditLogAnnotation(operateName = "取消待支付的订单")
-    public HttpResponseResult cancelWaitPayOrder(Integer groupId){
+    public HttpResponseResult cancelWaitPayOrder(Integer groupId) throws Exception{
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if (sysUser == null) {
             return failed(HttpStatus.FORBIDDEN, "请登录");