|
|
@@ -4877,4 +4877,159 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
return payMap;
|
|
|
}
|
|
|
+
|
|
|
+ @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);
|
|
|
+ if(!activity.getEnable()){
|
|
|
+ throw new BizException("活动尚未开启,感谢您的关注");
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ Date startTime = activity.getStartTime();
|
|
|
+ Date endTime = activity.getEndTime();
|
|
|
+ if(startTime.compareTo(now) > 0){
|
|
|
+ throw new BizException("活动尚未开始,感谢您的关注");
|
|
|
+ }
|
|
|
+ if(endTime.compareTo(now) <= 0){
|
|
|
+ throw new BizException("活动已结束,感谢您的参与");
|
|
|
+ }
|
|
|
+ Student student = studentDao.getLocked(practiceGroupBuyParams.getUserId());
|
|
|
+ Integer studentMaxUsedTimes = activity.getStudentMaxUsedTimes();
|
|
|
+ if(studentMaxUsedTimes != -1){
|
|
|
+ //获取活动购买次数
|
|
|
+ int activityBuyNum = activityUserMapperDao.countActivityBuyNum(activityId, practiceGroupBuyParams.getUserId());
|
|
|
+ if(activityBuyNum >= studentMaxUsedTimes){
|
|
|
+ throw new BizException("当前活动最多课购买{}次,感谢您的参与",studentMaxUsedTimes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ OrderTypeEnum orderTypeEnum;
|
|
|
+ if(activity.getActivityType() == 1){
|
|
|
+ orderTypeEnum = OrderTypeEnum.MEMBER;
|
|
|
+ }else {
|
|
|
+ if(activity.getCourseType().equals("VIP")){
|
|
|
+ orderTypeEnum = OrderTypeEnum.SMALL_CLASS_TO_BUY;
|
|
|
+ }else {
|
|
|
+ orderTypeEnum = OrderTypeEnum.PRACTICE_GROUP_BUY;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断用户是否已存在订单
|
|
|
+ // 判断是否存在支付中的记录
|
|
|
+ List<StudentPaymentOrder> list = studentPaymentOrderService
|
|
|
+ .queryByCondition(GroupType.ACTIVITY,null,student.getUserId(),DealStatusEnum.ING,orderTypeEnum);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ StudentPaymentOrder order = list.get(0);
|
|
|
+ // 查询订单状态
|
|
|
+ PayStatus payStatus = studentPaymentOrderService.queryPayStatus(order.getPaymentChannel(), order.getOrderNo(), order.getTransNo());
|
|
|
+ if(payStatus == PayStatus.SUCCESSED){
|
|
|
+ throw new BizException("订单已支付成功,请勿重复支付");
|
|
|
+ }else if(payStatus == PayStatus.PAYING){
|
|
|
+ throw new BizException("订单还在交易中,请稍后重试");
|
|
|
+ }
|
|
|
+ if(practiceGroupBuyParams.isRepeatPay()){
|
|
|
+ //处理关闭订单
|
|
|
+ order.setStatus(DealStatusEnum.CLOSE);
|
|
|
+ order.setMemo("关闭活动订单");
|
|
|
+ if (order.getBalancePaymentAmount() != null && order.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(order.getUserId(), order.getBalancePaymentAmount(),
|
|
|
+ PlatformCashAccountDetailTypeEnum.REFUNDS, "购买活动支付失败");
|
|
|
+ }
|
|
|
+ studentPaymentOrderService.update(order);
|
|
|
+ sysCouponCodeService.quit(order.getCouponCodeId());
|
|
|
+ }else {
|
|
|
+ return BaseController.failed(HttpStatus.CONTINUE,"您有待支付的订单");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal activityFee = BigDecimal.ZERO;
|
|
|
+ GroupType groupType = GroupType.MEMBER;
|
|
|
+ //计算订单金额
|
|
|
+ switch (orderTypeEnum) {
|
|
|
+ case MEMBER:
|
|
|
+ groupType = GroupType.MEMBER;
|
|
|
+ break;
|
|
|
+ case SMALL_CLASS_TO_BUY:
|
|
|
+ groupType = GroupType.VIP;
|
|
|
+ break;
|
|
|
+ case PRACTICE_GROUP_BUY:
|
|
|
+ groupType = GroupType.PRACTICE;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ 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.isUseBalancePayment() && 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);
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setType(orderTypeEnum);
|
|
|
+ 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);
|
|
|
+ studentPaymentOrderService.update(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 = "6.1考级活动";
|
|
|
+ String receiver = "degree";
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|