|
@@ -26,6 +26,7 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -2328,14 +2329,21 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
|
|
|
ZoneId zoneId = ZoneId.systemDefault();
|
|
|
|
|
|
+ Date today=new Date();
|
|
|
+
|
|
|
LocalDate now = LocalDate.now();
|
|
|
if(renew){
|
|
|
PracticeGroup userLatestPracticeGroup = practiceGroupDao.findUserPracticeGroup(userId,groupId);
|
|
|
if(Objects.nonNull(userLatestPracticeGroup)){
|
|
|
+ if(userLatestPracticeGroup.getCoursesExpireDate().after(today)){
|
|
|
+ throw new BizException("此课程组已超过可续费期限");
|
|
|
+ }
|
|
|
LocalDate lastExpiredDay=LocalDateTime.ofInstant(userLatestPracticeGroup.getCoursesExpireDate().toInstant(),DateUtil.zoneId).toLocalDate();
|
|
|
if(Objects.nonNull(lastExpiredDay)&&lastExpiredDay.compareTo(now)>=0){
|
|
|
now=lastExpiredDay;
|
|
|
}
|
|
|
+ }else{
|
|
|
+ throw new BizException("需要续费的课程组不存在");
|
|
|
}
|
|
|
}
|
|
|
now.plusDays(1);
|
|
@@ -2873,13 +2881,23 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
@Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
|
|
public void orderCallback(StudentPaymentOrder order) {
|
|
|
StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(order.getId());
|
|
|
- if(studentPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS)){
|
|
|
+ if(!studentPaymentOrder.getStatus().equals(DealStatusEnum.ING)){
|
|
|
return;
|
|
|
}
|
|
|
+ List<StudentPaymentOrder> userGroupOrders = studentPaymentOrderDao.findUserGroupOrders(order.getUserId(), order.getMusicGroupId(), order.getGroupType(),null);
|
|
|
+ Map<DealStatusEnum, Long> statusOrderNumMap = userGroupOrders.stream().collect(Collectors.groupingBy(StudentPaymentOrder::getStatus, Collectors.counting()));
|
|
|
+ Long successOrderNum=statusOrderNumMap.get(DealStatusEnum.SUCCESS);
|
|
|
+ if(Objects.nonNull(successOrderNum)&&successOrderNum>0){
|
|
|
+ studentPaymentOrderDao.update(order);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if(order.getStatus().equals(DealStatusEnum.SUCCESS)){
|
|
|
courseScheduleDao.updateGroupCourseLock(order.getMusicGroupId(),GroupType.PRACTICE,0);
|
|
|
}else{
|
|
|
+ studentPaymentOrderDao.update(order);
|
|
|
groupService.deleteGroupInfo(order.getMusicGroupId(),GroupType.PRACTICE);
|
|
|
+ return;
|
|
|
}
|
|
|
studentPaymentOrderDao.update(order);
|
|
|
SysUserCashAccount sysUserCashAccount = sysUserCashAccountService.get(order.getUserId());
|
|
@@ -2989,4 +3007,72 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
practiceBuyResult.setTeacherName(teacher.getRealName());
|
|
|
return practiceBuyResult;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
|
|
+ public HttpResponseResult repay(Integer userId,Integer practiceGroupId) {
|
|
|
+ if(Objects.isNull(practiceGroupId)){
|
|
|
+ throw new BizException("请指定需要重新支付的课程组");
|
|
|
+ }
|
|
|
+ PracticeGroup practiceGroup = practiceGroupDao.get(practiceGroupId.longValue());
|
|
|
+ if(!practiceGroup.getGroupStatus().equals(GroupStatusEnum.LOCK)){
|
|
|
+ throw new BizException("此课程组不处于支付中");
|
|
|
+ }
|
|
|
+ List<StudentPaymentOrder> userGroupOrders = studentPaymentOrderDao.findUserGroupOrders(userId, practiceGroupId.toString(), GroupType.PRACTICE,null);
|
|
|
+ Map<DealStatusEnum, List<StudentPaymentOrder>> statusOrderMap = userGroupOrders.stream().collect(Collectors.groupingBy(StudentPaymentOrder::getStatus));
|
|
|
+ List<StudentPaymentOrder> successOrders=statusOrderMap.get(DealStatusEnum.SUCCESS);
|
|
|
+ if(!CollectionUtils.isEmpty(successOrders)&&successOrders.size()>0){
|
|
|
+ throw new BizException("此课程组存在支付成功的订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ StudentPaymentOrder latestOrder=userGroupOrders.stream().max(Comparator.comparing(StudentPaymentOrder::getCreateTime)).get();
|
|
|
+ StudentPaymentOrder newOrder = new StudentPaymentOrder();
|
|
|
+ BeanUtils.copyProperties(latestOrder,newOrder);
|
|
|
+ newOrder.setId(null);
|
|
|
+
|
|
|
+ List<StudentPaymentOrder> ingOrders = statusOrderMap.get(DealStatusEnum.ING);
|
|
|
+ if(CollectionUtils.isEmpty(ingOrders)||ingOrders.size()<=0){
|
|
|
+ throw new BizException("此课程组不存在进行中的订单");
|
|
|
+ }else{
|
|
|
+ for (StudentPaymentOrder ingOrder : ingOrders) {
|
|
|
+ ingOrder.setStatus(DealStatusEnum.CLOSE);
|
|
|
+ ingOrder.setMemo("用户重新支付");
|
|
|
+ studentPaymentOrderDao.update(ingOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderNo=idGeneratorService.generatorId("payment") + "";
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
+ Map<String, BigDecimal> classFee = new HashMap<>();
|
|
|
+ classFee.put("course",newOrder.getActualAmount());
|
|
|
+ classFee.put("instrument",BigDecimal.ZERO);
|
|
|
+ classFee.put("accessories",BigDecimal.ZERO);
|
|
|
+ classFee.put("other",BigDecimal.ZERO);
|
|
|
+ try {
|
|
|
+ Map<String,Object> payMap = payService.getPayMap(
|
|
|
+ newOrder.getActualAmount(),
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl+"/api-student/studentOrder/notify",
|
|
|
+ baseApiUrl+"/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
+ "vip课购买",
|
|
|
+ practiceGroup.getName(),
|
|
|
+ practiceGroup.getStudentId(),
|
|
|
+ classFee,
|
|
|
+ practiceGroup.getOrganId()
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<String,BigDecimal> routingFee = (Map<String,BigDecimal>)payMap.get("routingFee");
|
|
|
+ newOrder.setOrganId(practiceGroup.getOrganId());
|
|
|
+ newOrder.setComAmount(routingFee.get("COM"));
|
|
|
+ newOrder.setPerAmount(routingFee.get("PER"));
|
|
|
+ newOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ newOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ newOrder.setUpdateTime(new Date());
|
|
|
+ studentPaymentOrderService.insert(newOrder);
|
|
|
+
|
|
|
+ return BaseController.succeed(payMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("调用支付接口出错", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|