Forráskód Böngészése

管乐迷商城改造

zouxuan 1 éve
szülő
commit
f24ed4e09c

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

@@ -244,4 +244,6 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
     List<String> getMallProductCategory(@Param("database") String database);
 
     List<SellOrder> queryByOrganNos(@Param("orderNos") List<String> orderNos);
+
+    void deleteByOrderNo(@Param("orderNo") String orderNo);
 }

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

@@ -480,4 +480,6 @@ public interface StudentPaymentOrderDao extends BaseDAO<Long, StudentPaymentOrde
     Integer queryPaymentStudentCount(Map<String, Object> params);
 
     List<Double11StaticWrapper.StudentCount> count2023Double11StudentsByOrgan(@Param("param") Double11StaticWrapper.SaleStaticConfigParam configParam);
+
+    void deleteByOrderNo(@Param("orderNo") String orderNo);
 }

+ 9 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderCourseSettings.java

@@ -40,12 +40,20 @@ public class MusicGroupPaymentCalenderCourseSettings extends BaseEntity {
 	@ApiModelProperty(value = "是否学生可选", required = false)
 	private boolean isStudentOptional = true;
 
-
 	/**  */
 	private java.util.Date createTime;
 	
 	/**  */
 	private java.util.Date updateTime;
+
+	public boolean getIsStudentOptional() {
+		return isStudentOptional;
+	}
+
+	public void setIsStudentOptional(boolean studentOptional) {
+		isStudentOptional = studentOptional;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/OrderTypeEnum.java

@@ -38,6 +38,7 @@ public enum OrderTypeEnum implements BaseEnum<String, OrderTypeEnum> {
     ACTIVITY("ACTIVITY", "活动购买"),
     MEMBER("MEMBER", "会员购买"),
     LIVE_BUY("LIVE_BUY", "直播购物"),
+    SCHOOL_GOODS_PURCHASE("SCHOOL_GOODS_PURCHASE","学校商品采购"),
     MALL_BUY("MALL_BUY", "商城购物");
 
 

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

@@ -91,4 +91,6 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
     List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,
                                   BigDecimal totalBalance, BigDecimal expectTotalAmount, BigDecimal couponRemitAmount,
                                   BigDecimal actualTotalAmount,Boolean saveFlag);
+
+    void deleteByOrderNo(String orderNo);
 }

+ 143 - 56
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -149,6 +149,8 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
     private GoodsSubService goodsSubService;
     @Autowired
     private GoodsDao goodsDao;
+    @Autowired
+    private SellOrderService sellOrderService;
 
     @Autowired
     private SysAreaService sysAreaService;
@@ -1113,64 +1115,29 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                 if (CollectionUtils.isEmpty(goods)) {
                     throw new BizException("商品信息不存在");
                 }
-                // 查询地区信息
-                List<String> areaIds = new ArrayList<>();
-                areaIds.add(address.getProvince());
-                areaIds.add(address.getCity());
-                areaIds.add(address.getRegion());
-                areaIds = areaIds.stream().filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
-                Map<String, String> nameMapByIds = sysAreaService.getNameMapByIds(areaIds);
-                OrderCreate orderCreate = new OrderCreate();
-                String orderNo = idGeneratorService.generatorId("payment") + "";
+                String orderNo = "Y" + idGeneratorService.generatorId("payment");
+                //管乐迷应收订单创建
+                StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
+                studentPaymentOrder.setActualAmount(calender.getCurrentTotalAmount());
+                studentPaymentOrder.setCooperationId(musicGroup.getCooperationOrganId());
+                studentPaymentOrder.setMusicGroupId(calender.getMusicGroupId());
+                studentPaymentOrder.setCalenderId(calender.getId());
+                studentPaymentOrder.setType(OrderTypeEnum.SCHOOL_GOODS_PURCHASE);
+                studentPaymentOrder.setGroupType(GroupType.OUTORDER);
+                studentPaymentOrder.setOrganId(musicGroup.getOrganId());
+                studentPaymentOrder.setExpectAmount(calender.getCurrentTotalAmount());
+                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
+                studentPaymentOrder.setCreateTime(date);
+                studentPaymentOrder.setUpdateTime(date);
+                studentPaymentOrder.setPayTime(date);
+                studentPaymentOrder.setOrderNo(orderNo);
+                studentPaymentOrderDao.insert(studentPaymentOrder);
+                //保存商品订单详情
+                this.saveSellOrder(goods, studentPaymentOrder);
                 address.setOrderNo(orderNo);
                 musicGroupPaymentCalenderAddressService.updateById(address);
-                orderCreate.setOrderNo(orderNo);
-                orderCreate.setOrchestraId(musicGroup.getId());
-                orderCreate.setMemberId(musicGroup.getSchoolId().longValue());
-                orderCreate.setTotalAmount(calender.getCurrentTotalAmount());
-                orderCreate.setOrderFormType("MEC");
-                orderCreate.setPlatformType("SCHOOL");
-                orderCreate.setSourceType(2);
-                orderCreate.setReceiverName(address.getName());
-                orderCreate.setReceiverPostCode(address.getPostCode());
-                orderCreate.setReceiverPhone(address.getPhone());
-                orderCreate.setReceiverProvince(nameMapByIds.getOrDefault(address.getProvince(),""));
-                orderCreate.setReceiverCity(nameMapByIds.getOrDefault(address.getCity(),""));
-                orderCreate.setReceiverRegion(nameMapByIds.getOrDefault(address.getRegion(),""));
-                orderCreate.setReceiverDetailAddress(address.getAddress());
-                orderCreate.setStatus(1);
-                List<OrderCreate.OrderItem> orderItems = new ArrayList<>();
-                for (MusicGroupPaymentCalenderGoods e : goods) {
-                    BigDecimal totalPrice = e.getTotalPrice();
-                    List<ComplementGoodsDto> goodsDtoList = JSON.parseArray(e.getChildGoodsJson(), ComplementGoodsDto.class);
-                    //总金额按比例分配
-                    //待分配
-                    BigDecimal waitRemitFee = totalPrice;
-                    BigDecimal totalAmount = WrapperUtil.sumList(goodsDtoList, ComplementGoodsDto::getOrganCostPrice);
-                    for (int i = 0; i < goodsDtoList.size(); i++) {
-                        ComplementGoodsDto goodsDto = goodsDtoList.get(i);
-                        OrderCreate.OrderItem orderItemCreate = new OrderCreate.OrderItem();
-                        orderItemCreate.setProductQuantity(e.getNum());
-                        orderItemCreate.setProductSkuId(goodsDto.getSkuStockId().longValue());
-                        //如果是最后一件商品
-                        if (i == goodsDtoList.size() - 1) {
-                            orderItemCreate.setRealAmount(waitRemitFee);
-                        } else {
-                            //获取比例
-                            BigDecimal ratioAmount = goodsDto.getOrganCostPrice().divide(totalAmount, 6, RoundingMode.HALF_UP);
-                            //获取分配的金额
-                            BigDecimal multiply = ratioAmount.multiply(totalPrice).setScale(2, RoundingMode.HALF_UP);
-                            orderItemCreate.setRealAmount(multiply);
-                            waitRemitFee = waitRemitFee.subtract(multiply);
-                        }
-                        orderItems.add(orderItemCreate);
-                    }
-                }
-                orderCreate.setOrderItemList(orderItems);
-                CommonResult<Boolean> result = mallFeignService.productOrderCreate(orderCreate);
-                if (result.getCode() != 200) {
-                    throw new BizException(result.getMessage());
-                }
+                // 同步订单到商城
+                this.syncMallOrder(address, calender, musicGroup, goods);
             }
             for (MusicGroupPaymentCalender musicGroupPaymentCalender : musicGroupPaymentCalenders) {
                 //将0元未缴费学员缴费状态更新为已缴费
@@ -1183,6 +1150,121 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
         }
     }
 
