Просмотр исходного кода

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 5 лет назад
Родитель
Сommit
7f8040aa31

+ 14 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDao.java

@@ -233,4 +233,18 @@ public interface StudentPaymentOrderDao extends BaseDAO<Long, StudentPaymentOrde
      */
     List<StudentPaymentOrder> findUserBuyVipGroupOrder(@Param("userId") Integer userId,
                                                        @Param("vipGroupId") Integer vipGroupId);
+
+    /**
+     * @describe 获取用户的团体订单
+     * @author Joburgess
+     * @date 2020/2/21
+     * @param userId:
+     * @param groupId:
+     * @param groupType:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentPaymentOrder>
+     */
+    List<StudentPaymentOrder> findUserGroupOrders(@Param("userId") Integer userId,
+                                                  @Param("groupId") String groupId,
+                                                  @Param("groupType") GroupType groupType,
+                                                  @Param("status") DealStatusEnum orderStatus);
 }

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TeacherClassGroupDto.java

@@ -84,7 +84,7 @@ public class TeacherClassGroupDto {
     private String studyReportUrl;
 
     @ApiModelProperty(value = "是否已有报告")
-    private Boolean hasReport;
+    private Boolean hasReport=false;
 
     public Date getCourseStartDate() {
         return courseStartDate;

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/GroupStatusEnum.java

@@ -9,7 +9,8 @@ import com.ym.mec.common.enums.BaseEnum;
 public enum GroupStatusEnum implements BaseEnum<String, GroupStatusEnum> {
 
     NORMAL("NORMAL", "正常"),
-    LOCK("LOCK", "锁定");
+    LOCK("LOCK", "锁定"),
+    FINISH("FINISH", "结束");
 
     private String code;
 

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

@@ -196,4 +196,13 @@ public interface PracticeGroupService extends BaseService<Long, PracticeGroup> {
 	 * @return com.ym.mec.biz.dal.dto.PracticeBuyResultDto
 	 */
 	PracticeBuyResultDto queryOrderInfo(String orderNo);
+
+	/**
+	 * @describe
+	 * @author Joburgess
+	 * @date 2020/2/21
+	 * @param practiceGroupId:
+	 * @return com.ym.mec.common.entity.HttpResponseResult
+	 */
+	HttpResponseResult repay(Integer userId,Integer practiceGroupId);
 }

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

@@ -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);
+        }
+    }
 }

+ 1 - 2
mec-biz/src/main/resources/config/mybatis/PracticeGroupMapper.xml

@@ -133,10 +133,9 @@
 			practice_group pg
 			LEFT JOIN sys_user su ON pg.user_id_ = su.id_
 			LEFT JOIN `subject` s ON pg.subject_id_ = s.id_
-			LEFT JOIN student_payment_order spo ON spo.music_group_id_=pg.id_ AND spo.group_type_='PRACTICE'
 		WHERE
 			student_id_=#{userId}
-			AND spo.status_="SUCCESS"
+			AND pg.group_status_!='FINISH'
 	</select>
 	<select id="findUserPracticeGroup" resultMap="PracticeGroup">
 		SELECT * FROM practice_group WHERE student_id_=#{userId} AND id_=#{groupId};

+ 9 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -510,4 +510,13 @@
     <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
       select * from student_payment_order where  user_id_=#{userId} and music_group_id_=#{vipGroupId} and group_type_='VIP'
     </select>
+    <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
+        select * from student_payment_order
+        where user_id_=#{userId}
+        and music_group_id_=#{groupId}
+        and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+        <if test="status!=null">
+            and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+        </if>
+    </select>
 </mapper>

+ 10 - 0
mec-student/src/main/java/com/ym/mec/student/controller/PracticeGroupController.java

@@ -165,4 +165,14 @@ public class PracticeGroupController extends BaseController {
         return succeed(practiceGroupService.queryOrderInfo(orderNo));
     }
 
+    @ApiOperation("重新支付")
+    @PostMapping(value = "/repay")
+    public HttpResponseResult repay(Integer groupId){
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            return failed(HttpStatus.FORBIDDEN, "请登录");
+        }
+        return succeed(practiceGroupService.repay(sysUser.getId(),groupId));
+    }
+
 }