Bläddra i källkod

fix:乐理考级报名

Joburgess 4 år sedan
förälder
incheckning
e110e3c51c

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/DegreeRegistrationService.java

@@ -22,6 +22,8 @@ public interface DegreeRegistrationService extends BaseService<Integer, DegreeRe
 
     HttpResponseResult pay(DegreeRegistrationActivityDto degreeRegistration) throws Exception;
 
+    HttpResponseResult theoryPay(DegreeRegistrationActivityDto degreeRegistration) throws Exception;
+
     Boolean updateStatus(StudentPaymentOrder order);
 
     PageInfoDegree<DegreeRegistration> getPageList(DegreeQueryInfo queryInfo);

+ 196 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/DegreeRegistrationServiceImpl.java

@@ -341,6 +341,202 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
         return BaseController.succeed(payMap);
     }
 
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+    public HttpResponseResult theoryPay(DegreeRegistrationActivityDto degreeRegistration) throws Exception {
+        Student student = studentDao.getLocked(degreeRegistration.getUserId());
+
+        List<DegreeRegistration> userLevelDegrees = degreeRegistrationDao.getUserLevelDegrees(degreeRegistration.getUserId(), ACTIVITY_TAG);
+
+        long endTheoryLevelNum = userLevelDegrees.stream().filter(d -> StringUtils.isNotBlank(d.getTheoryLevel())&&d.getStatus().equals(2)).count();
+        long ingTheoryLevelNum = userLevelDegrees.stream().filter(d -> StringUtils.isNotBlank(d.getTheoryLevel())&&d.getStatus().equals(1)).count();
+
+        if(StringUtils.isNotBlank(degreeRegistration.getTheoryLevel())&&endTheoryLevelNum>0){
+            throw new BizException("您已报考过选择的考级项目");
+        }
+
+        degreeRegistration.setActivityTag(ACTIVITY_TAG);
+
+        Date nowDate = new Date();
+
+        if(ACTIVITY_END_TIME.compareTo(nowDate)<0){
+            throw new BizException("活动已截至");
+        }
+
+        String orderNo = idGeneratorService.generatorId("payment") + "";
+
+        degreeRegistration.setMoney(BigDecimal.ZERO);
+
+        List<String> courseInfos = new ArrayList<>();
+
+        if("免考".equals(degreeRegistration.getTheoryLevel())){
+            degreeRegistration.setTheoryLevel(null);
+        }
+
+        if(StringUtils.isNotBlank(degreeRegistration.getTheoryLevel())){
+            degreeRegistration.setOrderNo(orderNo);
+            BigDecimal theoryMoney = BigDecimal.ZERO;
+            switch (degreeRegistration.getTheoryLevel()) {
+                case "一级":
+                    theoryMoney = new BigDecimal(200);
+                    break;
+                case "二级":
+                    theoryMoney = new BigDecimal(240);
+                    break;
+                case "三级":
+                    theoryMoney = new BigDecimal(280);
+                    break;
+                case "四级":
+                    theoryMoney = new BigDecimal(320);
+                    break;
+                default:
+                    throw new BizException("您选择的乐理级别不存在,请核对");
+            }
+            degreeRegistration.setTheoryMoney(theoryMoney);
+        }else{
+            degreeRegistration.setTheoryMoney(BigDecimal.ZERO);
+        }
+
+        if(Objects.nonNull(degreeRegistration.getSporadicId())||StringUtils.isNotBlank(degreeRegistration.getTheoryLevel())){
+            degreeRegistration.setStatus(1);
+            degreeRegistration.setCreateTime(nowDate);
+            degreeRegistration.setUpdateTime(nowDate);
+            degreeRegistrationDao.insert(degreeRegistration);
+
+            List<DegreeRegistration> updateDegrees = new ArrayList<>();
+            if(ingTheoryLevelNum>0){
+                for (DegreeRegistration userLevelDegree : userLevelDegrees) {
+                    if(Objects.nonNull(userLevelDegree.getSporadicId())&&Objects.nonNull(userLevelDegree.getSporadicId())){
+                        userLevelDegree.setStatus(0);
+                        updateDegrees.add(userLevelDegree);
+                    }
+                    if(Objects.nonNull(userLevelDegree.getTheoryLevel())&&StringUtils.isNotBlank(userLevelDegree.getTheoryLevel())){
+                        userLevelDegree.setStatus(0);
+                        updateDegrees.add(userLevelDegree);
+                    }
+                }
+                if(!CollectionUtils.isEmpty(updateDegrees)){
+                    degreeRegistrationDao.batchUpdate(updateDegrees);
+                }
+            }
+        }
+
+        BigDecimal additionCoursePrice = new BigDecimal("0");
+        if(Objects.nonNull(degreeRegistration.getAdditionCourseInfo())){
+            Map<CourseSchedule.CourseScheduleType, Integer> additionCourseInfo = degreeRegistration.getAdditionCourseInfo();
+            PracticeGroupSellPrice practiceGroupSellPrice = practiceGroupSellPriceDao.get(degreeRegistration.getOrganId());
+            if(Objects.isNull(practiceGroupSellPrice)){
+                throw new BizException("该分部暂未参与此活动");
+            }
+
+            BigDecimal practiceUnitPrice = practiceGroupSellPrice.getOnceOriginalPrice(),
+                    vipUnitPrice = practiceGroupSellPrice.getVipOneStudentTwelveCourseOriginalPriceWithNewUser(),
+                    highUnitPrice = practiceGroupSellPrice.getHighOnlineTenCourseOriginalPriceWithOldUser();
+
+            for (Map.Entry<CourseSchedule.CourseScheduleType, Integer> courseScheduleTypeIntegerEntry : additionCourseInfo.entrySet()) {
+                BigDecimal courseTime = new BigDecimal(courseScheduleTypeIntegerEntry.getValue());
+                switch (courseScheduleTypeIntegerEntry.getKey()){
+                    case VIP:
+                        BigDecimal vipPrice = vipUnitPrice.multiply(courseTime);
+                        additionCoursePrice = additionCoursePrice.add(vipPrice);
+                        courseInfos.add((courseTime.multiply(new BigDecimal(12)))+"节VIP-1V1课程费用:" + vipPrice);
+                        break;
+                    case PRACTICE:
+                        BigDecimal practicePrice = practiceUnitPrice.multiply(courseTime);
+                        additionCoursePrice = additionCoursePrice.add(practicePrice);
+                        courseInfos.add((courseTime.multiply(new BigDecimal(12)))+"节1V1网管课课程费用:" + practicePrice);
+                        break;
+                    case HIGH:
+                        BigDecimal highPrice = highUnitPrice.multiply(courseTime);
+                        additionCoursePrice = additionCoursePrice.add(highPrice);
+                        courseInfos.add((courseTime.multiply(new BigDecimal(10)))+"节乐理课程费用:" + highPrice);
+                        break;
+                }
+            }
+        }
+
+        BigDecimal amount = degreeRegistration.getMoney();
+        amount = amount.add(degreeRegistration.getTheoryMoney());
+        amount = amount.add(additionCoursePrice);
+
+        if(amount.compareTo(degreeRegistration.getPrice())!=0){
+            throw new BizException("商品价格不符");
+        }
+
+        OrderTypeEnum type = OrderTypeEnum.DEGREE_REGISTRATION;
+
+        Integer userId = degreeRegistration.getUserId();
+        String channelType = "";
+        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
+        studentPaymentOrder.setUserId(userId);
+        studentPaymentOrder.setGroupType(GroupType.SPORADIC);
+        studentPaymentOrder.setOrderNo(orderNo);
+        studentPaymentOrder.setType(type);
+        studentPaymentOrder.setExpectAmount(amount);
+        studentPaymentOrder.setActualAmount(amount);
+        studentPaymentOrder.setStatus(DealStatusEnum.ING);
+        studentPaymentOrder.setClassGroupId(degreeRegistration.getId());
+        if(Objects.nonNull(degreeRegistration.getSporadicId())){
+            studentPaymentOrder.setMusicGroupId(degreeRegistration.getSporadicId().toString());
+        }
+        studentPaymentOrder.setOrganId(degreeRegistration.getOrganId());
+        studentPaymentOrder.setRoutingOrganId(degreeRegistration.getOrganId());
+        if (StringUtils.isNotBlank(degreeRegistration.getTheoryLevel())) {
+            courseInfos.add("乐理" + degreeRegistration.getTheoryLevel() + ",费用:" + degreeRegistration.getTheoryMoney());
+        }
+        studentPaymentOrder.setMemo(StringUtils.join(courseInfos, ";"));
+        studentPaymentOrderService.insert(studentPaymentOrder);
+        studentPaymentOrder.setVersion(0);
+
+        if(BigDecimal.ZERO.compareTo(additionCoursePrice)<0){
+            StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
+            studentPaymentOrderDetail.setType(OrderDetailTypeEnum.DEGREE_REGISTRATION);
+            if(Objects.nonNull(degreeRegistration.getAdditionCourseInfo())){
+                studentPaymentOrderDetail.setGoodsIdList(JSON.toJSONString(degreeRegistration.getAdditionCourseInfo()));
+            }
+            studentPaymentOrderDetail.setPrice(additionCoursePrice);
+            studentPaymentOrderDetail.setRemitFee(BigDecimal.ZERO);
+            studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+            studentPaymentOrderDetail.setCreateTime(nowDate);
+            studentPaymentOrderDetail.setUpdateTime(nowDate);
+            studentPaymentOrderDetailDao.insert(studentPaymentOrderDetail);
+        }
+
+        if (amount.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, "恭喜您,支付成功!");
+        }
+
+        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+
+        String receiver = "kjRegister";
+        Map payMap = payService.getPayMap(
+                amount,
+                BigDecimal.ZERO,
+                orderNo,
+                baseApiUrl + "/api-student/studentOrder/notify",
+                baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
+                "乐理考级报名活动",
+                "乐理考级报名活动",
+                degreeRegistration.getOrganId(),
+                receiver
+        );
+
+        studentPaymentOrder.setOrganId(degreeRegistration.getOrganId());
+        studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
+        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
+        studentPaymentOrder.setUpdateTime(nowDate);
+        studentPaymentOrderService.update(studentPaymentOrder);
+        return BaseController.succeed(payMap);
+    }
+
     @Override
     public Boolean updateStatus(StudentPaymentOrder studentPaymentOrder) {
         DegreeRegistration degree = degreeRegistrationDao.getLock(studentPaymentOrder.getClassGroupId());

+ 25 - 0
mec-student/src/main/java/com/ym/mec/student/controller/DegreeController.java

@@ -93,6 +93,31 @@ public class DegreeController extends BaseController {
         return degreeRegistrationService.pay(degreeRegistration);
     }
 
+    @ApiOperation(value = "考级报名支付")
+    @PostMapping("/theoryPay")
+    public HttpResponseResult theoryPay(@RequestBody DegreeRegistrationActivityDto degreeRegistration) throws Exception {
+        SysUser user = sysUserFeignService.queryUserInfo();
+        if(Objects.isNull(user)){
+            return failed(HttpStatus.FORBIDDEN,"请登录");
+        }
+        degreeRegistration.setUserId(user.getId());
+
+        if(Objects.nonNull(degreeRegistration.getTheoryLevel())){
+            IdcardValidator idcardValidator = new IdcardValidator();
+            if (!idcardValidator.isValidatedAllIdcard(degreeRegistration.getIdcard())) {
+                throw new BizException("身份证号不正确,请核对");
+            }
+        }else{
+            degreeRegistration.setOrganId(user.getOrganId());
+        }
+
+        if(Objects.isNull(degreeRegistration.getOrganId())){
+            return failed("该分部暂未参与此活动");
+        }
+
+        return degreeRegistrationService.theoryPay(degreeRegistration);
+    }
+
     @ApiOperation(value = "考级报名检查")
     @PostMapping("/check")
     @Transactional(isolation = Isolation.READ_COMMITTED)