+    public void saveSellOrder(List<MusicGroupPaymentCalenderGoods> goods, StudentPaymentOrder studentPaymentOrder) {
+        List<SellOrder> sellOrderList = new ArrayList<>();
+        for (MusicGroupPaymentCalenderGoods calenderGood : goods) {
+            //待分配金额
+            for (Integer i = 0; i < calenderGood.getNum(); i++) {
+                List<ComplementGoodsDto> goodsDtoList = JSON.parseArray(calenderGood.getChildGoodsJson(), ComplementGoodsDto.class);
+                //获取总成本
+                BigDecimal totalCostPrice = goodsDtoList.stream().map(e->e.getOrganCostPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
+                //待分配金额
+                BigDecimal totalAmount = calenderGood.getSinglePrice();
+                BigDecimal waitAmount = totalAmount;
+                for (int j = 0; j < goodsDtoList.size(); j++) {
+                    ComplementGoodsDto goodsDto = goodsDtoList.get(j);
+                    //获取比例
+                    BigDecimal proportion = BigDecimal.ZERO;
+                    if (totalCostPrice.compareTo(BigDecimal.ZERO) > 0) {
+                        proportion = goodsDto.getOrganCostPrice().divide(totalCostPrice, 2, BigDecimal.ROUND_HALF_UP);
+                    }
+                    SellOrder sellOrder = new SellOrder();
+                    sellOrder.setGoodsSkuId(goodsDto.getSkuStockId());
+                    sellOrder.setOrganSellCost(goodsDto.getOrganCostPrice());
+                    sellOrder.setOrderId(studentPaymentOrder.getOrganId().longValue());
+                    sellOrder.setType(StringUtils.endsWithIgnoreCase("INSTRUMENT", calenderGood.getGoodsType()) ? SellTypeEnum.INSTRUMENT
+                            : StringUtils.endsWithIgnoreCase("ACCESSORIES", calenderGood.getGoodsType()) ? SellTypeEnum.ACCESSORIES
+                            : StringUtils.endsWithIgnoreCase("TEACHING", calenderGood.getGoodsType()) ? SellTypeEnum.TEACHING
+                            : StringUtils.endsWithIgnoreCase("STAFF", calenderGood.getGoodsType()) ? SellTypeEnum.STAFF
+                            : SellTypeEnum.OTHER);
+                    sellOrder.setOrderNo(studentPaymentOrder.getOrderNo());
+                    if (j == goodsDtoList.size() - 1) {
+                        sellOrder.setOrderAmount(waitAmount);
+                    } else {
+                        BigDecimal amount = totalAmount.multiply(proportion);
+                        waitAmount = waitAmount.subtract(amount);
+                        sellOrder.setOrderAmount(amount);
+                    }
+                    sellOrder.setActualAmount(sellOrder.getOrderAmount());
+                    sellOrder.setExpectAmount(sellOrder.getOrderAmount());
+                    sellOrder.setCouponRemitAmount(BigDecimal.ZERO);
+                    sellOrder.setBalanceAmount(BigDecimal.ZERO);
+                    sellOrder.setParentGoodsId(calenderGood.getGoodsId());
+                    sellOrder.setNum(1);
+                    sellOrder.setGoodsName(calenderGood.getGoodsName());
+                    sellOrder.setAccountType(AccountType.INTERNAL);
+                    sellOrder.setCooperationOrganId(studentPaymentOrder.getCooperationId());
+                    sellOrder.setTransNo(studentPaymentOrder.getTransNo());
+                    sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
+                    sellOrder.setMerNo(studentPaymentOrder.getMerNos());
+                    sellOrder.setSellTime(studentPaymentOrder.getCreateTime());
+                    sellOrder.setTenantId(studentPaymentOrder.getTenantId());
+                    sellOrderList.add(sellOrder);
+                }
+            }
+        }
+        sellOrderService.batchInsert(sellOrderList);
+    }
+
+    public void syncMallOrder(MusicGroupPaymentCalenderAddress address, MusicGroupPaymentCalender calender,
+                              MusicGroup musicGroup, List<MusicGroupPaymentCalenderGoods> goods){
+        // 查询地区信息
+        List<String> areaIds = new ArrayList<>();
+        areaIds.add(address.getProvince());
+        areaIds.add(address.getCity());
+        areaIds.add(address.getRegion());
+        areaIds = areaIds.stream().filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
+        Map<String, String> nameMapByIds = sysAreaService.getNameMapByIds(areaIds);
+        OrderCreate orderCreate = new OrderCreate();
+        orderCreate.setOrderNo(address.getOrderNo());
+        orderCreate.setOrchestraId(musicGroup.getId());
+        orderCreate.setMemberId(musicGroup.getSchoolId().longValue());
+        orderCreate.setTotalAmount(calender.getCurrentTotalAmount());
+        orderCreate.setOrderFormType("MEC");
+        orderCreate.setPlatformType("SCHOOL");
+        orderCreate.setSourceType(2);
+        orderCreate.setReceiverName(address.getName());
+        orderCreate.setReceiverPostCode(address.getPostCode());
+        orderCreate.setReceiverPhone(address.getPhone());
+        orderCreate.setReceiverProvince(nameMapByIds.getOrDefault(address.getProvince(),""));
+        orderCreate.setReceiverCity(nameMapByIds.getOrDefault(address.getCity(),""));
+        orderCreate.setReceiverRegion(nameMapByIds.getOrDefault(address.getRegion(),""));
+        orderCreate.setReceiverDetailAddress(address.getAddress());
+        orderCreate.setStatus(1);
+        List<OrderCreate.OrderItem> orderItems = new ArrayList<>();
+        for (MusicGroupPaymentCalenderGoods e : goods) {
+            BigDecimal totalPrice = e.getTotalPrice();
+            List<ComplementGoodsDto> goodsDtoList = JSON.parseArray(e.getChildGoodsJson(), ComplementGoodsDto.class);
+            //总金额按比例分配
+            //待分配
+            BigDecimal waitRemitFee = totalPrice;
+            BigDecimal totalAmount = WrapperUtil.sumList(goodsDtoList, ComplementGoodsDto::getOrganCostPrice);
+            for (int i = 0; i < goodsDtoList.size(); i++) {
+                ComplementGoodsDto goodsDto = goodsDtoList.get(i);
+                OrderCreate.OrderItem orderItemCreate = new OrderCreate.OrderItem();
+                orderItemCreate.setProductQuantity(e.getNum());
+                orderItemCreate.setProductSkuId(goodsDto.getSkuStockId().longValue());
+                //如果是最后一件商品
+                if (i == goodsDtoList.size() - 1) {
+                    orderItemCreate.setRealAmount(waitRemitFee);
+                } else {
+                    //获取比例
+                    BigDecimal ratioAmount = goodsDto.getOrganCostPrice().divide(totalAmount, 6, RoundingMode.HALF_UP);
+                    //获取分配的金额
+                    BigDecimal multiply = ratioAmount.multiply(totalPrice).setScale(2, RoundingMode.HALF_UP);
+                    orderItemCreate.setRealAmount(multiply);
+                    waitRemitFee = waitRemitFee.subtract(multiply);
+                }
+                orderItems.add(orderItemCreate);
+            }
+        }
+        orderCreate.setOrderItemList(orderItems);
+        CommonResult<Boolean> result = mallFeignService.productOrderCreate(orderCreate);
+        if (result.getCode() != 200) {
+            throw new BizException(result.getMessage());
+        }
+    }
+
     private void createPreImGroup(MusicGroup musicGroup){
         // 创建群
         imGroupService.create(musicGroup.getId(), null, "乐团预报名", null,
@@ -1530,6 +1612,11 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                 if (byOrderNo != null) {
                     throw new BizException("操作失败:商品采购订单已录入");
                 }
+                //删除关联的商品采购订单
+                if(StringUtils.isNotEmpty(address.getOrderNo())){
+                    studentPaymentOrderDao.deleteByOrderNo(address.getOrderNo());
+                    sellOrderService.deleteByOrderNo(address.getOrderNo());
+                }
             }
             musicGroupPaymentCalenderGoodsService.lambdaUpdate().eq(MusicGroupPaymentCalenderGoods::getCalenderId,id).remove();
         }

+ 6 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -876,6 +876,12 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 
     @Override
     @Transactional(rollbackFor = Exception.class)
+    public void deleteByOrderNo(String orderNo) {
+        sellOrderDao.deleteByOrderNo(orderNo);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
     public List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds,
                                          KitGroupPurchaseTypeEnum kitGroupPurchaseType,Boolean saveFlag) {
         if (CollectionUtils.isEmpty(goodsIds)) {

+ 24 - 312
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -403,7 +403,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         return payMap;
     }
 
-    public List<StudentPaymentOrderDetail> initStudentPaymentOrderDetail(StudentPaymentOrder studentPaymentOrder, List<GoodsSellDto> goodsSellDtos){
+    public void initStudentPaymentOrderDetail(StudentPaymentOrder studentPaymentOrder, List<GoodsSellDto> goodsSellDtos){
         Date date = new Date();
         //添加订单详情
         List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
@@ -413,24 +413,17 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         BigDecimal totalPrice = BigDecimal.ZERO;
 
         if (goodsSellDtos != null) {
-            //String goodsIdsStr = goodsSellDtos.stream().map(t -> t.getGoodsId().toString()).collect(Collectors.joining(","));
-
             StringBuffer sb = new StringBuffer();
             for (GoodsSellDto goodsSellDto : goodsSellDtos) {
                 for (int i = 0; i < goodsSellDto.getGoodsNum(); i++) {
                     sb.append(goodsSellDto.getGoodsId()).append(",");
                 }
             }
-
             String goodsIdsStr = StringUtils.removeEnd(sb.toString(), ",");
 
             List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
             Map<Integer, Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getId, t -> t));
-            BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
-
-            for (String goodsIdStr : goodsIdsStr.split(",")) {
-                totalGroupPurchasePrice = totalGroupPurchasePrice.add(goodsMap.get(Integer.parseInt(goodsIdStr)).getGroupPurchasePrice());
-            }
+            BigDecimal totalGroupPurchasePrice = goodsMap.values().stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 
             Goods goods = null;
             for (String goodsIdStr : goodsIdsStr.split(",")) {
@@ -472,10 +465,27 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             }
         }
 
-        if (studentPaymentOrderDetailList.size() > 0) {
+        if (CollectionUtils.isNotEmpty(studentPaymentOrderDetailList)) {
+            //分摊优惠券金额
+            if(studentPaymentOrder.getCouponRemitFee().compareTo(BigDecimal.ZERO) > 0 &&
+                    studentPaymentOrder.getExpectAmount().compareTo(BigDecimal.ZERO) > 0){
+                BigDecimal subCouponRemitFee = studentPaymentOrder.getCouponRemitFee();
+                for (int i = 0; i < studentPaymentOrderDetailList.size(); i++) {
+                    StudentPaymentOrderDetail orderDetail = studentPaymentOrderDetailList.get(i);
+                    if (i == studentPaymentOrderDetailList.size() - 1) {
+                        orderDetail.setRemitFee(subCouponRemitFee);
+                    } else {
+                        //获取比例
+                        BigDecimal ratioAmount = orderDetail.getPrice().divide(studentPaymentOrder.getExpectAmount(), 6, BigDecimal.ROUND_HALF_UP);
+                        //获取分配的减免金额
+                        BigDecimal multiply = ratioAmount.multiply(studentPaymentOrder.getCouponRemitFee()).setScale(2, BigDecimal.ROUND_HALF_UP);
+                        subCouponRemitFee = subCouponRemitFee.subtract(multiply);
+                        orderDetail.setRemitFee(multiply);
+                    }
+                }
+            }
             studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
         }
-        return studentPaymentOrderDetailList;
     }
 
     @Override
@@ -1235,234 +1245,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         return pageInfo;
     }
 
-    @Transactional(rollbackFor = Exception.class)
-    public void saveSellOrder(String orderNo) {
-        StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(orderNo);
-        StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(orderNo);
-        String goodsJson = studentGoodsSell.getGoodsJson();
-        List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(goodsJson, GoodsSellDto.class);
-        //用户选择的商品
-//        Map<Integer, List<GoodsSellDto>> collect = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
-        List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
-        sellOrderService.initSellOrder(orderByOrderNo,null,goodsIds,null,true);
-        /*goodsSellDtos.forEach(e -> {
-            for (int i = 0; i < e.getGoodsNum(); i++) {
-                goodsIds.add(e.getGoodsId());
-            }
-        });
-        AccountType accountType = AccountType.INTERNAL;
-        if (StringUtils.isNotEmpty(orderByOrderNo.getPaymentChannel())) {
-            accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(orderByOrderNo.getPaymentChannel()), orderByOrderNo.getMerNos(), orderByOrderNo.getTenantId());
-        }
-        //实际扣减的库存商品
-        List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
-        Map<String, BigDecimal> costMap = new HashMap<>(2);
-        BigDecimal balancePaymentAmount = orderByOrderNo.getBalancePaymentAmount();
-        //可用余额
-        BigDecimal usableBalance = balancePaymentAmount;
-        BigDecimal marketAmount = studentGoodsSell.getMarketAmount().add(studentGoodsSell.getCouponMarketAmount());
-        //可用减免金额
-        BigDecimal usableMarketAmount = marketAmount;
-        //包含减免余额的总金额
-        BigDecimal totalAmount = goodsSellDtos.stream().map(e -> e.getTotalGoodsPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
-        //组合商品减免金额
-        Map<Integer, BigDecimal> parentGoodsCutTotalPriceMap = new HashMap<>();
-        //组合商品附加金额
-        Map<Integer, BigDecimal> parentGoodsAddTotalPriceMap = new HashMap<>();
-        //组合商品实际总价
-        Map<Integer, BigDecimal> parentGoodsTotalPriceMap = new HashMap<>();
-        //应付总额
-        BigDecimal totalActual = totalAmount.subtract(marketAmount);
-        //可用应付
-        BigDecimal usableActual = totalActual;
-        //获取实付总额
-        BigDecimal realityAmount = totalActual.subtract(usableBalance);
-        //可用实付总额
-        BigDecimal usableAmount = realityAmount;
-        //可用组合商品总减免金额
-        BigDecimal usableParentGoodsCutTotalPrice;
-        //可用组合商品总附加金额
-        BigDecimal usableParentGoodsAddTotalPrice;
-
-        //获取组合商品列表
-        List<SellOrder> orderList = sellOrderList.stream().filter(sellOrder -> sellOrder.getParentGoodsId() != null).collect(Collectors.toList());
-        Map<Integer, List<SellOrder>> orderListMap = orderList.stream().collect(Collectors.groupingBy(SellOrder::getParentGoodsId));
-
-        //获取组合商品实际销售价,和单个商品总和价
-        for (Integer integer : orderListMap.keySet()) {
-            SellOrder sellOrder = orderListMap.get(integer).get(0);
-            //获取组合商品销售总价
-            GoodsSellDto goodsSellDto = collect.get(sellOrder.getParentGoodsId()).get(0);
-            BigDecimal parentTotalGoodsPrice = goodsSellDto.getTotalGoodsPrice().divide(new BigDecimal(goodsSellDto.getGoodsNum()));
-            BigDecimal totalGoodsPrice = BigDecimal.ZERO;
-            //获取单个商品销售总价
-            for (GoodsSellDto sellDto : goodsSellDto.getGoodsSellDtos()) {
-                totalGoodsPrice = totalGoodsPrice.add(sellDto.getTotalGoodsPrice());
-            }
-            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));
-            }
-        }
-        //分配组合商品的中单个商品的价格
-        noFreeAmount:
-        for (Integer parentGoodsId : orderListMap.keySet()) {
-
-            BigDecimal addTotalPrice = parentGoodsAddTotalPriceMap.get(parentGoodsId);
-            usableParentGoodsAddTotalPrice = addTotalPrice;
-            BigDecimal cutTotalPrice = parentGoodsCutTotalPriceMap.get(parentGoodsId);
-            usableParentGoodsCutTotalPrice = cutTotalPrice;
-
-            //获取组合商品销售总价
-            GoodsSellDto goodsSellDto = collect.get(parentGoodsId).get(0);
-//            BigDecimal divide = goodsSellDto.getGoodsPrice();
-
-            //获取子商品明细map
-            List<GoodsSellDto> sellDtos = goodsSellDto.getGoodsSellDtos();
-            Map<Integer, List<GoodsSellDto>> subGoodsMap = sellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
-            List<Integer> integers = new ArrayList<>(subGoodsMap.keySet());
-            BigDecimal divide = parentGoodsTotalPriceMap.get(parentGoodsId);
-            for (int i = 0; i < integers.size(); i++) {
-                GoodsSellDto sellDto = subGoodsMap.get(integers.get(i)).get(0);
-                //获取比例
-                BigDecimal ratioAmount = sellDto.getTotalGoodsPrice().divide(divide, 6, BigDecimal.ROUND_HALF_UP);
-
-                if (addTotalPrice != null && addTotalPrice.doubleValue() > 0l) {
-                    //如果是最后一件商品
-                    if (i == integers.size() - 1) {
-                        sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(usableParentGoodsAddTotalPrice));
-                    } else {
-                        //获取分配的附加
-                        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) {
-                    //如果是最后一件商品
-                    if (i == integers.size() - 1) {
-                        sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(usableParentGoodsCutTotalPrice));
-                    } else {
-                        //获取分配的组合减免金额
-                        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 {
-                    continue noFreeAmount;
-                }
-            }
-        }
-        for (int i = 0; i < sellOrderList.size(); i++) {
-            SellOrder sellOrder = sellOrderList.get(i);
-            Integer e = null;
-            if (sellOrder.getParentGoodsId() != null) {
-                e = sellOrder.getParentGoodsId();
-            } else {
-                e = sellOrder.getGoodsId();
-            }
-            GoodsSellDto goodsSellDto = collect.get(e).get(0);
-            List<GoodsSellDto> sellDtos = goodsSellDto.getGoodsSellDtos();
-            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);
-            }
-            sellOrder.setOrganId(orderByOrderNo.getOrganId());
-            sellOrder.setTransNo(orderByOrderNo.getTransNo());
-            sellOrder.setOrderId(orderByOrderNo.getId());
-            sellOrder.setOrderNo(orderByOrderNo.getOrderNo());
-            Goods goods = goodsService.get(e);
-            costMap.put("sellCost", goods.getDiscountPrice());
-            if (goods.getAgreeCostPrice() != null) {
-                costMap.put("SellCost2", goods.getAgreeCostPrice());
-            }
-            BigDecimal multiply2 = goodsSellDto.getGoodsPrice().multiply(new BigDecimal(sellOrder.getNum()));
-            //获取比例
-            BigDecimal ratioAmount = multiply2.divide(totalAmount, 6, BigDecimal.ROUND_HALF_UP);
-            //实际支付价格
-            BigDecimal actualAmount = multiply2;
-            //如果有减免金额
-            if (marketAmount.doubleValue() > 0l) {
-                //如果是最后一件商品
-                if (i == sellOrderList.size() - 1) {
-                    actualAmount = multiply2.subtract(usableMarketAmount);
-                } else {
-                    //获取分配的减免金额
-                    BigDecimal multiply = ratioAmount.multiply(marketAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
-                    actualAmount = multiply2.subtract(multiply);
-                    usableMarketAmount = usableMarketAmount.subtract(multiply);
-                }
-            }
-
-            //如果没有使用余额,那么实际金额和预计金额一致
-            if (balancePaymentAmount.doubleValue() == 0l) {
-                sellOrder.setActualAmount(actualAmount);
-                sellOrder.setBalanceAmount(BigDecimal.ZERO);
-            } else {
-                //如果是最后一件商品
-                if (i == sellOrderList.size() - 1) {
-                    sellOrder.setActualAmount(usableAmount);
-                    sellOrder.setBalanceAmount(usableBalance);
-                } else {
-                    //获取分配的余额
-                    BigDecimal multiply = ratioAmount.multiply(balancePaymentAmount).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);
-                    usableBalance = usableBalance.subtract(multiply);
-                    usableActual = usableActual.subtract(multiply1).subtract(multiply);
-                }
-            }
-            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())) {
-                sellOrder.setType(SellTypeEnum.valueOf(goodsSellDto.getGoodsType()));
-            } else {
-                sellOrder.setType(SellTypeEnum.OTHER);
-            }
-            sellOrder.setGoodsId(sellOrder.getGoodsId());
-            sellOrder.setGoodsName(goodsSellDto.getGoodsName());
-            sellOrder.setUserId(studentGoodsSell.getUserId());
-            sellOrder.setPaymentChannel(orderByOrderNo.getPaymentChannel());
-            sellOrder.setMerNo(orderByOrderNo.getMerNos());
-            sellOrder.setSellTime(orderByOrderNo.getPayTime());
-            sellOrder.setEduTeacherId(studentGoodsSell.getTeacherId());
-            sellOrder.setCooperationOrganId(studentGoodsSell.getCooperationOrganId());
-        }
-        if (sellOrderList.size() > 0) {
-            //如果有优惠券金额
-            BigDecimal couponMarketAmount = studentGoodsSell.getCouponMarketAmount();
-            if (couponMarketAmount.compareTo(BigDecimal.ZERO) > 0) {
-                BigDecimal reduce = sellOrderList.stream().map(e -> e.getExpectAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
-                List<SellOrder> sellOrders = sellOrderList.stream().filter(e -> e.getExpectAmount().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
-                //可用优惠券金额
-                BigDecimal subCouponMarketAmount = couponMarketAmount;
-                for (int i = 0; i < sellOrders.size(); i++) {
-                    SellOrder sellOrder = sellOrders.get(i);
-                    //如果是最后一件商品
-                    if (i == sellOrders.size() - 1) {
-                        sellOrder.setCouponRemitAmount(subCouponMarketAmount);
-                    } else {
-                        //获取比例
-                        BigDecimal ratioAmount = sellOrder.getExpectAmount().divide(reduce, 6, BigDecimal.ROUND_HALF_UP);
-                        //获取分配的减免金额
-                        BigDecimal multiply = couponMarketAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
-                        subCouponMarketAmount = subCouponMarketAmount.subtract(multiply);
-                        sellOrder.setCouponRemitAmount(multiply);
-                    }
-                }
-            }
-            sellOrderService.batchInsert(sellOrderList);
-            sellOrderService.syncSellOrder2Mall(sellOrderList,orderByOrderNo);
-        }*/
-    }
-
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
@@ -1536,32 +1318,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
             }
             sysUserCashAccountDetailService.insert(paymentDetail);
