Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

Joburgess 4 tahun lalu
induk
melakukan
eda233c453

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

@@ -72,7 +72,7 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
     List<OperatingReport> getSporadicMonthReport(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
 
     /**
-     * 维修单和商品销售
+     * 维修单
      *
      * @param startTime
      * @param endTime
@@ -81,7 +81,7 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
     List<OperatingReport> getRepairGoodsSellGroupMonthReport(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
 
     /**
-     * 维修单和商品销售,总收入
+     * 维修单,总收入
      *
      * @param startTime
      * @param endTime
@@ -91,6 +91,15 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
 
 
     /**
+     * 商品销售
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    List<OperatingReport> getGoodsSellGroupMonthReport(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
+
+
+    /**
      * 根据订单号删除
      *
      * @param orderId
@@ -174,4 +183,12 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
      * @return
      */
     List<SellOrder> getSellOrderByParentGoodsId(@Param("orderId") Long orderId, @Param("parentGoodsId") Integer parentGoodsId);
+
+    /**
+     * 获取退货的sellOrder
+     *
+     * @param orderId
+     * @return
+     */
+    List<SellOrder> getRefundSellOrder(@Param("orderId") Long orderId);
 }

+ 25 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SellOrder.java

@@ -167,6 +167,13 @@ public class SellOrder {
     @ApiModelProperty(value = "状态")
     private SellStatus status;
 
+
+    /**
+     * 退货时间
+     */
+    @ApiModelProperty(value="退货时间")
+    private Date refundTime;
+
     /**
     * 交易时间
     */
@@ -188,6 +195,8 @@ public class SellOrder {
     @ApiModelProperty(value = "收货状态,NO_RECEIVE 未确认,MANUAL_RECEIVE 手动确认,AUTO_RECEIVE 自动确认",required = true)
     private String receiveStatus;
 
+    private Boolean hasRoute = false;
+
     public String getReceiveStatus() {
         return receiveStatus;
     }
@@ -451,4 +460,20 @@ public class SellOrder {
     public void setParentGoodsId(Integer parentGoodsId) {
         this.parentGoodsId = parentGoodsId;
     }
+
+    public Date getRefundTime() {
+        return refundTime;
+    }
+
+    public void setRefundTime(Date refundTime) {
+        this.refundTime = refundTime;
+    }
+
+    public Boolean getHasRoute() {
+        return hasRoute;
+    }
+
+    public void setHasRoute(Boolean hasRoute) {
+        this.hasRoute = hasRoute;
+    }
 }

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

@@ -48,15 +48,25 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
      * 退货
      *
      * @param sellOrders
+     * @param reBackFee  是否退费
      * @return
      */
-    List<SellOrder> refund(List<SellOrder> sellOrders);
+    List<SellOrder> refund(List<SellOrder> sellOrders, Boolean reBackFee);
 
     /**
      * 根据订单id退货
      *
      * @param orderId
+     * @param reBackFee 是否退费
      * @return
      */
-    List<SellOrder> refundByOrderId(Long orderId);
+    List<SellOrder> refundByOrderId(Long orderId, Boolean reBackFee);
+
+    /**
+     * 获取订单退货的sellOrder
+     * @param orderId
+     * @return
+     */
+    List<SellOrder> getRefundSellOrder(Long orderId);
+
 }

+ 7 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OperatingReportServiceImpl.java

@@ -121,17 +121,19 @@ public class OperatingReportServiceImpl extends BaseServiceImpl<Integer, Operati
         reports.addAll(sellOrderDao.getOutOrderMonthReport(startTime, endTime));
         //外部添加订单销售总收入
         reports.addAll(sellOrderDao.getOutOrderIncome(startTime, endTime));
-        //3.4、乐器维修、商品销售
+        //3.4、乐器维修
         reports.addAll(sellOrderDao.getRepairGoodsSellGroupMonthReport(startTime, endTime));
         reports.addAll(sellOrderDao.getRepairGoodsSellGroupIncome(startTime, endTime));
-        //3.5、零星支付充值
+        //3.5、商品销售
+        reports.addAll(sellOrderDao.getGoodsSellGroupMonthReport(startTime, endTime));
+        //3.6、零星支付充值
         reports.addAll(sellOrderDao.getRechargeMonthReport(startTime, endTime));
-        //3.6、零星收费(不是充值部分的)
+        //3.7、零星收费(不是充值部分的)
         reports.addAll(sellOrderDao.getSporadicMonthReport(startTime, endTime));
-        //3.7 声部更换的收入
+        //3.8 声部更换的收入
         reports.addAll(sellOrderDao.getSubjectChangeMonthReport(startTime, endTime));
         reports.addAll(sellOrderDao.getSubjectChangeGroupIncome(startTime, endTime));
-        //3.8 退货部分的统计
+        //3.9 退货部分的统计
         reports.addAll(sellOrderDao.getRefundIncome(startTime, endTime));
 
         updateFee(organOperating, cooperationOperating, reports);

+ 26 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -110,6 +110,9 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 if (!goodsId.equals(sellOrder.getParentGoodsId()) && !goodsId.equals(sellOrder.getGoodsId())) {
                     continue;
                 }
+                if (sellOrder.getHasRoute()) {
+                    continue;
+                }
                 BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
                 BigDecimal sellOrderBalance = BigDecimal.ZERO;
                 if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
@@ -120,7 +123,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 complementGoodsNum = complementGoodsNum - sellOrder.getNum();
                 if (complementGoodsNum <= 0) {
                     sellOrderActualAmount = goodsPrice.subtract(hasRouteSellOrderActualAmount);
-                    sellOrderBalance = goodsBalance.subtract(hasRouteSellOrderActualAmount);
+                    sellOrderBalance = goodsBalance.subtract(hasRouteSellOrderBalance);
                 }
                 hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
                 hasRouteSellOrderBalance = hasRouteSellOrderBalance.add(sellOrderBalance);
@@ -146,6 +149,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 } else {
                     sellOrder.setType(SellTypeEnum.OTHER);
                 }
