|  | @@ -258,6 +258,10 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
											
												
													
														|  |      private VipGroupCategoryDao vipGroupCategoryDao;
 |  |      private VipGroupCategoryDao vipGroupCategoryDao;
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private SysUserCashAccountLogService sysUserCashAccountLogService;
 |  |      private SysUserCashAccountLogService sysUserCashAccountLogService;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private MemberFeeSettingDao memberFeeSettingDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private MemberFeeSettingService memberFeeSettingService;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      private static Map<Integer, Map<Integer, List<Integer>>> schoolSubjectTeachersMap;
 |  |      private static Map<Integer, Map<Integer, List<Integer>>> schoolSubjectTeachersMap;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -4546,7 +4550,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
											
												
													
														|  |              }/*else if(payStatus == PayStatus.PAYING){
 |  |              }/*else if(payStatus == PayStatus.PAYING){
 | 
											
												
													
														|  |                  throw new BizException("订单还在交易中,请稍后重试");
 |  |                  throw new BizException("订单还在交易中,请稍后重试");
 | 
											
												
													
														|  |              }*/
 |  |              }*/
 | 
											
												
													
														|  | -            if (!practiceGroupBuyParams.isRepeatPay()) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (!practiceGroupBuyParams.getRepeatPay()) {
 | 
											
												
													
														|  |                  return BaseController.failed(HttpStatus.CONTINUE, "您有待支付的订单");
 |  |                  return BaseController.failed(HttpStatus.CONTINUE, "您有待支付的订单");
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |              //处理关闭订单
 |  |              //处理关闭订单
 | 
											
										
											
												
													
														|  | @@ -4614,7 +4618,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          BigDecimal amount = studentPaymentOrder.getActualAmount();
 |  |          BigDecimal amount = studentPaymentOrder.getActualAmount();
 | 
											
												
													
														|  |          BigDecimal balance = BigDecimal.ZERO;
 |  |          BigDecimal balance = BigDecimal.ZERO;
 | 
											
												
													
														|  | -        if (practiceGroupBuyParams.isUseBalancePayment() || amount.doubleValue() == 0) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +        if (practiceGroupBuyParams.getUseBalancePayment() || amount.doubleValue() == 0) {
 | 
											
												
													
														|  |              SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(user.getId());
 |  |              SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(user.getId());
 | 
											
												
													
														|  |              if (userCashAccount == null) {
 |  |              if (userCashAccount == null) {
 | 
											
												
													
														|  |                  throw new BizException("用户账户找不到");
 |  |                  throw new BizException("用户账户找不到");
 | 
											
										
											
												
													
														|  | @@ -4686,6 +4690,123 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
												
													
														|  | 
 |  | +    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 | 
											
												
													
														|  | 
 |  | +    public Object buyActivityPracticeGroup(PracticeGroupBuyParamsDto practiceGroupBuyParams) throws Exception {
 | 
											
												
													
														|  | 
 |  | +        Integer activityId = practiceGroupBuyParams.getActivityId();
 | 
											
												
													
														|  | 
 |  | +        VipGroupActivity activity = vipGroupActivityDao.get(activityId);
 | 
											
												
													
														|  | 
 |  | +        Date now = new Date();
 | 
											
												
													
														|  | 
 |  | +        Date startTime = activity.getStartTime();
 | 
											
												
													
														|  | 
 |  | +        Date endTime = activity.getEndTime();
 | 
											
												
													
														|  | 
 |  | +        if (startTime != null && startTime.compareTo(now) > 0) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("活动尚未开始,感谢您的关注");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        if (endTime != null && endTime.compareTo(now) <= 0) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("活动已结束,感谢您的参与");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        Student student = studentDao.getLocked(practiceGroupBuyParams.getUserId());
 | 
											
												
													
														|  | 
 |  | +        Integer studentMaxUsedTimes = activity.getStudentMaxUsedTimes();
 | 
											
												
													
														|  | 
 |  | +        if (studentMaxUsedTimes != -1) {
 | 
											
												
													
														|  | 
 |  | +            //获取活动购买次数
 | 
											
												
													
														|  | 
 |  | +            int activityBuyNum = activityUserMapperService.countActivityBuyNum(activityId, practiceGroupBuyParams.getUserId());
 | 
											
												
													
														|  | 
 |  | +            if (activityBuyNum >= studentMaxUsedTimes) {
 | 
											
												
													
														|  | 
 |  | +                throw new BizException("当前活动最多课购买{}次,感谢您的参与", studentMaxUsedTimes);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        //判断用户是否已存在订单
 | 
											
												
													
														|  | 
 |  | +        // 判断是否存在支付中的记录
 | 
											
												
													
														|  | 
 |  | +        List<StudentPaymentOrder> applyOrderList = studentPaymentOrderService.queryByCondition(GroupType.MEMBER, null, student.getUserId(), DealStatusEnum.ING, OrderTypeEnum.ACTIVITY);
 | 
											
												
													
														|  | 
 |  | +        if (org.apache.commons.collections.CollectionUtils.isNotEmpty(applyOrderList)) {
 | 
											
												
													
														|  | 
 |  | +            HttpResponseResult result = studentPaymentOrderService.checkRepeatPay(applyOrderList.get(0), practiceGroupBuyParams.getRepeatPay());
 | 
											
												
													
														|  | 
 |  | +            if (result.getCode() != 200) {
 | 
											
												
													
														|  | 
 |  | +                return result;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        //现价
 | 
											
												
													
														|  | 
 |  | +        Integer buyNum = practiceGroupBuyParams.getBuyMemberNum();
 | 
											
												
													
														|  | 
 |  | +        BigDecimal activityFee = activity.getMarketPrice().multiply(new BigDecimal(buyNum)).
 | 
											
												
													
														|  | 
 |  | +                multiply(activity.getDiscount()).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
 | 
											
												
													
														|  | 
 |  | +        //计算订单金额
 | 
											
												
													
														|  | 
 |  | +        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(), activityFee, true);
 | 
											
												
													
														|  | 
 |  | +        activityFee = studentPaymentOrder.getActualAmount();
 | 
											
												
													
														|  | 
 |  | +        if (practiceGroupBuyParams.getAmount().compareTo(activityFee) != 0) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("非法访问");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        String channelType = "";
 | 
											
												
													
														|  | 
 |  | +        Date nowDate = new Date();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        BigDecimal balance = BigDecimal.ZERO;
 | 
											
												
													
														|  | 
 |  | +        if (practiceGroupBuyParams.getUseBalancePayment() && activityFee.compareTo(BigDecimal.ZERO) > 0) {
 | 
											
												
													
														|  | 
 |  | +            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(student.getUserId());
 | 
											
												
													
														|  | 
 |  | +            if (userCashAccount == null) {
 | 
											
												
													
														|  | 
 |  | +                throw new BizException("用户账户找不到");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
 | 
											
												
													
														|  | 
 |  | +                balance = activityFee.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : activityFee;
 | 
											
												
													
														|  | 
 |  | +                activityFee = activityFee.subtract(balance);
 | 
											
												
													
														|  | 
 |  | +                studentPaymentOrder.setActualAmount(activityFee);
 | 
											
												
													
														|  | 
 |  | +                studentPaymentOrder.setBalancePaymentAmount(balance);
 | 
											
												
													
														|  | 
 |  | +                sysUserCashAccountService.updateBalance(student.getUserId(), balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "营销活动购买");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setPaymentChannel("BALANCE");
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setUserId(student.getUserId());
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setGroupType(GroupType.MEMBER);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setOrderNo(orderNo);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setType(OrderTypeEnum.MEMBER);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setRemitFee(BigDecimal.ZERO);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setCourseRemitFee(BigDecimal.ZERO);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setOrganId(practiceGroupBuyParams.getOrganId());
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setRoutingOrganId(practiceGroupBuyParams.getOrganId());
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setCreateTime(nowDate);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setUpdateTime(nowDate);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setActivityId(activityId.toString());
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setActivityBuyNum(buyNum);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrderService.insert(studentPaymentOrder);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setVersion(0);
 | 
											
												
													
														|  | 
 |  | +        if (activityFee.compareTo(BigDecimal.ZERO) == 0) {
 | 
											
												
													
														|  | 
 |  | +            studentPaymentRouteOrderService.addRouteOrder(orderNo, practiceGroupBuyParams.getOrganId(), balance);
 | 
											
												
													
														|  | 
 |  | +            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 notifyMap;
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        String orderSubject = "营销活动";
 | 
											
												
													
														|  | 
 |  | +        String receiver = "activity";
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        Map payMap = payService.getPayMap(
 | 
											
												
													
														|  | 
 |  | +                activityFee,
 | 
											
												
													
														|  | 
 |  | +                balance,
 | 
											
												
													
														|  | 
 |  | +                orderNo,
 | 
											
												
													
														|  | 
 |  | +                baseApiUrl + "/api-student/studentOrder/notify",
 | 
											
												
													
														|  | 
 |  | +                baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
 | 
											
												
													
														|  | 
 |  | +                orderSubject,
 | 
											
												
													
														|  | 
 |  | +                orderSubject,
 | 
											
												
													
														|  | 
 |  | +                studentPaymentOrder.getOrganId(),
 | 
											
												
													
														|  | 
 |  | +                receiver
 | 
											
												
													
														|  | 
 |  | +        );
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setOrganId(studentPaymentOrder.getOrganId());
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrder.setUpdateTime(nowDate);
 | 
											
												
													
														|  | 
 |  | +        studentPaymentOrderService.update(studentPaymentOrder);
 | 
											
												
													
														|  | 
 |  | +        return payMap;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @Override
 | 
											
												
													
														|  |      public StudentVipGroupDetailDto getPracticeGroupDetail(Long groupId) {
 |  |      public StudentVipGroupDetailDto getPracticeGroupDetail(Long groupId) {
 | 
											
												
													
														|  |          return practiceGroupDao.getPracticeGroupDetail(groupId);
 |  |          return practiceGroupDao.getPracticeGroupDetail(groupId);
 | 
											
												
													
														|  |      }
 |  |      }
 |