-            //优惠券减免金额
-            BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
-            if (couponRemitFee.compareTo(BigDecimal.ZERO) > 0 && repairInfo.getAmount().compareTo(BigDecimal.ZERO) > 0) {
-                //获取维修金额
-                BigDecimal repairAmount = repairInfo.getAmount();
-                //获取比例
-                BigDecimal divide = repairAmount.divide(repairAmount.add(couponRemitFee), 6, BigDecimal.ROUND_HALF_UP);
-                BigDecimal bigDecimal = couponRemitFee.multiply(divide).setScale(2, BigDecimal.ROUND_HALF_UP);
-                couponRemitFee = couponRemitFee.subtract(bigDecimal);
-//                repairInfo.setAmount(repairAmount.subtract(bigDecimal));
-//                studentRepairDao.update(repairInfo);
-            }
             //生成销售订单
-            if (StringUtils.isNotBlank(repairInfo.getGoodsJson())) {
-                List<Goods> goods = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
-                List<Integer> goodsIds = goods.stream().map(Goods::getId).collect(Collectors.toList());
-                if (goodsIds.size() > 0) {
-                    /*List<SellOrder> sellOrders = sellOrderService.addSellOrder(studentPaymentOrder.getId(),
-                            null,
-                            goodsIds,
-                            studentPaymentOrder.getExpectAmount().add(repairInfo.getExemptionAmount()),
-                            studentPaymentOrder.getBalancePaymentAmount(), couponRemitFee);*/
-                    studentPaymentOrder.setExpectAmount(studentPaymentOrder.getExpectAmount().add(repairInfo.getExemptionAmount()));
-                    studentPaymentOrder.setCouponRemitFee(couponRemitFee);
-                    sellOrderService.initSellOrder(studentPaymentOrder,null,goodsIds,null,true);
-                }
+            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
+            if (CollectionUtils.isNotEmpty(orderDetails)) {
+                sellOrderService.addOrderDetail2SellOrder(studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId()),studentPaymentOrder,null);
             }
 
             String imContent = repairInfo.getStudentName() + "学员您好,您的乐器维修已受理,我们会尽快完成保养维修";