+                sellOrder.setHasRoute(true);
             }
         }
         sellOrderDao.batchInsert(sellOrderList);
@@ -217,13 +221,16 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                     if (!goods.getId().equals(sellOrder.getParentGoodsId()) && !goods.getId().equals(sellOrder.getGoodsId())) {
                         continue;
                     }
+                    if (sellOrder.getHasRoute()) {
+                        continue;
+                    }
                     BigDecimal sellOrderExpectAmount = BigDecimal.ZERO;
                     BigDecimal sellOrderBalance = BigDecimal.ZERO;
                     if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
                         sellOrderExpectAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(expectAmount).divide(complementPrice, 2, BigDecimal.ROUND_HALF_UP);
                         sellOrderBalance = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(balance).divide(complementPrice, 2, BigDecimal.ROUND_HALF_UP);
                     }
-                     complementGoodsNum = complementGoodsNum - sellOrder.getNum();
+                    complementGoodsNum = complementGoodsNum - sellOrder.getNum();
                     if (complementGoodsNum <= 0) {
                         sellOrderExpectAmount = expectAmount.subtract(hasRouteSellOrderExpectAmount);
                         sellOrderBalance = balance.subtract(hasRouteSellOrderBalance);
@@ -265,6 +272,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                         sellOrder.setBalanceAmount(BigDecimal.ZERO);
                         sellOrder.setExpectAmount(BigDecimal.ZERO);
                     }
+                    sellOrder.setHasRoute(true);
                 }
 
                 sellOrders.addAll(sellOrderList);
