浏览代码

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

yonge 4 年之前
父节点
当前提交
28affc1b7b

+ 2 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupPaymentCalenderDetailDao.java

@@ -194,8 +194,8 @@ public interface MusicGroupPaymentCalenderDetailDao extends BaseDAO<Long, MusicG
 	 * @author zouxuan
 	 * @date 2020/11/3
 	 * @time 15:41
-	 * @param orderNo:
+	 * @param orderId:
 	 * @return com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail
 	 */
-	MusicGroupPaymentCalenderDetail findByOrderNo(@Param("orderNo") String orderNo);
+	MusicGroupPaymentCalenderDetail findByOrderId(@Param("orderId") Long orderId);
 }

+ 33 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SporadicChargeInfo.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.dal.entity;
 
 import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
+import com.ym.mec.biz.dal.enums.YesOrNoEnum;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.math.BigDecimal;
@@ -68,6 +69,14 @@ public class SporadicChargeInfo {
 
 	private Integer paidNum;
 
+	@ApiModelProperty(value = "最大缴费金额", required = true)
+	private BigDecimal maxAmount;
+
+	private BigDecimal paidAmount;
+
+	@ApiModelProperty(value = "是否开启最大缴费金额限制 1 开启 0-关闭", required = true)
+	private YesOrNoEnum openMaxTerm;
+
 	private Integer version;
 
 	public String getMusicGroupName() {
@@ -261,4 +270,28 @@ public class SporadicChargeInfo {
 	public void setVersion(Integer version) {
 		this.version = version;
 	}
+
+	public BigDecimal getMaxAmount() {
+		return maxAmount;
+	}
+
+	public void setMaxAmount(BigDecimal maxAmount) {
+		this.maxAmount = maxAmount;
+	}
+
+	public BigDecimal getPaidAmount() {
+		return paidAmount;
+	}
+
+	public void setPaidAmount(BigDecimal paidAmount) {
+		this.paidAmount = paidAmount;
+	}
+
+	public YesOrNoEnum getOpenMaxTerm() {
+		return openMaxTerm;
+	}
+
+	public void setOpenMaxTerm(YesOrNoEnum openMaxTerm) {
+		this.openMaxTerm = openMaxTerm;
+	}
 }

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

@@ -147,12 +147,12 @@ public interface MusicGroupService extends BaseService<String, MusicGroup> {
 
 	/**
 	 *  续费
-	 * @param musicGroupId 乐团编号
+	 * @param calenderId 缴费项目编号
 	 * @param userId 用户编号
 	 * @param isUseBalancePayment 是否使用余额付款
 	 * @return
 	 */
-	Map renew(String musicGroupId, Integer userId, boolean isUseBalancePayment) throws Exception;
+	Map renew(Long calenderId, Integer userId, boolean isUseBalancePayment) throws Exception;
 
 	/**
 	 * 学生支付订单

+ 70 - 143
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -1,74 +1,18 @@
 package com.ym.mec.biz.service.impl;
 
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import com.ym.mec.biz.dal.dao.*;
-import com.ym.mec.biz.dal.entity.*;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.entity.SysUserRole;
-import com.ym.mec.biz.dal.dto.BasicUserDto;
-import com.ym.mec.biz.dal.dto.CourseFormDto;
-import com.ym.mec.biz.dal.dto.CourseScheduleTeachersDto;
-import com.ym.mec.biz.dal.dto.HighClassGroupDto;
-import com.ym.mec.biz.dal.dto.MusicCardDto;
-import com.ym.mec.biz.dal.dto.RegisterPayDto;
-import com.ym.mec.biz.dal.dto.SporadicPayDto;
-import com.ym.mec.biz.dal.dto.SubFeeSettingDto;
-import com.ym.mec.biz.dal.dto.SubjectRegisterDto;
-import com.ym.mec.biz.dal.dto.UpdateExpectedNumDto;
+import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dto.*;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus;
-import com.ym.mec.biz.dal.enums.ClassGroupTypeEnum;
-import com.ym.mec.biz.dal.enums.DealStatusEnum;
-import com.ym.mec.biz.dal.enums.GoodsType;
-import com.ym.mec.biz.dal.enums.GroupType;
-import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
-import com.ym.mec.biz.dal.enums.MessageTypeEnum;
-import com.ym.mec.biz.dal.enums.MusicGroupStatusEnum;
-import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
-import com.ym.mec.biz.dal.enums.OrderTypeEnum;
-import com.ym.mec.biz.dal.enums.PaymentStatusEnum;
-import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
-import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
-import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
+import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.dal.page.MusicGroupQueryInfo;
-import com.ym.mec.biz.service.ClassGroupService;
-import com.ym.mec.biz.service.ClassGroupStudentMapperService;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.MusicGroupPaymentCalenderService;
-import com.ym.mec.biz.service.MusicGroupService;
-import com.ym.mec.biz.service.MusicGroupSubjectGoodsGroupService;
-import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
-import com.ym.mec.biz.service.PayService;
-import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
-import com.ym.mec.biz.service.StudentRegistrationService;
-import com.ym.mec.biz.service.SysConfigService;
-import com.ym.mec.biz.service.SysMessageService;
-import com.ym.mec.biz.service.SysUserCashAccountDetailService;
-import com.ym.mec.biz.service.SysUserCashAccountService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.entity.ImGroupMember;
 import com.ym.mec.common.entity.ImGroupModel;
@@ -81,6 +25,20 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext.MessageSender;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.CLOSE;
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
 
 @Service
 public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> implements MusicGroupService {
@@ -343,11 +301,11 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         if (!(amount.compareTo(sporadicPayDto.getAmount()) == 0)) {
             throw new BizException("订单金额异常");
         }
-        if (chargeInfo.getMaxNum() != null) {
-            if (chargeInfo.getMaxNum() <= chargeInfo.getPaidNum()) {
+        if (chargeInfo.getMaxAmount() != null) {
+            if (chargeInfo.getOpenMaxTerm().equals(YesOrNoEnum.YES) && chargeInfo.getMaxAmount().compareTo(chargeInfo.getPaidAmount()) <= 0) {
                 throw new Exception("活动人数暂时已满,请稍后再试");
             }
-            chargeInfo.setPaidNum(chargeInfo.getPaidNum() + 1);
+            chargeInfo.setPaidAmount(chargeInfo.getPaidAmount().add(chargeInfo.getAmount()));
             chargeInfo.setUpdateTime(new Date());
             int update = sporadicChargeInfoDao.update(chargeInfo);
             if (update <= 0) {
@@ -1267,13 +1225,13 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         teacherAttendanceDao.deleteByMusicGroupId(musicGroupId, GroupType.MUSIC);
 
         // 查询已缴费信息
-        studentPaymentOrders = studentPaymentOrderDao.queryByDealStatus(musicGroupId, OrderTypeEnum.APPLY, DealStatusEnum.SUCCESS);
+        studentPaymentOrders = studentPaymentOrderDao.queryByDealStatus(musicGroupId, OrderTypeEnum.APPLY, SUCCESS);
 
         // 退费
         for (StudentPaymentOrder order : studentPaymentOrders) {
             // 增加交易流水
             sysUserCashAccountDetailService.addCashAccountDetail(order.getUserId(), order.getActualAmount().add(order.getBalancePaymentAmount()), SysUserCashAccountDetailService.MUSIC_GROUP
-                    + musicGroupId, "", PlatformCashAccountDetailTypeEnum.REFUNDS, null, DealStatusEnum.SUCCESS, "取消乐团", null);
+                    + musicGroupId, "", PlatformCashAccountDetailTypeEnum.REFUNDS, null, SUCCESS, "取消乐团", null);
         }
         //获取当前乐团所有已报名学员
         if (musicGroup.getOwnershipType() != null && musicGroup.getOwnershipType() == CooperationOrgan.OwnershipType.OWN) {
@@ -1540,7 +1498,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             // 判断乐器是否是租赁
             // MusicGroupSubjectPlan musicGroupSubjectPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(musicGroupId, subjectId);
 
-            StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, DealStatusEnum.SUCCESS);
+            StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, SUCCESS);
 
             if (studentPaymentOrder == null) {
                 //兼容历史数据
@@ -1582,7 +1540,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             if (amount.doubleValue() > 0) {
                 // 增加交易流水
                 sysUserCashAccountDetailService.addCashAccountDetail(userId, amount, SysUserCashAccountDetailService.MUSIC_GROUP + musicGroupId, "",
-                        PlatformCashAccountDetailTypeEnum.REFUNDS, null, DealStatusEnum.SUCCESS, "退出乐团", null);
+                        PlatformCashAccountDetailTypeEnum.REFUNDS, null, SUCCESS, "退出乐团", null);
             }
         }
         return true;
@@ -1643,7 +1601,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         // 判断乐器是否是租赁
         // MusicGroupSubjectPlan musicGroupSubjectPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(musicGroupId, subjectId);
 
-        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, DealStatusEnum.SUCCESS);
+        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, SUCCESS);
 
         if (studentPaymentOrder == null) {
             return true;
@@ -1683,7 +1641,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         if (amount.doubleValue() > 0) {
             // 增加交易流水
             sysUserCashAccountDetailService.addCashAccountDetail(userId, amount, SysUserCashAccountDetailService.MUSIC_GROUP + musicGroupId, "",
-                    PlatformCashAccountDetailTypeEnum.REFUNDS, null, DealStatusEnum.SUCCESS, "退出乐团", null);
+                    PlatformCashAccountDetailTypeEnum.REFUNDS, null, SUCCESS, "退出乐团", null);
         }
 
         return true;
@@ -1691,41 +1649,31 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
-    public Map renew(String musicGroupId, Integer userId, boolean isUseBalancePayment) throws Exception {
-
-        MusicGroup musicGroup = this.get(musicGroupId);
-        if (musicGroup == null) {
-            throw new BizException("乐团不存在");
+    public Map renew(Long calenderId, Integer userId, boolean isUseBalancePayment) throws Exception {
+        MusicGroupPaymentCalender calender = musicGroupPaymentCalenderDao.get(calenderId);
+        if (calender == null) {
+            throw new BizException("缴费项目不存在");
         }
-
-        MusicGroupStudentFee musicGroupStudentFee = musicGroupStudentFeeDao.findByUser(userId, musicGroupId);
-
-        if (musicGroupStudentFee == null) {
-            throw new BizException("个人续费信息错误");
-        }
-
-        StudentRegistration studentRegistration = studentRegistrationService.queryByUserIdAndMusicGroupId(userId, musicGroupId);
+        StudentRegistration studentRegistration = studentRegistrationService.queryByUserIdAndMusicGroupId(userId, calender.getMusicGroupId());
         if (studentRegistration == null || studentRegistration.getPaymentStatus() != PaymentStatusEnum.YES) {
             throw new BizException("请走报名缴费流程");
         }
-        MusicGroupPaymentCalenderDetail userLastCalenderDetail = musicGroupPaymentCalenderDetailDao.getUserLastCalenderDetail(musicGroupId, userId);
-        if (userLastCalenderDetail == null) {
-            throw new BizException("当前续费时间已截止,请联系指导老师");
+        Integer organId = studentRegistration.getOrganId();
+        MusicGroupPaymentCalenderDetail calenderDetail = musicGroupPaymentCalenderDetailDao.findByCalenderIdAndUserId(calenderId, userId);
+        //关闭之前的订单
+        if(calenderDetail.getPaymentOrderId() != null){
+            StudentPaymentOrder oldStudentPaymentOrder = studentPaymentOrderDao.get(calenderDetail.getPaymentOrderId());
+            if(oldStudentPaymentOrder != null){
+                if(oldStudentPaymentOrder.getStatus() == SUCCESS){
+                    throw new BizException("您已支付请勿重复提交");
+                }
+                oldStudentPaymentOrder.setStatus(CLOSE);
+                studentPaymentOrderService.update(oldStudentPaymentOrder);
+            }
         }
-
-        //判断是否是续费
-		/*List<StudentPaymentOrder> orderList = studentPaymentOrderDao.queryByCondition(GroupType.MUSIC, musicGroupId, userId, DealStatusEnum.SUCCESS);
-		if (orderList == null || orderList.size() == 0) {
-			throw new BizException("请走报名缴费流程");
-		}*/
-
         String orderNo = idGeneratorService.generatorId("payment") + "";
-        // 判断当前是否是续费状态
-        if (musicGroupStudentFee.getPaymentStatus() != PaymentStatus.NON_PAYMENT) {
-            throw new BizException("已缴费");
-        }
 
-        BigDecimal amount = userLastCalenderDetail.getExpectAmount();
+        BigDecimal amount = calenderDetail.getExpectAmount();
 
         Date date = new Date();
         StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
@@ -1736,11 +1684,13 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         studentPaymentOrder.setExpectAmount(amount);
         studentPaymentOrder.setActualAmount(amount);
         studentPaymentOrder.setStatus(DealStatusEnum.ING);
-        studentPaymentOrder.setMusicGroupId(musicGroupId);
+        studentPaymentOrder.setMusicGroupId(calender.getMusicGroupId());
         studentPaymentOrder.setCreateTime(date);
         studentPaymentOrder.setUpdateTime(date);
         studentPaymentOrder.setVersion(0);
         studentPaymentOrderService.insert(studentPaymentOrder);
+        calenderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+        musicGroupPaymentCalenderDetailDao.update(calenderDetail);
 
         ArrayList<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
         StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
@@ -1761,45 +1711,19 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             }
             studentPaymentOrder.setPaymentChannel("BALANCE");
             if (userCashAccount.getBalance().subtract(amount).doubleValue() >= 0) {
-                studentPaymentRouteOrderService.addRouteOrder(orderNo, musicGroup.getOrganId(), amount);
+                studentPaymentRouteOrderService.addRouteOrder(orderNo, organId, amount);
 
                 // 更新订单信息
                 studentPaymentOrder.setActualAmount(BigDecimal.ZERO);
                 studentPaymentOrder.setBalancePaymentAmount(amount);
                 studentPaymentOrder.setActualAmount(new BigDecimal(0));
-                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
+                studentPaymentOrder.setStatus(SUCCESS);
                 studentPaymentOrder.setUpdateTime(date);
-                studentPaymentOrder.setOrganId(musicGroup.getOrganId());
-                studentPaymentOrder.setRoutingOrganId(musicGroup.getOrganId());
+                studentPaymentOrder.setOrganId(organId);
+                studentPaymentOrder.setRoutingOrganId(organId);
                 studentPaymentOrderService.update(studentPaymentOrder);
 
                 sysUserCashAccountService.updateBalance(userId, amount.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团续费");
-
-                MusicGroupPaymentCalender musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(userLastCalenderDetail.getMusicGroupPaymentCalenderId());
-                //更新下次续费时间
-                musicGroupStudentFee.setUpdateTime(date);
-                musicGroupStudentFee.setLatestPaidTime(date);
-                musicGroupStudentFee.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
-                musicGroupStudentFee.setTemporaryCourseFee(new BigDecimal(0));
-                /*if (musicGroupPaymentCalender.getType().equals(MusicGroupPaymentCalender.FeeType.ONLINE)) {
-                    Integer getRemainNetworkClassTimes = musicGroupStudentFee.getRemainNetworkClassTimes() == null ? 0 : musicGroupStudentFee.getRemainNetworkClassTimes();
-                    musicGroupStudentFee.setRemainNetworkClassTimes(getRemainNetworkClassTimes + 1);
-                }*/
-//                musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId, musicGroupStudentFee.getNextPaymentDate(), musicGroupStudentFee));
-                musicGroupStudentFeeDao.update(musicGroupStudentFee);
-
-                //更新学生的缴费记录状态
-                userLastCalenderDetail.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
-                userLastCalenderDetail.setActualAmount(userLastCalenderDetail.getExpectAmount());
-                userLastCalenderDetail.setPayTime(date);
-                userLastCalenderDetail.setUpdateTime(date);
-                musicGroupPaymentCalenderDetailDao.update(userLastCalenderDetail);
-                //更新实际缴费人数
-                Integer actualNum = musicGroupPaymentCalender.getActualNum() == null ? 0 : musicGroupPaymentCalender.getActualNum();
-                musicGroupPaymentCalender.setActualNum(actualNum + 1);
-                musicGroupPaymentCalender.setUpdateTime(date);
-                musicGroupPaymentCalenderDao.update(musicGroupPaymentCalender);
-                return null;
             } else {
                 if (userCashAccount.getBalance().doubleValue() > 0) {
                     balance = userCashAccount.getBalance();
@@ -1814,12 +1738,16 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 
-        //分类费用 course,instrument,accessories,other
-        Map<String, BigDecimal> classFee = new HashMap<>();
-        classFee.put("course", amount);
-        classFee.put("instrument", BigDecimal.ZERO);
-        classFee.put("accessories", BigDecimal.ZERO);
-        classFee.put("other", BigDecimal.ZERO);
+        if (amount.compareTo(BigDecimal.ZERO) == 0) {
+            studentPaymentRouteOrderService.addRouteOrder(orderNo,organId, balance);
+            Map<String, String> notifyMap = new HashMap<>();
+            notifyMap.put("tradeState", "1");
+            notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
+            notifyMap.put("channelType", "");
+            notifyMap.put("orderNo", "");
+            studentPaymentOrderService.updateOrder(notifyMap);
+            return notifyMap;
+        }
 
         Map<String, Object> payMap = payService.getPayMap(
                 amount,
@@ -1829,17 +1757,16 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + studentPaymentOrder.getOrderNo(),
                 "续费",
                 "乐团续费",
-                musicGroup.getOrganId(),
+                organId,
                 "renew"
         );
 
         studentPaymentOrder.setActualAmount(amount);
-        studentPaymentOrder.setOrganId(musicGroup.getOrganId());
+        studentPaymentOrder.setOrganId(organId);
         studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
         studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
         studentPaymentOrder.setUpdateTime(date);
         studentPaymentOrderService.update(studentPaymentOrder);
-
         return payMap;
     }
 
@@ -1860,9 +1787,9 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         Map<Integer, String> push = new HashMap<>(1);
         push.put(userId, userId.toString());
         yimei.put(userId, studentRegistration.getParentsPhone());
-        if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
+        if (studentPaymentOrder.getStatus() == SUCCESS) {
             //当前乐团报名是否赠送乐团网管课
-            MusicGroupPaymentCalenderDetail calenderDetail = musicGroupPaymentCalenderDetailDao.findByOrderNo(studentPaymentOrder.getOrderNo());
+            MusicGroupPaymentCalenderDetail calenderDetail = musicGroupPaymentCalenderDetailDao.findByOrderId(studentPaymentOrder.getId());
             MusicGroupStudentFee musicGroupStudentFee = musicGroupPaymentCalenderService.updateCalender(calenderDetail.getId(),studentRegistration.getUserId());
 
             musicGroupStudentFee.setUpdateTime(date);
@@ -1885,7 +1812,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
             rechargeDetail.setComment("缴费前充值");
             rechargeDetail.setCreateTime(date);
-            rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
+            rechargeDetail.setStatus(SUCCESS);
             rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
             rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
             rechargeDetail.setUpdateTime(date);
@@ -1901,7 +1828,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             paymentDetail.setBalance(cashAccount.getBalance());
             paymentDetail.setComment("续费");
             paymentDetail.setCreateTime(date);
-            paymentDetail.setStatus(DealStatusEnum.SUCCESS);
+            paymentDetail.setStatus(SUCCESS);
             paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
             paymentDetail.setType(PlatformCashAccountDetailTypeEnum.PAY_FEE);
             paymentDetail.setUpdateTime(date);
@@ -1925,7 +1852,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
         MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
         if (musicGroup.getOwnershipType() != null && musicGroup.getOwnershipType() == CooperationOrgan.OwnershipType.OWN) {
-            if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
+            if (studentPaymentOrder.getStatus() == CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
                 String baseUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
                 String memo = baseUrl + "/#/renew?musicGroupId=" + musicGroupId;
                 //4?http://mstudev.dayaedu.com/#/renew?musicGroupId=" +musicGroupId

+ 3 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SporadicChargeInfoImpl.java

@@ -148,12 +148,12 @@ public class SporadicChargeInfoImpl extends BaseServiceImpl<Integer, SporadicCha
             return true;
         }
         if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
-            if (info.getMaxNum() != null && info.getPaidNum() > 0) {
-                info.setPaidNum(info.getPaidNum() - 1);
+            if (info.getMaxAmount() != null && info.getPaidAmount().compareTo(BigDecimal.ZERO) > 0) {
+                info.setPaidAmount(info.getPaidAmount().subtract(studentPaymentOrder.getActualAmount()));
                 info.setUpdateTime(new Date());
                 int update = sporadicChargeInfoDao.update(info);
                 if (update <= 0) {
-                    throw new BizException("人数更新失败,请重试");
+                    throw new BizException("已收金额更新失败,请重试");
                 }
             }
             if (info.getOrganId().equals(42) && info.getChargeType().equals(SporadicChargeTypeEnum.LEVEL)) {

+ 38 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -237,6 +237,44 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         callOrderCallBack(order);
     }
 
+    //Date date = new Date();
+    //        BigDecimal balance = BigDecimal.ZERO;
+    //        MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
+    //        if (registerPayDto.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
+    //            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
+    //            if (userCashAccount == null) {
+    //                throw new BizException("用户账户找不到");
+    //            }
+    //            if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
+    //                balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
+    //                amount = amount.subtract(balance);
+    //                studentPaymentOrder.setPaymentChannel("BALANCE");
+    //                studentPaymentOrder.setActualAmount(amount);
+    //                studentPaymentOrder.setBalancePaymentAmount(balance);
+    //                sysUserCashAccountService.updateBalance(userId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团报名");
+    //            }
+    //        }
+    //        studentPaymentOrder.setPaymentChannel("BALANCE");
+    //        studentPaymentOrder.setRemitFee(remitFee);
+    //        studentPaymentOrder.setCourseRemitFee(courseRemitFee);
+    //        studentPaymentOrder.setOrganId(musicGroup.getOrganId());
+    //        studentPaymentOrder.setRoutingOrganId(musicGroup.getOrganId());
+    //        studentPaymentOrder.setUpdateTime(date);
+    //        studentPaymentOrderService.update(studentPaymentOrder);
+    //        studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
+    //
+    //        if (amount.compareTo(BigDecimal.ZERO) == 0) {
+    //            //如果赠送网管课
+    //            studentPaymentRouteOrderService.addRouteOrder(orderNo, musicGroup.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;
+    //        }
+
     //调用相应业务回调接口
     private void callOrderCallBack(StudentPaymentOrder order) throws Exception {
         if (order.getType().equals(OrderTypeEnum.APPLY)) { //报名订单

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

@@ -366,7 +366,7 @@
 	<select id="findByCalenderIdAndUserId" resultMap="MusicGroupPaymentCalenderDetail">
 		SELECT * FROM music_group_payment_calender_detail WHERE music_group_payment_calender_id_ = #{calenderId} AND user_id_ = #{userId} LIMIT 1
 	</select>
-	<select id="findByOrderNo" resultMap="MusicGroupPaymentCalenderDetail">
-		SELECT * FROM music_group_payment_calender_detail WHERE payment_order_id_ = #{orderNo} LIMIT 1
+	<select id="findByOrderId" resultMap="MusicGroupPaymentCalenderDetail">
+		SELECT * FROM music_group_payment_calender_detail WHERE payment_order_id_ = #{orderId} LIMIT 1
 	</select>
 </mapper>

+ 14 - 3
mec-biz/src/main/resources/config/mybatis/SporadicChargeInfo.xml

@@ -20,7 +20,9 @@
         <result column="user_id_" property="userId"/>
         <result column="music_group_id_" property="musicGroupId"/>
         <result column="max_num_" property="maxNum"/>
-        <result column="paid_num_" property="paidNum"/>
+        <result column="max_amount_" property="maxAmount"/>
+        <result column="paid_amount_" property="paidAmount"/>
+        <result column="open_max_term_" property="openMaxTerm" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="version_" property="version"/>
     </resultMap>
 
@@ -43,10 +45,10 @@
             useGeneratedKeys="true" keyColumn="id" keyProperty="id">
         INSERT INTO sporadic_charge_info
         (title_, charge_type_, organ_id_, amount_, discount_amount_, detail_, create_time_, update_time_, operator_id_,
-         user_id_, music_group_id_, max_num_)
+         user_id_, music_group_id_, max_num_,max_amount_,open_max_term_)
         VALUES (#{title}, #{chargeType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                 #{organId}, #{amount}, #{discountAmount}, #{detail}, now(), now(), #{operatorId}, #{userId},
-                #{musicGroupId}, #{maxNum})
+                #{musicGroupId}, #{maxNum},#{maxAmount},#{openMaxTerm})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -92,6 +94,15 @@
             <if test="paidNum != null">
                 paid_num_ = #{paidNum},
             </if>
+            <if test="maxAmount != null">
+                max_amount_ = #{maxAmount},
+            </if>
+            <if test="paidAmount != null">
+                paid_amount_ = #{paidAmount},
+            </if>
+            <if test="openMaxTerm != null">
+                open_max_term_ = #{openMaxTerm},
+            </if>
             <if test="version != null">
                 version_ = version_+1,
             </if>

+ 3 - 2
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -32,6 +32,7 @@
         <result column="birthdate_" property="birthdate" />
         <result column="gender_" property="gender" />
         <result column="organ_name_" property="organName" />
+        <result column="organ_id_" property="organId" />
         <result column="school_name_" property="schoolName" />
         <result column="subject_name_" property="subjectName" />
         <result column="kit_group_purchase_type_" property="kitType" />
@@ -349,8 +350,8 @@
     </select>
 
     <select id="queryByUserIdAndMusicGroupId" resultMap="StudentRegistration">
-        SELECT sr.*,su.id_card_no_ FROM student_registration sr
-        LEFT JOIN sys_user su ON su.id_ =sr.user_id_
+        SELECT sr.*,su.id_card_no_,su.organ_id_ FROM student_registration sr
+        LEFT JOIN sys_user su ON su.id_ = sr.user_id_
         WHERE sr.music_group_id_ = #{musicGroupId} AND sr.user_id_ = #{userId} AND sr.music_group_status_ != 'QUIT' LIMIT 1
     </select>
 

+ 26 - 19
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupController.java

@@ -1,5 +1,6 @@
 package com.ym.mec.student.controller;
 
+import com.ym.mec.biz.dal.entity.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -30,16 +31,8 @@ import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDao;
 import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDetailDao;
 import com.ym.mec.biz.dal.dao.MusicGroupStudentFeeDao;
 import com.ym.mec.biz.dal.dto.RegisterPayDto;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.MusicGroup;
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender;
 import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender.PaymentCalenderStatusEnum;
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail;
-import com.ym.mec.biz.dal.entity.MusicGroupStudentFee;
 import com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus;
-import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.StudentRegistration;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.biz.dal.enums.MusicGroupStatusEnum;
@@ -220,30 +213,46 @@ public class MusicGroupController extends BaseController {
 
     @ApiOperation(value = "续费")
     @GetMapping("/renew")
-    @ApiImplicitParams({@ApiImplicitParam(name = "musicGroupId", value = "乐团id", required = true, dataType = "String"),
+    @ApiImplicitParams({@ApiImplicitParam(name = "calenderId", value = "缴费项目编号", required = true, dataType = "Long"),
             @ApiImplicitParam(name = "isUseBalancePayment", value = "是否使用余额付款", required = true, dataType = "Boolean")})
-    public HttpResponseResult renew(String musicGroupId, Boolean isUseBalancePayment, boolean isRepeatPay) throws Exception {
+    public HttpResponseResult renew(Long calenderId, Boolean isUseBalancePayment, boolean isRepeatPay) throws Exception {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         Integer userId = sysUser.getId();
 
         if (isUseBalancePayment == null) {
             isUseBalancePayment = false;
         }
+        MusicGroupPaymentCalender calender = musicGroupPaymentCalenderDao.get(calenderId);
         if (isRepeatPay == false) {
             // 判断是否存在支付中的记录
-            List<StudentPaymentOrder> list = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, musicGroupId, userId, DealStatusEnum.ING,
+            List<StudentPaymentOrder> list = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, calender.getMusicGroupId(), userId, DealStatusEnum.ING,
                     OrderTypeEnum.RENEW);
             if (list.size() > 0) {
                 return failed(HttpStatus.CONTINUE, "您有待支付的订单");
             }
         }
-        MusicGroupPaymentCalenderDetail userLastCalenderDetail = musicGroupPaymentCalenderDetailDao.getUserLastCalenderDetail(musicGroupId, userId);
-        if (userLastCalenderDetail == null) {
-            MusicGroupPaymentCalender lastCalender = musicGroupPaymentCalenderDao.getLastStartOne(musicGroupId);
-            String tips = (lastCalender != null && lastCalender.getStatus() == PaymentCalenderStatusEnum.OVER) ? "当前续费时间已截止,如有问题请联系指导老师" : "当前续费未开始,如有问题请联系指导老师";
-            throw new BizException(tips);
+        MusicGroupPaymentCalenderDetail calenderDetail = musicGroupPaymentCalenderDetailDao.findByCalenderIdAndUserId(calenderId,userId);
+        if (calenderDetail == null) {
+            throw new BizException("缴费项不存在该学员,请联系教务老师");
         }
-        return succeed(musicGroupService.renew(musicGroupId, userId, isUseBalancePayment));
+        if(calenderDetail.getPaymentStatus() == PaymentStatus.PAID_COMPLETED){
+            throw new BizException("当前缴费项已缴费");
+        }else if(calenderDetail.getPaymentStatus() == PaymentStatus.PROCESSING){
+            throw new BizException("当前缴费项存在待处理的订单,请稍候尝试");
+        }
+        //缴费项目已开启或者单独开启
+        Map renew;
+        if(calender.getStatus() == PaymentCalenderStatusEnum.OPEN || calenderDetail.getOpen() == 1){
+            renew = musicGroupService.renew(calenderId, userId, isUseBalancePayment);
+        }else if(calender.getStatus() == PaymentCalenderStatusEnum.OVER){
+            throw new BizException("当前缴费项时间已截止,如有问题请联系指导老师");
+        }else {
+            throw new BizException("当前缴费项未开始,如有问题请联系指导老师");
+        }
+        if (renew.containsKey("tradeState")) {
+            return failed(HttpStatus.CREATED, "恭喜您,缴费成功!");
+        }
+        return succeed(renew);
     }
 
     @ApiOperation(value = "退团")
@@ -270,7 +279,6 @@ public class MusicGroupController extends BaseController {
         if (ApplyOrder != null && waitPay == null) {
             return failed("您已支付成功,请勿重复支付");
         }
-
         //判断用户是否已存在订单
         ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId(), DealStatusEnum.ING);
         if (ApplyOrder != null) {
@@ -280,7 +288,6 @@ public class MusicGroupController extends BaseController {
         if (payMap.containsKey("tradeState")) {
             return failed(HttpStatus.CREATED, "恭喜您,报名成功!");
         }
-
         return succeed(payMap);
     }
 

+ 2 - 2
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupPaymentCalenderController.java

@@ -62,14 +62,14 @@ public class MusicGroupPaymentCalenderController extends BaseController {
             throw new BizException("缴费项不存在该学员,请联系教务老师");
         }
         if(calenderDetail.getPaymentStatus() == PaymentStatus.PAID_COMPLETED){
-            throw new BizException("当前缴费项已缴费");
+            throw new BizException("您已缴费,请勿重复提交");
         }else if(calenderDetail.getPaymentStatus() == PaymentStatus.PROCESSING){
             throw new BizException("当前缴费项存在待处理的订单,请稍候尝试");
         }
         if(calender.getStatus() == PaymentCalenderStatusEnum.OPEN){
             StudentRegistration studentRegistration = studentRegistrationService.queryByUserIdAndMusicGroupId(userId,musicGroupId);
             if (studentRegistration == null) {
-                return failed("乐团报名信息找不到");
+                return failed("乐团报名信息不存在");
             }
             List<MusicGroupPaymentCalenderCourseSettings> calenderCourseSettings = musicGroupPaymentCalenderCourseSettingsDao.queryCalenderCourseSettings(calenderId);
             ModelMap model = new ModelMap();

+ 1 - 1
mec-student/src/main/java/com/ym/mec/student/controller/SporadicChargeInfoController.java

@@ -72,7 +72,7 @@ public class SporadicChargeInfoController extends BaseController {
         }
         SporadicChargeInfo info = sporadicChargeInfoService.get(sporadicPayDto.getSporadicId());
 
-        if (info.getMaxNum() != null) {
+        if (info.getMaxAmount() != null) {
             String msg = "";
             for (int i = 1; i <= 100; i++) {
                 try {