@@ -1587,54 +1347,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             if (this.update(repairInfo) <= 0) {
                 throw new BizException("维修单更新失败");
             }
-
-            //增加商品库存
-            List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
-            String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
-            if (StringUtils.isNotBlank(goodsIds)) {
-//                GoodsProcurement goodsProcurement = null;
-                List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
-                Map<Integer, Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getId, t -> t));
-                Goods goods = null;
-                Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
-//                Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
-
-                for (String goodsIdStr : goodsIds.split(",")) {
-                    if (StringUtils.isBlank(goodsIdStr)) {
-                        continue;
-                    }
-                    goods = goodsMap.get(Integer.parseInt(goodsIdStr));
-                    if (batchUpdateGoodsMap.get(goods.getId()) != null) {
-                        goods = batchUpdateGoodsMap.get(goods.getId());
-                    }
-//                    goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
-                    goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
-                    goods.setUpdateTime(nowDate);
-
-                    batchUpdateGoodsMap.put(goods.getId(), goods);
-
-                    // 进货清单
-                    /*goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
-                    if (goodsProcurement != null) {
-                        if (goodsProcurementMap.get(goodsProcurement.getId()) != null) {
-                            goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
-                        }
-                        goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
-                        goodsProcurement.setUpdateTime(nowDate);
-                        goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
-                    }*/
-
-                }
-
-                /*if (goodsProcurementMap.size() > 0) {
-                    goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
-                }*/
-
-                if (batchUpdateGoodsMap.size() > 0) {
-                    goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
-                }
-            }
-
             if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
                 sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器维修支付失败");
             }

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