@@ -289,16 +297,18 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public List<SellOrder> refund(List<SellOrder> sellOrders) {
+    public List<SellOrder> refund(List<SellOrder> sellOrders, Boolean reBackFee) {
+        Date nowDate = new Date();
         for (SellOrder sellOrder : sellOrders) {
             //1、更改销售列表状态
             sellOrder.setStatus(SellStatus.REFUND);
-            sellOrder.setUpdateTime(new Date());
+            sellOrder.setUpdateTime(nowDate);
+            sellOrder.setRefundTime(nowDate);
             sellOrderDao.update(sellOrder);
 
             //2、金额退到余额
-            if (sellOrder.getExpectAmount().compareTo(BigDecimal.ZERO) > 0) {
-                sysUserCashAccountService.updateBalance(sellOrder.getUserId(), sellOrder.getActualAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "订单:" + sellOrder.getOrderId() + " 商品id:" + sellOrder.getGoodsId() + "退货");
+            if (reBackFee && sellOrder.getExpectAmount().compareTo(BigDecimal.ZERO) > 0) {
+                sysUserCashAccountService.updateBalance(sellOrder.getUserId(), sellOrder.getExpectAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "订单:" + sellOrder.getOrderId() + " 商品id:" + sellOrder.getGoodsId() + "退货");
             }
         }
         //3、退货
@@ -309,9 +319,17 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     }
 
     @Override
-    public List<SellOrder> refundByOrderId(Long orderId) {
+    public List<SellOrder> refundByOrderId(Long orderId, Boolean reBackFee) {
         List<SellOrder> sellOrders = sellOrderDao.getSellOrderByParentGoodsId(orderId, null);
-        return refund(sellOrders);
+        if (sellOrders.size() <= 0) {
+            return sellOrders;
+        }
+        return refund(sellOrders, reBackFee);
+    }
+
+    @Override
+    public List<SellOrder> getRefundSellOrder(Long orderId) {
+        return sellOrderDao.getRefundSellOrder(orderId);
     }
 
 }

+ 61 - 60
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -109,11 +109,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception {
         //关闭老订单
-        if(StringUtils.isNotEmpty(studentGoodsSell.getOrderNo())){
+        if (StringUtils.isNotEmpty(studentGoodsSell.getOrderNo())) {
             StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(studentGoodsSell.getOrderNo());
-            if(orderByOrderNo.getBalancePaymentAmount() != null){
+            if (orderByOrderNo.getBalancePaymentAmount() != null) {
                 studentGoodsSell.setIsUseBalancePayment(true);
-            }else {
+            } else {
                 studentGoodsSell.setIsUseBalancePayment(false);
             }
             orderByOrderNo.setStatus(DealStatusEnum.CLOSE);
@@ -122,14 +122,14 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 sysUserCashAccountService.updateBalance(orderByOrderNo.getUserId(), orderByOrderNo.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
             }
             StudentGoodsSell byOrderNo = studentGoodsSellDao.findByOrderNo(studentGoodsSell.getOrderNo());
-            if(byOrderNo != null){
+            if (byOrderNo != null) {
                 studentGoodsSell = byOrderNo;
-                studentGoodsSell.setGoodsSellDtos(JSON.parseArray(byOrderNo.getGoodsJson(),GoodsSellDto.class));
+                studentGoodsSell.setGoodsSellDtos(JSON.parseArray(byOrderNo.getGoodsJson(), GoodsSellDto.class));
             }
         }
         Integer studentId = studentGoodsSell.getUserId();
         List<GoodsSellDto> goodsSellDtos = studentGoodsSell.getGoodsSellDtos();
-        if(goodsSellDtos == null || goodsSellDtos.size() == 0){
+        if (goodsSellDtos == null || goodsSellDtos.size() == 0) {
             throw new BizException("请选择需要购买的商品");
         }
         if (studentId == null) {
@@ -139,21 +139,21 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentDao.lockUser(studentId);
         SysUser student = sysUserFeignService.queryUserById(studentId);
         //如果教务老师为空,代表学员自己创建的订单
-        if(studentGoodsSell.getTeacherId() == null){
+        if (studentGoodsSell.getTeacherId() == null) {
             //获取学生关联的所有教务老师列表
             List<Integer> stuEducation = studentRepairDao.countStuEducation(studentId);
-            if (stuEducation != null && stuEducation.size() == 1){
+            if (stuEducation != null && stuEducation.size() == 1) {
                 //获取学员乐团关联的教务
                 MusicGroup musicGroup = musicGroupDao.getStuMusic(studentId);
                 studentGoodsSell.setTeacherId(stuEducation.get(0));
-                if(musicGroup != null){
+                if (musicGroup != null) {
                     studentGoodsSell.setCooperationOrganId(musicGroup.getCooperationOrganId());
                 }
             }
-        }else if(studentGoodsSell.getCooperationOrganId() == null){
+        } else if (studentGoodsSell.getCooperationOrganId() == null) {
             //获取教务老师,学员关联的乐团
-            MusicGroup musicGroup = musicGroupDao.getStuEduMusic(studentId,studentGoodsSell.getTeacherId());
-            if(musicGroup != null){
+            MusicGroup musicGroup = musicGroupDao.getStuEduMusic(studentId, studentGoodsSell.getTeacherId());
+            if (musicGroup != null) {
                 studentGoodsSell.setCooperationOrganId(musicGroup.getCooperationOrganId());
             }
         }
@@ -162,7 +162,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         Map<Integer, BigDecimal> map = getMap("goods", "id_", "discount_price_", goodsIds, Integer.class, BigDecimal.class);
         for (GoodsSellDto goodsSellDto : goodsSellDtos) {
             goodsSellDto.setGoodsType(integerStringMap.get(goodsSellDto.getGoodsId()));
-            if(StringUtils.isNotEmpty(goodsSellDto.getComplementGoodsIdList())){
+            if (StringUtils.isNotEmpty(goodsSellDto.getComplementGoodsIdList())) {
                 goodsSellDto.setGoodsSellDtos(goodsService.queryGoodsSellDtos(goodsSellDto.getComplementGoodsIdList()));
             }
             goodsSellDto.setGoodsPrice(map.get(goodsSellDto.getGoodsId()));
@@ -175,7 +175,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             amount = amount.add(goodsSellDto.getTotalGoodsPrice());
         }
         amount = amount.subtract(studentGoodsSell.getMarketAmount());
-        if(amount.signum() < 0){
+        if (amount.signum() < 0) {
             throw new BizException("操作失败:订单金额异常");
         }
         studentGoodsSell.setOrganId(student.getOrganId());
@@ -257,13 +257,13 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         StudentGoodsSell studentGoodsSell = studentGoodsSellDao.get(goodsSellId);
         Integer studentId = studentGoodsSell.getUserId();
         studentDao.lockUser(studentId);
-        List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(studentGoodsSell.getGoodsJson(),GoodsSellDto.class);
+        List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(studentGoodsSell.getGoodsJson(), GoodsSellDto.class);
         List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
         Map<Integer, String> integerStringMap = getMap("goods", "id_", "type_", goodsIds, Integer.class, String.class);
         Map<Integer, BigDecimal> map = getMap("goods", "id_", "discount_price_", goodsIds, Integer.class, BigDecimal.class);
         for (GoodsSellDto goodsSellDto : goodsSellDtos) {
             goodsSellDto.setGoodsType(integerStringMap.get(goodsSellDto.getGoodsId()));
-            if(StringUtils.isNotEmpty(goodsSellDto.getComplementGoodsIdList())){
+            if (StringUtils.isNotEmpty(goodsSellDto.getComplementGoodsIdList())) {
                 goodsSellDto.setGoodsSellDtos(goodsService.queryGoodsSellDtos(goodsSellDto.getComplementGoodsIdList()));
             }
             goodsSellDto.setGoodsPrice(map.get(goodsSellDto.getGoodsId()));
@@ -276,7 +276,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             amount = amount.add(goodsSellDto.getTotalGoodsPrice());
         }
         amount = amount.subtract(studentGoodsSell.getMarketAmount());
-        if(amount.signum() < 0){
+        if (amount.signum() < 0) {
             throw new BizException("操作失败:订单金额异常");
         }
         String orderNo1 = studentGoodsSell.getOrderNo();
@@ -284,16 +284,16 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 
         studentGoodsSell.setOrderNo(orderNo);
         StudentPaymentOrder studentPaymentOrder = null;
-        if(StringUtils.isNotEmpty(orderNo1)){
+        if (StringUtils.isNotEmpty(orderNo1)) {
             studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(orderNo1);
-            if(studentPaymentOrder != null){
-                if(studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS){
+            if (studentPaymentOrder != null) {
+                if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
                     throw new BizException("该订单已支付");
                 }
                 //关闭老订单
-                if(studentPaymentOrder.getBalancePaymentAmount() != null){
+                if (studentPaymentOrder.getBalancePaymentAmount() != null) {
                     studentGoodsSell.setIsUseBalancePayment(true);
-                }else {
+                } else {
                     studentGoodsSell.setIsUseBalancePayment(false);
                 }
                 studentPaymentOrder.setStatus(DealStatusEnum.CLOSE);
@@ -726,7 +726,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         PageInfo<BasicUserDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
         Map<String, Object> params = new HashMap<>();
         MapUtil.populateMap(params, queryInfo);
-        params.put("teacherId",sysUser.getId());
+        params.put("teacherId", sysUser.getId());
 
         List<BasicUserDto> dataList = null;
         int count = studentRepairDao.countEduStudents(params);
@@ -742,7 +742,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         return pageInfo;
     }
 
-    public void saveSellOrder(String orderNo){
+    public void saveSellOrder(String orderNo) {
         StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(orderNo);
         StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(orderNo);
         String goodsJson = studentGoodsSell.getGoodsJson();
@@ -750,13 +750,13 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         //用户选择的商品
         Map<Integer, List<GoodsSellDto>> collect = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
         List<Integer> goodsIds = new ArrayList<>();
-        goodsSellDtos.forEach(e->{
+        goodsSellDtos.forEach(e -> {
             for (int i = 0; i < e.getGoodsNum(); i++) {
                 goodsIds.add(e.getGoodsId());
             }
         });
         AccountType accountType = AccountType.INTERNAL;
-        if(StringUtils.isNotEmpty(orderByOrderNo.getPaymentChannel())){
+        if (StringUtils.isNotEmpty(orderByOrderNo.getPaymentChannel())) {
             accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(orderByOrderNo.getPaymentChannel()), orderByOrderNo.getMerNos());
         }
         //实际扣减的库存商品
@@ -771,11 +771,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         //包含减免余额的总金额
         BigDecimal totalAmount = goodsSellDtos.stream().map(e -> e.getTotalGoodsPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
         //组合商品减免金额
-        Map<Integer,BigDecimal> parentGoodsCutTotalPriceMap = new HashMap<>();
+        Map<Integer, BigDecimal> parentGoodsCutTotalPriceMap = new HashMap<>();
         //组合商品附加金额
-        Map<Integer,BigDecimal> parentGoodsAddTotalPriceMap = new HashMap<>();
+        Map<Integer, BigDecimal> parentGoodsAddTotalPriceMap = new HashMap<>();
         //组合商品实际总价
-        Map<Integer,BigDecimal> parentGoodsTotalPriceMap = new HashMap<>();
+        Map<Integer, BigDecimal> parentGoodsTotalPriceMap = new HashMap<>();
         //应付总额
         BigDecimal totalActual = totalAmount.subtract(marketAmount);
         //可用应付
@@ -804,16 +804,17 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             for (GoodsSellDto sellDto : goodsSellDto.getGoodsSellDtos()) {
                 totalGoodsPrice = totalGoodsPrice.add(sellDto.getTotalGoodsPrice());
             }
-            parentGoodsTotalPriceMap.put(sellOrder.getParentGoodsId(),totalGoodsPrice);
+            parentGoodsTotalPriceMap.put(sellOrder.getParentGoodsId(), totalGoodsPrice);
             //如果组合价大于预计总价
-            if (parentTotalGoodsPrice.compareTo(totalGoodsPrice) == 1){
-                parentGoodsAddTotalPriceMap.put(sellOrder.getParentGoodsId(),parentTotalGoodsPrice.subtract(totalGoodsPrice));
-            }else if(parentTotalGoodsPrice.compareTo(totalGoodsPrice) == -1){//小于
-                parentGoodsCutTotalPriceMap.put(sellOrder.getParentGoodsId(),totalGoodsPrice.subtract(parentTotalGoodsPrice));
+            if (parentTotalGoodsPrice.compareTo(totalGoodsPrice) == 1) {
+                parentGoodsAddTotalPriceMap.put(sellOrder.getParentGoodsId(), parentTotalGoodsPrice.subtract(totalGoodsPrice));
+            } else if (parentTotalGoodsPrice.compareTo(totalGoodsPrice) == -1) {//小于
+                parentGoodsCutTotalPriceMap.put(sellOrder.getParentGoodsId(), totalGoodsPrice.subtract(parentTotalGoodsPrice));
             }
         }
         //分配组合商品的中单个商品的价格
-        noFreeAmount:for (Integer parentGoodsId : orderListMap.keySet()) {
+        noFreeAmount:
+        for (Integer parentGoodsId : orderListMap.keySet()) {
 
             BigDecimal addTotalPrice = parentGoodsAddTotalPriceMap.get(parentGoodsId);
             usableParentGoodsAddTotalPrice = addTotalPrice;
@@ -834,29 +835,29 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 //获取比例
                 BigDecimal ratioAmount = sellDto.getTotalGoodsPrice().divide(divide, 6, BigDecimal.ROUND_HALF_UP);
 
-                if(addTotalPrice != null && addTotalPrice.doubleValue() > 0l){
+                if (addTotalPrice != null && addTotalPrice.doubleValue() > 0l) {
                     //如果是最后一件商品
-                    if(i == integers.size() - 1){
+                    if (i == integers.size() - 1) {
                         sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(usableParentGoodsAddTotalPrice));
-                    }else {
+                    } else {
                         //获取分配的附加
-                        BigDecimal multiply = ratioAmount.multiply(addTotalPrice).setScale(2,BigDecimal.ROUND_HALF_UP);
+                        BigDecimal multiply = ratioAmount.multiply(addTotalPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
                         sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(multiply));
                         usableParentGoodsAddTotalPrice = usableParentGoodsAddTotalPrice.subtract(multiply);
                     }
                     sellDto.setGoodsPrice(sellDto.getTotalGoodsPrice());
-                }else if(cutTotalPrice != null && cutTotalPrice.doubleValue() > 0l){
+                } else if (cutTotalPrice != null && cutTotalPrice.doubleValue() > 0l) {
                     //如果是最后一件商品
-                    if(i == integers.size() - 1){
+                    if (i == integers.size() - 1) {
                         sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(usableParentGoodsCutTotalPrice));
-                    }else {
+                    } else {
                         //获取分配的组合减免金额
-                        BigDecimal multiply = ratioAmount.multiply(cutTotalPrice).setScale(2,BigDecimal.ROUND_HALF_UP);
+                        BigDecimal multiply = ratioAmount.multiply(cutTotalPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
                         sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(multiply));
                         usableParentGoodsCutTotalPrice = usableParentGoodsCutTotalPrice.subtract(multiply);
                     }
                     sellDto.setGoodsPrice(sellDto.getTotalGoodsPrice());
-                }else {
+                } else {
                     continue noFreeAmount;
                 }
             }
@@ -864,14 +865,14 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         for (int i = 0; i < sellOrderList.size(); i++) {
             SellOrder sellOrder = sellOrderList.get(i);
             Integer e = null;
-            if(sellOrder.getParentGoodsId() != null){
+            if (sellOrder.getParentGoodsId() != null) {
                 e = sellOrder.getParentGoodsId();
-            }else {
+            } else {
                 e = sellOrder.getGoodsId();
             }
             GoodsSellDto goodsSellDto = collect.get(e).get(0);
             List<GoodsSellDto> sellDtos = goodsSellDto.getGoodsSellDtos();
-            if(sellDtos != null && sellDtos.size() > 0){
+            if (sellDtos != null && sellDtos.size() > 0) {
                 Map<Integer, List<GoodsSellDto>> map = sellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
                 goodsSellDto = map.get(sellOrder.getGoodsId()).get(0);
             }
@@ -888,32 +889,32 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             //获取比例
             BigDecimal ratioAmount = multiply2.divide(totalAmount, 6, BigDecimal.ROUND_HALF_UP);
             //如果有减免金额
-            if(marketAmount.doubleValue() > 0l){
+            if (marketAmount.doubleValue() > 0l) {
                 //如果是最后一件商品
-                if(i == sellOrderList.size() - 1){
+                if (i == sellOrderList.size() - 1) {
                     goodsSellDto.setTotalGoodsPrice(multiply2.subtract(usableMarketAmount));
-                }else {
+                } else {
                     //获取分配的减免金额
-                    BigDecimal multiply = ratioAmount.multiply(marketAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
+                    BigDecimal multiply = ratioAmount.multiply(marketAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
                     goodsSellDto.setTotalGoodsPrice(multiply2.subtract(multiply));
                     usableMarketAmount = usableMarketAmount.subtract(multiply);
                 }
             }
 
             //如果没有使用余额,那么实际金额和预计金额一致
-            if(balancePaymentAmount.doubleValue() == 0l){
+            if (balancePaymentAmount.doubleValue() == 0l) {
                 sellOrder.setActualAmount(goodsSellDto.getTotalGoodsPrice());
                 sellOrder.setBalanceAmount(BigDecimal.ZERO);
-            }else {
+            } else {
                 //如果是最后一件商品
-                if(i == sellOrderList.size() - 1){
+                if (i == sellOrderList.size() - 1) {
                     sellOrder.setActualAmount(usableAmount);
                     sellOrder.setBalanceAmount(usableBalance);
-                }else {
+                } else {
                     //获取分配的余额
-                    BigDecimal multiply = ratioAmount.multiply(balancePaymentAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
+                    BigDecimal multiply = ratioAmount.multiply(balancePaymentAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
                     //分配的实际支付
-                    BigDecimal multiply1 = ratioAmount.multiply(realityAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
+                    BigDecimal multiply1 = ratioAmount.multiply(realityAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
                     sellOrder.setActualAmount(multiply1);
                     sellOrder.setBalanceAmount(multiply);
                     usableAmount = usableAmount.subtract(multiply1);
@@ -923,9 +924,9 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             }
             sellOrder.setExpectAmount(sellOrder.getActualAmount().add(sellOrder.getBalanceAmount()));
 //            sellOrder.setSellCost2(JSONObject.toJSONString(costMap));
-            if(SellTypeEnum.ACCESSORIES.getCode().equals(goodsSellDto.getGoodsType())||SellTypeEnum.INSTRUMENT.getCode().equals(goodsSellDto.getGoodsType())){
+            if (SellTypeEnum.ACCESSORIES.getCode().equals(goodsSellDto.getGoodsType()) || SellTypeEnum.INSTRUMENT.getCode().equals(goodsSellDto.getGoodsType())) {
                 sellOrder.setType(SellTypeEnum.valueOf(goodsSellDto.getGoodsType()));
-            }else{
+            } else {
                 sellOrder.setType(SellTypeEnum.OTHER);
             }
             sellOrder.setGoodsId(sellOrder.getGoodsId());
@@ -937,7 +938,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             sellOrder.setEduTeacherId(studentGoodsSell.getTeacherId());
             sellOrder.setCooperationOrganId(studentGoodsSell.getCooperationOrganId());
         }
-        if(sellOrderList.size() > 0){
+        if (sellOrderList.size() > 0) {
             sellOrderService.batchInsert(sellOrderList);
         }
     }

+ 56 - 14
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -289,7 +289,7 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             List<Integer> goodsIdList = Arrays.stream(goodsIds.split(",")).map(Integer::parseInt).collect(Collectors.toList());
 
             //退原订单商品
-            sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue());
+            sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue(), false);
             //添加新订单
             this.addSellOrder(studentPaymentOrder.getId(), subjectChange.getMusicGroupId(), goodsIdList, BigDecimal.ZERO, BigDecimal.ZERO);
         }
@@ -316,25 +316,39 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
         SubjectChange subjectChange = new SubjectChange();
         SubjectChange studentLastChange = subjectChangeDao.getStudentLastChange(studentId, musicGroupId);
         if (studentLastChange != null) {
+            Set<Integer> refundSellOrderGoodsIds = getRefundGoodsId(subjectChange.getOrderId().longValue());
             subjectChange.setStudentId(studentLastChange.getStudentId());
             subjectChange.setOrderId(studentLastChange.getOrderId());
             subjectChange.setCooperationOrganId(studentLastChange.getCooperationOrganId());
             subjectChange.setMusicGroupId(studentLastChange.getMusicGroupId());
             subjectChange.setOriginalCourseFee(studentLastChange.getChangeCourseFee());
             subjectChange.setKitGroupPurchaseType(studentLastChange.getKitGroupPurchaseType());
-            subjectChange.setOriginalCost(studentLastChange.getChangeCost());
 
-            if (studentLastChange.getChangeMusical() != null) {
+            BigDecimal originalCost = BigDecimal.ZERO;
+            if (studentLastChange.getChangeMusical() != null && !refundSellOrderGoodsIds.contains(studentLastChange.getChangeMusical())) {
                 subjectChange.setOriginalMusical(studentLastChange.getChangeMusical());
                 subjectChange.setOriginalMusicalGoods(goodsDao.get(studentLastChange.getChangeMusical()));
                 subjectChange.setOriginalMusicalPrice(studentLastChange.getChangeMusicalPrice());
             }
 
             if (studentLastChange.getChangeAccessories() != null) {
-                subjectChange.setOriginalAccessories(studentLastChange.getChangeAccessories());
-                subjectChange.setOriginalAccessoriesGoods(goodsDao.findGoodsByIds(studentLastChange.getChangeAccessories()));
-                subjectChange.setOriginalAccessoriesPrice(studentLastChange.getChangeAccessoriesPrice());
+                String[] goodsIdArr = studentLastChange.getChangeAccessories().split(",");
+                String accessoriesId = "";
+                for (String goodsId : goodsIdArr) {
+                    if (refundSellOrderGoodsIds.contains(Integer.parseInt(goodsId))) {
+                        continue;
+                    }
+                    accessoriesId += StringUtils.isBlank(accessoriesId) ? goodsId : "," + goodsId;
+                }
+                if (StringUtils.isNotBlank(accessoriesId)) {
+                    subjectChange.setOriginalAccessories(accessoriesId);
+                    List<Goods> accessoriesGoods = goodsDao.findGoodsByIds(accessoriesId);
+                    subjectChange.setOriginalAccessoriesGoods(accessoriesGoods);
+                    BigDecimal price = accessoriesGoods.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+                    subjectChange.setOriginalAccessoriesPrice(price);
+                }
             }
+            subjectChange.setOriginalCost(originalCost);
             return subjectChange;
         }
         //2.1不存在历史的更换
@@ -342,6 +356,9 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
         if (details.size() <= 0) {
             return null;
         }
+
+        Set<Integer> refundSellOrderGoodsIds = getRefundGoodsId(details.get(0).getPaymentOrderId());
+
         MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
         subjectChange.setStudentId(studentId);
         subjectChange.setOrganId(musicGroup.getOrganId());
@@ -355,10 +372,12 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 subjectChange.setOriginalCourseFee(detail.getPrice());
             } else if (detail.getType().equals(OrderDetailTypeEnum.MUSICAL)) {
                 subjectChange.setKitGroupPurchaseType(detail.getKitGroupPurchaseType());
-                int goodsId = Integer.parseInt(detail.getGoodsIdList());
-                subjectChange.setOriginalMusical(goodsId);
-                subjectChange.setOriginalMusicalGoods(goodsDao.get(goodsId));
-                subjectChange.setOriginalMusicalPrice(detail.getPrice());
+                Integer goodsId = Integer.parseInt(detail.getGoodsIdList());
+                if (!refundSellOrderGoodsIds.contains(goodsId)) {
+                    subjectChange.setOriginalMusical(goodsId);
+                    subjectChange.setOriginalMusicalGoods(goodsDao.get(goodsId));
+                    subjectChange.setOriginalMusicalPrice(detail.getPrice());
+                }
             } else {
                 if (StringUtils.isNotBlank(detail.getGoodsIdList())) {
                     accessoriesPrice = accessoriesPrice.add(detail.getPrice());
@@ -367,9 +386,20 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             }
         }
         if (StringUtils.isNotBlank(accessoriesIds)) {
-            subjectChange.setOriginalAccessories(accessoriesIds);
-            subjectChange.setOriginalAccessoriesGoods(goodsDao.findGoodsByIds(accessoriesIds));
-            subjectChange.setOriginalAccessoriesPrice(accessoriesPrice);
+            String[] goodsIdArr = accessoriesIds.split(",");
+            String accessoriesId = "";
+            for (String goodsId : goodsIdArr) {
+                if (refundSellOrderGoodsIds.contains(Integer.parseInt(goodsId))) {
+                    continue;
+                }
+                accessoriesId += StringUtils.isBlank(accessoriesId) ? goodsId : "," + goodsId;
+            }
+
+            subjectChange.setOriginalAccessories(accessoriesId);
+            List<Goods> accessoriesGoods = goodsDao.findGoodsByIds(accessoriesId);
+            subjectChange.setOriginalAccessoriesGoods(accessoriesGoods);
+            BigDecimal price = accessoriesGoods.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+            subjectChange.setOriginalAccessoriesPrice(price);
         }
         Long orderId = details.get(0).getPaymentOrderId();
         //2.2 计算销售成本
@@ -378,6 +408,14 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
         return subjectChange;
     }
 
+    private Set<Integer> getRefundGoodsId(Long orderId) {
+        List<SellOrder> refundSellOrders = sellOrderService.getRefundSellOrder(orderId);
+        Set<Integer> refundSellOrderGoodsIds = refundSellOrders.stream().filter(e -> e.getParentGoodsId() == null).map(SellOrder::getGoodsId).collect(Collectors.toSet());
+        Set<Integer> refundSellOrderParentGoodsId = refundSellOrders.stream().filter(e -> e.getParentGoodsId() != null).map(SellOrder::getParentGoodsId).collect(Collectors.toSet());
+        refundSellOrderGoodsIds.addAll(refundSellOrderParentGoodsId);
+        return refundSellOrderGoodsIds;
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
@@ -440,7 +478,7 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             if (StringUtils.isNotBlank(goodsIds)) {
                 List<Integer> goodsIdList = Arrays.stream(goodsIds.split(",")).map(Integer::parseInt).collect(Collectors.toList());
                 //退原订单商品
-                sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue());
+                sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue(), false);
                 //添加新订单
                 this.addSellOrder(studentPaymentOrder.getId(), subjectChange.getMusicGroupId(), goodsIdList, studentPaymentOrder.getExpectAmount(), studentPaymentOrder.getBalancePaymentAmount());
             }
@@ -618,6 +656,9 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 if (!goodsId.equals(sellOrder.getParentGoodsId()) && !goodsId.equals(sellOrder.getGoodsId())) {
                     continue;
                 }
+                if (sellOrder.getHasRoute()) {
+                    continue;
+                }
                 BigDecimal sellOrderExpectAmount = BigDecimal.ZERO;
                 BigDecimal sellOrderBalance = BigDecimal.ZERO;
                 if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
@@ -655,6 +696,7 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 } else {
                     sellOrder.setType(SellTypeEnum.OTHER);
                 }
+                sellOrder.setHasRoute(true);
             }
         }
         sellOrderDao.batchInsert(sellOrderList);

+ 42 - 10
mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml

@@ -32,6 +32,7 @@
         <result column="mer_no_" property="merNo"/>
         <result column="batch_no_" property="batchNo"/>
         <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+        <result column="refund_time_" property="refundTime"/>
         <result column="sell_time_" property="sellTime"/>
         <result column="create_ime_" property="createIme"/>
         <result column="update_time_" property="updateTime"/>
@@ -45,7 +46,8 @@
         id_, edu_teacher_id_,organ_id_, cooperation_organ_id_, trans_no_,order_id_, order_no_, expect_amount_,
         actual_amount_,balance_amount_, sell_cost_, sell_cost2_, type_,parent_goods_id_, goods_id_,goods_name_, num_,
         user_id_,
-        payment_channel_,mer_no_,batch_no_,stock_type_,account_type_,status_, sell_time_, create_ime_, update_time_
+        payment_channel_,mer_no_,batch_no_,stock_type_,account_type_,status_, refund_time_,sell_time_, create_ime_,
+        update_time_
     </sql>
     <select id="get" parameterType="java.lang.Integer" resultMap="SellOrder">
         <!--@mbg.generated-->
@@ -65,13 +67,13 @@
         insert into sell_order (edu_teacher_id_,organ_id_, cooperation_organ_id_, trans_no_,order_id_, order_no_,
         expect_amount_,actual_amount_,balance_amount_, type_,parent_goods_id_, goods_id_,goods_name_, sell_cost_,
         sell_cost2_, num_, user_id_, payment_channel_,
-        mer_no_,batch_no_,stock_type_,account_type_, sell_time_, create_ime_, update_time_)
+        mer_no_,batch_no_,stock_type_,account_type_, refund_time_,sell_time_, create_ime_, update_time_)
         values (#{eduTeacherId},#{organId}, #{cooperationOrganId}, #{transNo}, #{orderNo},#{orderId}, #{expectAmount},
         #{actualAmount}, #{balanceAmount}, #{type},#{parentGoodsId}, #{goodsId}, #{goodsName}, #{sellCost},
         #{sellCost2}, #{num}, #{userId},
         #{paymentChannel}, #{merNo},#{batchNo},
         #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{accountType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-        #{sellTime}, #{createIme}, #{updateTime})
+        #{refundTime},#{sellTime}, #{createIme}, #{updateTime})
     </insert>
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.SellOrder">
         <!--@mbg.generated-->
@@ -146,6 +148,9 @@
             <if test="status != null">
                 status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
             </if>
+            <if test="refundTime != null">
+                refund_time_ = #{refundTime},
+            </if>
             <if test="sellTime != null">
                 sell_time_ = #{sellTime},
             </if>
@@ -232,6 +237,9 @@
                 <if test="sellOrder.status != null">
                     status_ = #{sellOrder.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                 </if>
+                <if test="sellOrder.refundTime != null">
+                    refund_time_ = #{sellOrder.refundTime},
+                </if>
                 <if test="sellOrder.sellTime != null">
                     sell_time_ = #{sellOrder.sellTime},
                 </if>
@@ -442,7 +450,7 @@
         FROM student_payment_order spo
                  LEFT JOIN sell_order so on so.order_id_ = spo.id_
         WHERE spo.status_ = 'SUCCESS'
-          AND spo.group_type_ IN ('REPAIR', 'GOODS_SELL')
+          AND spo.group_type_ = 'REPAIR'
           AND spo.create_time_ >= #{startTime}
           AND spo.create_time_ <= #{endTime}
         GROUP BY spo.organ_id_
@@ -454,13 +462,31 @@
         SELECT spo.organ_id_,
                SUM(spo.actual_amount_) income_total_
         FROM student_payment_order spo
+                 LEFT JOIN sell_order so on so.order_id_ = spo.id_
         WHERE spo.status_ = 'SUCCESS'
-          AND spo.group_type_ IN ('REPAIR', 'GOODS_SELL')
+          AND spo.group_type_ = 'REPAIR'
           AND spo.create_time_ >= #{startTime}
           AND spo.create_time_ <= #{endTime}
         GROUP BY spo.organ_id_
         ]]></select>
 
+    <!-- 获取分部学校的收入支出(商品销售订单) -->
+    <select id="getGoodsSellGroupMonthReport"
+            resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
+        SELECT spo.organ_id_,
+               so.cooperation_organ_id_,
+               SUM(so.actual_amount_)       income_total_,
+               SUM(so.actual_amount_)       sell_amount_,
+               SUM(so.sell_cost_ * so.num_) sell_cost_
+        FROM student_payment_order spo
+                 LEFT JOIN sell_order so on so.order_id_ = spo.id_
+        WHERE spo.status_ = 'SUCCESS'
+          AND spo.group_type_ ='GOODS_SELL'
+          AND spo.create_time_ >= #{startTime}
+          AND spo.create_time_ <= #{endTime}
+        GROUP BY spo.organ_id_, so.cooperation_organ_id_
+        ]]></select>
+
 
     <!-- 获取订单的销售列表 -->
     <select id="getOrderSellOrder" resultMap="SellOrder">
@@ -515,13 +541,11 @@
     <select id="getRefundIncome" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
         SELECT organ_id_,
                cooperation_organ_id_,
-               -SUM(actual_amount_)    sell_amount_,
-               -SUM(sell_cost_ * num_) sell_cost_,
-                SUM(actual_amount_)    other_income_
+               -SUM(sell_cost_ * num_) sell_cost_
         FROM sell_order
         WHERE status_ = 1
-          AND sell_time_ >= #{startTime}
-          AND sell_time_ <= #{endTime}
+          AND refund_time_ >= #{startTime}
+          AND refund_time_ <= #{endTime}
         GROUP BY organ_id_, cooperation_organ_id_
         ]]></select>
 
@@ -548,6 +572,14 @@
         ORDER BY sell_time_
     </select>
 
+    <select id="getRefundSellOrder" resultMap="SellOrder">
+        SELECT *
+        FROM sell_order
+        WHERE order_id_ = #{orderId}
+          AND status_ = 0
+    </select>
+
+
     <select id="lockSellOrders" resultMap="SellOrder">
         SELECT * FROM sell_order WHERE id_ IN
         <foreach collection="sellOrderIds" item="sellOrderId" open="(" close=")" separator=",">

+ 47 - 22
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupController.java

@@ -1,38 +1,59 @@
 package com.ym.mec.student.controller;
 
-import com.ym.mec.auth.api.client.SysUserFeignService;
-import com.ym.mec.auth.api.entity.SysUser;
-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.*;
-import com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus;
-import com.ym.mec.biz.dal.enums.*;
-import com.ym.mec.biz.service.*;
-import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.common.entity.HttpResponseResult;
-import com.ym.mec.common.exception.BizException;
-
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.*;
-
-import javax.annotation.Resource;
-
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
+import javax.annotation.Resource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
+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.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;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
+import com.ym.mec.biz.dal.enums.PaymentStatusEnum;
+import com.ym.mec.biz.service.MusicGroupService;
+import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
+import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
+import com.ym.mec.biz.service.StudentPaymentOrderService;
+import com.ym.mec.biz.service.StudentRegistrationService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.exception.BizException;
+import com.ym.mec.util.date.DateUtil;
+
 @RequestMapping("musicGroup")
 @Api(tags = "乐团服务")
 @RestController
@@ -136,6 +157,10 @@ public class MusicGroupController extends BaseController {
                 (musicGroup.getStatus() != MusicGroupStatusEnum.APPLY && musicGroup.getStatus() != MusicGroupStatusEnum.PAY)){
             return failed("乐团在"+musicGroup.getStatus().getMsg()+",不能缴费");
         }
+        Date now = new Date();
+        if (DateUtil.daysBetween(musicGroup.getPaymentExpireDate(), now) > 1) {
+            return failed("乐团缴费时间已截止");
+        }
         studentRegistration.setOwnershipType(musicGroup.getOwnershipType());
         studentRegistration.setChargeTypeId(musicGroup.getChargeTypeId());
 

+ 1 - 1
mec-web/src/main/java/com/ym/mec/web/controller/SellOrderController.java

@@ -106,7 +106,7 @@ public class SellOrderController extends BaseController {
         } else {
             sellOrders.add(sellOrder);
         }
-        return succeed(sellOrderService.refund(sellOrders));
+        return succeed(sellOrderService.refund(sellOrders,true));
     }
 
 }