@@ -48,10 +48,13 @@
 
     <insert id="batchInsert" parameterType="java.util.List">
         INSERT INTO music_group_subject_goods_group
-        (name_,type_,music_group_id_,subject_id_,goods_id_list_,create_time_,update_time_,price_,deposit_fee_,remission_course_fee_,group_remission_course_fee_,kit_group_purchase_type_json_,course_purchase_type_json_,organ_share_profit_,tenant_id_) VALUES
+        (name_,type_,music_group_id_,subject_id_,goods_id_list_,create_time_,update_time_,price_,deposit_fee_,
+         remission_course_fee_,group_remission_course_fee_,kit_group_purchase_type_json_,course_purchase_type_json_,organ_share_profit_,tenant_id_) VALUES
         <foreach collection="lists" item="item" index="index" separator=",">
             (#{item.name},#{item.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-            #{musicGroupId},#{item.subjectId},#{item.goodsIdList},now(),now(),#{item.price},#{item.depositFee},#{item.remissionCourseFee},#{item.groupRemissionCourseFee},#{item.kitGroupPurchaseTypeJson},#{item.coursePurchaseTypeJson},#{item.organShareProfit},#{item.tenantId})
+            #{musicGroupId},#{item.subjectId},#{item.goodsIdList},now(),now(),#{item.price},#{item.depositFee},
+             #{item.remissionCourseFee},#{item.groupRemissionCourseFee},#{item.kitGroupPurchaseTypeJson},
+             #{item.coursePurchaseTypeJson},#{item.organShareProfit},#{item.tenantId})
         </foreach>
     </insert>
 

+ 5 - 0
mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml

@@ -537,6 +537,11 @@
         FROM sell_order
         WHERE order_id_ = #{orderId}
     </delete>
+    <delete id="deleteByOrderNo">
+        DELETE
+        FROM sell_order
+        WHERE order_no_ = #{orderNo}
+    </delete>
 
     <select id="getOrderSellCost" resultType="decimal">
         SELECT SUM(sell_cost_ * num_)

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

@@ -316,6 +316,11 @@
         FROM student_payment_order
         WHERE id_ = #{id}
     </delete>
+    <delete id="deleteByOrderNo">
+        DELETE
+        FROM student_payment_order
+        WHERE order_no_ = #{orderNo}
+    </delete>
 
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="PaymentOrderAndStudentInfo" parameterType="map">