Parcourir la source

Merge remote-tracking branch 'origin/zx_saas_goods' into zx_saas_goods

yuanliang il y a 1 an
Parent
commit
1d5d7a50da
21 fichiers modifiés avec 431 ajouts et 339 suppressions
  1. 22 16
      mec-application/src/main/java/com/ym/mec/web/controller/APIController.java
  2. 2 2
      mec-application/src/main/java/com/ym/mec/web/controller/GoodsController.java
  3. 2 2
      mec-application/src/main/java/com/ym/mec/web/controller/ImportController.java
  4. 3 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SellOrder.java
  5. 4 4
      mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java
  6. 3 0
      mec-biz/src/main/java/com/ym/mec/biz/service/SchoolService.java
  7. 10 2
      mec-biz/src/main/java/com/ym/mec/biz/service/SellOrderService.java
  8. 66 44
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java
  9. 7 10
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java
  10. 6 4
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentActivityServiceImpl.java
  11. 12 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SchoolServiceImpl.java
  12. 237 34
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java
  13. 9 9
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java
  14. 7 6
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java
  15. 5 3
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java
  16. 15 191
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java
  17. 14 5
      mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml
  18. 1 1
      mec-client-api/src/main/java/com/ym/mec/web/WebFeignService.java
  19. 1 1
      mec-client-api/src/main/java/com/ym/mec/web/fallback/WebFeignServiceFallback.java
  20. 1 1
      mec-common/common-core/src/main/java/com/ym/mec/common/dto/SchoolDto.java
  21. 4 4
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

+ 22 - 16
mec-application/src/main/java/com/ym/mec/web/controller/APIController.java

@@ -11,6 +11,7 @@ import com.ym.mec.biz.dal.page.StudentVipGroupQueryInfo;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.biz.service.impl.GoodsServiceImpl;
 import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.dto.SchoolDto;
 import com.ym.mec.common.entity.GoodsSubModel;
 import com.ym.mec.common.entity.GoodsSubStockModel;
 import com.ym.mec.common.entity.HttpResponseResult;
@@ -25,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
@@ -34,35 +36,34 @@ import java.util.Map;
 @Api(tags = "对外接口")
 @RestController
 public class APIController extends BaseController {
-	@Autowired
+	@Resource
 	private SysUserCashAccountDao sysUserCashAccountDao;
-	@Autowired
+	@Resource
 	private TeacherDao teacherDao;
-	@Autowired
+	@Resource
 	private EmployeeDao employeeDao;
-	@Autowired
+	@Resource
 	private PracticeLessonApplyService practiceLessonApplyService;
-	@Autowired
+	@Resource
 	private PracticeGroupService practiceGroupService;
-	@Autowired
+	@Resource
 	private ImGroupService imGroupService;
-	@Autowired
+	@Resource
 	private SysUserFeignService sysUserFeignService;
-	@Autowired
+	@Resource
 	private SysTenantConfigService sysTenantConfigService;
-	@Autowired
+	@Resource
 	private SysUserService sysUserService;
-	@Autowired
+	@Resource
 	private VipGroupService vipGroupService;
-
-	@Autowired
+	@Resource
 	private SysConfigService sysConfigService;
-
-	@Autowired
+	@Resource
 	private StudentPaymentOrderService studentPaymentOrderService;
-
-	@Autowired
+	@Resource
 	private GoodsService goodsService;
+	@Resource
+	private SchoolService schoolService;
 
 	@GetMapping("/createCashAccount")
 	public Boolean createCashAccount(Integer userId,Integer tenantId) {
@@ -253,4 +254,9 @@ public class APIController extends BaseController {
 	public HttpResponseResult<Boolean> goodsStockCountSynchronize(@RequestBody List<GoodsSubStockModel> goodsSubStockModels) {
 		return succeed(goodsService.goodsStockCountSynchronize(goodsSubStockModels));
 	}
+
+	@PostMapping("/schoolListByIds")
+	public HttpResponseResult<List<SchoolDto>> schoolListByIds(@RequestBody List<Integer> schoolIds) {
+		return succeed(schoolService.schoolListByIds(schoolIds));
+	}
 }

+ 2 - 2
mec-application/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -54,14 +54,14 @@ public class GoodsController extends BaseController {
         return succeed();
     }
 
-    @ApiOperation(value = "新增商品清单")
+/*    @ApiOperation(value = "新增商品清单")
     @PostMapping("/addGoodsProcurement")
     @PreAuthorize("@pcs.hasPermissions('goods/addGoodsProcurement')")
     public Object addGoodsProcurement(GoodsProcurement goodsProcurement){
         goodsProcurement.setOperatorId(sysUserService.getUserId());
         goodsService.addGoodsProcurement(goodsProcurement);
         return succeed();
-    }
+    }*/
 
     @ApiOperation(value = "删除商品(教材、辅件)")
     @PostMapping("/del/{id}")

+ 2 - 2
mec-application/src/main/java/com/ym/mec/web/controller/ImportController.java

@@ -60,12 +60,12 @@ public class ImportController extends BaseController {
     private StudentVisitService studentVisitService;
 
 
-    @ApiOperation(value = "导入商品")
+/*    @ApiOperation(value = "导入商品")
     @PostMapping(value = "goods")
     @PreAuthorize("@pcs.hasPermissions('import/goods')")
     public HttpResponseResult<List<Goods>> importGoods(@RequestParam("file") MultipartFile file) throws Exception {
         return succeed(goodsService.importGoods(file, sysUserService.getUserId()));
-    }
+    }*/
 
     @ApiOperation(value = "导入商品")
     @PostMapping(value = "goodsV2")

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

@@ -72,6 +72,9 @@ public class SellOrder{
     @ApiModelProperty(value="商品id")
     private Integer goodsId;
 
+    @ApiModelProperty(value="商品sku_id")
+    private Integer goodsSkuId;
+
     @ApiModelProperty(value="商品名称")
     private String goodsName;
 

+ 4 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -27,7 +27,7 @@ public interface GoodsService extends BaseService<Integer, Goods> {
 
     void addGoods(GoodsWrapper.Goods goods, Integer operatorId);
 
-    void addGoodsProcurement(GoodsProcurement goodsProcurement);
+//    void addGoodsProcurement(GoodsProcurement goodsProcurement);
 
     /**
      * @describe 更新商品状态
@@ -78,7 +78,7 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @param file:
      * @return java.util.List<com.ym.mec.biz.dal.entity.Goods>
      */
-    List<Goods> importGoods(MultipartFile file, Integer operatorId) throws Exception;
+//    List<Goods> importGoods(MultipartFile file, Integer operatorId) throws Exception;
 
     /**
      * 导入组合商品
@@ -105,7 +105,7 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @date 2020.10.13
      * @return void
      */
-    void sellOrderBatchNoAllot(Integer tenantId);
+//    void sellOrderBatchNoAllot(Integer tenantId);
 
     /**
      * @describe 扣减商品库存
@@ -124,7 +124,7 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @param sellOrderIds: 对应批次商品列表
      * @return void
      */
-    void increaseStock(List<SellOrder> sellOrderIds, AccountType accountType);
+//    void increaseStock(List<SellOrder> sellOrderIds, AccountType accountType);
 
     /**
      * @describe 获取辅件商品列表

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/SchoolService.java

@@ -2,6 +2,7 @@ package com.ym.mec.biz.service;
 
 import com.ym.mec.biz.dal.entity.School;
 import com.ym.mec.biz.dal.page.SchoolQueryInfo;
+import com.ym.mec.common.dto.SchoolDto;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 
@@ -47,4 +48,6 @@ public interface SchoolService extends BaseService<Integer, School> {
     PageInfo<School> queryPageDetail(SchoolQueryInfo queryInfo);
     
     List<School> querySchoolExportList(SchoolQueryInfo queryInfo);
+
+    List<SchoolDto> schoolListByIds(List<Integer> schoolIds);
 }

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

@@ -5,6 +5,7 @@ import com.ym.mec.biz.dal.entity.MusicGroup;
 import com.ym.mec.biz.dal.entity.SellOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
+import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
 import com.ym.mec.common.dto.OrderCreate;
 import com.ym.mec.common.service.BaseService;
 
@@ -24,7 +25,7 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
      * @param couponRemitFee 优惠券减免
      * @return
      */
-    List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance, BigDecimal couponRemitFee);
+//    List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance, BigDecimal couponRemitFee);
 
     /**
      * 将订单详情加入销售列表
@@ -33,7 +34,7 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
      * @param studentPaymentOrder
      * @return
      */
-    List<SellOrder> addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails, StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup,BigDecimal musicRemitFee);
+    List<SellOrder> addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails, StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup,BigDecimal balancePaymentAmount);
 
     void batchInsert(List<SellOrder> sellOrders);
 
@@ -83,4 +84,11 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
     List<OrderCreate.OrderItem> convertMallOrder(List<SellOrder> sellOrderList);
 
     void syncSellOrder2Mall(List<SellOrder> sellOrders, StudentPaymentOrder studentPaymentOrder);
+
+    void mallRefundByOrderId(List<SellOrder> sellOrders);
+
+    List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,Boolean saveFlag);
+
+    List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,
+                                  BigDecimal totalBalance, BigDecimal expectTotalAmount, BigDecimal couponRemitAmount, BigDecimal actualTotalAmount,Boolean saveFlag);
 }

+ 66 - 44
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -31,12 +31,7 @@ import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
 import com.ym.mec.biz.dal.page.GoodsQuery;
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
 import com.ym.mec.biz.dal.wrapper.GoodsWrapper;
-import com.ym.mec.biz.service.GoodsCategoryService;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.SysConfigService;
-import com.ym.mec.biz.service.SysMessageService;
-import com.ym.mec.biz.service.SysTenantConfigService;
-import com.ym.mec.biz.service.UploadFileService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.dto.BrandDto;
 import com.ym.mec.common.dto.PmsProductDto;
@@ -90,34 +85,31 @@ import java.util.stream.Collectors;
 public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implements GoodsService {
 	private static final Logger LOGGER = LoggerFactory.getLogger(CourseScheduleTeacherSalaryServiceImpl.class);
 
-	@Autowired
+	@Resource
 	private GoodsDao goodsDao;
-	@Autowired
+	@Resource
 	private UploadFileService uploadFileService;
-	@Autowired
+	@Resource
 	private IdGeneratorService idGeneratorService;
-	@Autowired
+	@Resource
 	private GoodsProcurementDao goodsProcurementDao;
-	@Autowired
+	@Resource
 	private SysTenantConfigService sysTenantConfigService;
-	@Autowired
+	@Resource
 	private SysMessageService sysMessageService;
-	@Autowired
+	@Resource
 	private TeacherDao teacherDao;
-	@Autowired
+	@Resource
 	private SellOrderDao sellOrderDao;
-	@Autowired
+	@Resource
 	private OrganizationDao organizationDao;
 	@Resource
 	private MallFeignService mallFeignService;
-
-	@Autowired
-	private GoodsSubMapper goodsSubMapper;
-
-	@Autowired
-	private GoodsCategoryService goodsCategoryService;
-
-	@Autowired
+    @Resource
+    private GoodsCategoryService goodsCategoryService;
+	@Resource
+	private GoodsSubService goodsSubService;
+	@Resource
 	private OssPluginContext ossPluginContext;
 	@Override
 	public BaseDAO<Integer, Goods> getDAO() {
@@ -240,10 +232,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		goodsDao.insert(goodsRecord);
 		List<GoodsSub> goodsSubs = JSON.parseArray(JSON.toJSONString(goodsSubList), GoodsSub.class);
 		goodsSubs.forEach(next -> next.setGoodsId(goodsRecord.getId()));
-		goodsSubMapper.saveBatch(goodsSubs);
+		goodsSubService.saveBatch(goodsSubs);
 	}
 
-	@Override
+	/*@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void addGoodsProcurement(GoodsProcurement goodsProcurement) {
 		Goods existsGood = goodsDao.get(goodsProcurement.getGoodsId());
@@ -273,7 +265,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		goodsProcurementDao.insert(goodsProcurement);
 
 		sellOrderBatchNoAllot(existsGood.getTenantId());
-	}
+	}*/
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
@@ -321,7 +313,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		// 从管乐迷商城组合的商品
 		QueryWrapper<GoodsSub> queryWrapper = new QueryWrapper<>();
 		queryWrapper.eq("goods_id_", goodsId);
-		List<GoodsSub> goodsSubs = goodsSubMapper.selectList(queryWrapper);
+		List<GoodsSub> goodsSubs = goodsSubService.getBaseMapper().selectList(queryWrapper);
 		if (goodsSubs.isEmpty()) {
 			return new ArrayList<>();
 		}
@@ -398,7 +390,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		return page;
 	}
 
-	@Override
+/*	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public List<Goods> importGoods(MultipartFile file, Integer operatorId) throws Exception {
 		Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
@@ -596,7 +588,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		sellOrderBatchNoAllot(TenantContextHolder.getTenantId());
 
 		return goodsList;
-	}
+	}*/
 
 
 	@Transactional(rollbackFor = Exception.class)
@@ -927,7 +919,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 				sub.setGoodsPrice(next.getGoodsPrice());
 				return sub;
 			}).collect(Collectors.toList());
-			goodsSubMapper.saveBatch(subList);
+            goodsSubService.saveBatch(subList);
 		}
 
 //		goodsGroup.forEach((key, value) -> {
@@ -988,7 +980,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		}
 	}
 
-	@Override
+/*	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public void sellOrderBatchNoAllot(Integer tenantId) {
 		List<Integer> noneBatchNoSellOrderIds = sellOrderDao.getNoneBatchNoSellOrderIds(tenantId);
@@ -1030,7 +1022,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		if(!CollectionUtils.isEmpty(updateSellOrders)){
 			sellOrderDao.batchUpdate(updateSellOrders);
 		}
-	}
+	}*/
 
 	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
@@ -1040,7 +1032,37 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		}
 
 		List<Goods> tempGoodsList = goodsDao.lockGoods(new ArrayList<>(goodsIds));
-		Map<Integer, Goods> idTempGoodsMap = tempGoodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
+		PmsProductQueryParamDto paramDto = new PmsProductQueryParamDto();
+		String skuIds = goodsSubService.lambdaQuery().in(GoodsSub::getGoodsId, tempGoodsList.stream().map(Goods::getId).collect(Collectors.toList())).list()
+				.stream().map(e->e.getSku().toString()).collect(Collectors.joining(","));
+		paramDto.setSkuStockIds(skuIds);
+		PageInfo<PmsProductDto> productList = mallFeignService.getProductList(paramDto);
+		if (CollectionUtils.isEmpty(productList.getRows())) {
+			throw new BizException("商品不存在");
+		}
+		Map<Integer,PmsProductDto> skuIdProductMap = productList.getRows().stream().collect(Collectors.toMap(PmsProductDto::getSkuStockId, Function.identity()));
+		List<SellOrder> sellOrders = new ArrayList<>();
+		for (Goods goods : tempGoodsList) {
+			List<GoodsSub> goodsSubs = goodsSubService.lambdaQuery().eq(GoodsSub::getGoodsId, goods.getId()).list();
+			if(CollectionUtils.isEmpty(goodsSubs)){
+				throw new BizException("商品["+goods.getName()+"]未设置子商品");
+			}
+			for (GoodsSub goodsSub : goodsSubs) {
+				PmsProductDto productDto = skuIdProductMap.get(goodsSub.getSku());
+				if(Objects.isNull(productDto)){
+					throw new BizException("商品["+goods.getName()+"]子商品["+goodsSub.getSku()+"]不存在");
+				}
+				SellOrder sellOrder = new SellOrder();
+				sellOrder.setParentGoodsId(goods.getId());
+				sellOrder.setGoodsSkuId(goodsSub.getSku());
+				sellOrder.setNum(1);
+				sellOrder.setGoodsName(productDto.getName());
+				sellOrder.setAccountType(accountType);
+				sellOrder.setOrganSellCost(goodsSub.getGoodsPrice());
+				sellOrders.add(sellOrder);
+			}
+		}
+		/*Map<Integer, Goods> idTempGoodsMap = tempGoodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
 		List<GoodsProcurement> goodsProcurements = new ArrayList<>();
 		for (Integer goodsId : goodsIds) {
 			Goods tempGoods = idTempGoodsMap.get(goodsId);
@@ -1155,12 +1177,12 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 				}
 				sellOrders.add(sellOrder);
 			}
-		}
+		}*/
 
 		return sellOrders;
 	}
 
-	@Override
+/*	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public void increaseStock(List<SellOrder> sellOrders, AccountType accountType) {
 		if(CollectionUtils.isEmpty(sellOrders)){
@@ -1194,10 +1216,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			}
 			goods.setSellCount(new AtomicInteger(goods.getSellCount()).addAndGet(-sellOrder.getNum()));
 
-//			goodsDao.update(goods);
-//			goodsProcurementDao.update(goodsProcurement);
+			goodsDao.update(goods);
+			goodsProcurementDao.update(goodsProcurement);
 		}
-	}
+	}*/
 
 	@Override
 	public List<GoodsSellDto> queryGoodsSellDtos(String goodsId) {
@@ -1258,11 +1280,11 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			goodsInfo.setComplementGoodsIdList(null);
 			UpdateWrapper<GoodsSub> delWrapper = new UpdateWrapper<>();
 			delWrapper.eq("goods_id_", goods.getId());
-			goodsSubMapper.delete(delWrapper);
+			goodsSubService.getBaseMapper().delete(delWrapper);
 
 			List<GoodsSub> goodsSubs = JSON.parseArray(JSON.toJSONString(goodsSubList), GoodsSub.class);
 			goodsSubs.forEach(next -> next.setGoodsId(goods.getId()));
-			goodsSubMapper.saveBatch(goodsSubs);
+			goodsSubService.saveBatch(goodsSubs);
 
 			BigDecimal organCostPrice = goodsSubList.stream().map(GoodsWrapper.GoodsSub::getGoodsPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 			goodsInfo.setOrganCostPrice(organCostPrice);
@@ -1311,7 +1333,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		List<Integer> skuIds = goodsSubModelList.stream().map(GoodsSubModel::getSkuId).distinct().collect(Collectors.toList());
 		QueryWrapper<GoodsSub> queryWrapper = new QueryWrapper<>();
 		queryWrapper.in("sku_", skuIds);
-		List<GoodsSub> goodsSubs = goodsSubMapper.selectList(queryWrapper);
+		List<GoodsSub> goodsSubs = goodsSubService.getBaseMapper().selectList(queryWrapper);
 		if (CollectionUtils.isEmpty(goodsSubs)) {
 			return true;
 		}
@@ -1325,7 +1347,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			goodsDao.updateStatus(goodIdList, false);
 		}
 		Map<Boolean, List<Integer>> listMap = goodsSubList.stream().collect(Collectors.groupingBy(GoodsSub::getGoodsStatus, Collectors.mapping(GoodsSub::getId, Collectors.toList())));
-		listMap.forEach((key, values) -> goodsSubMapper.updateStatus(values, key));
+		listMap.forEach((key, values) -> goodsSubService.getBaseMapper().updateStatus(values, key));
 		log.info(Thread.currentThread().getName() + "同步商品状态完成");
 		return true;
 	}
@@ -1345,7 +1367,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 		QueryWrapper<GoodsSub> queryWrapper = new QueryWrapper<>();
 		queryWrapper.in("sku_", skus);
-		List<GoodsSub> goodsSubs = goodsSubMapper.selectList(queryWrapper);
+		List<GoodsSub> goodsSubs = goodsSubService.getBaseMapper().selectList(queryWrapper);
 		if (CollectionUtils.isEmpty(goodsSubs)) {
 			return true;
 		}
@@ -1357,7 +1379,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 		queryWrapper = new QueryWrapper<>();
 		queryWrapper.in("goods_id_", goodIds);
-		List<GoodsSub> allGoodsSubs = goodsSubMapper.selectList(queryWrapper);
+		List<GoodsSub> allGoodsSubs = goodsSubService.getBaseMapper().selectList(queryWrapper);
 		List<String> allSkuIdList = allGoodsSubs.stream().map(next -> next.getSku().toString()).distinct().collect(Collectors.toList());
 		PmsProductQueryParamDto dto = new PmsProductQueryParamDto();
 		dto.setSkuStockIds(String.join(",", allSkuIdList));

+ 7 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -257,16 +257,6 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 
         SysUser sysUser = sysUserService.getUser();
 
-        // 不是进行中,只能创建一次缴费
-        if (musicGroup.getStatus() != MusicGroupStatusEnum.PROGRESS) {
-            List<MusicGroupPaymentCalender> list = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
-            if (list.size() > 0) {
-                //排除商品采购
-                if(list.stream().anyMatch(e -> e.getPaymentType() != GOODS_PURCHASE)){
-                    throw new BizException("创建失败,已经存在缴费信息");
-                }
-            }
-        }
         //进行中加学员拓展信息
         CalenderAddStudent calenderAddStudent = musicGroupPaymentBaseCalender.getCalenderAddStudent();
         MusicGroupPaymentCalender musicGroupPaymentCalender = new MusicGroupPaymentCalender();
@@ -295,6 +285,13 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                     }
                 }
             }
+            // 不是进行中,只能创建一次缴费
+            if (musicGroup.getStatus() != MusicGroupStatusEnum.PROGRESS && musicGroupPaymentCalender.getPaymentType() != GOODS_PURCHASE) {
+                List<MusicGroupPaymentCalender> list = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
+                if (list.size() > 0) {
+                    throw new BizException("创建失败,已经存在缴费信息");
+                }
+            }
         }
         musicGroupPaymentBaseCalender.setMusicGroup(musicGroup);
 

+ 6 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentActivityServiceImpl.java

@@ -485,7 +485,10 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
                 sysUserCashAccountDetailService.insert(paymentDetail);
             }
             //添加sell_order
-            this.addSellOrder(studentPaymentOrder, replacementInstrumentActivity);
+//            this.addSellOrder(studentPaymentOrder, replacementInstrumentActivity);
+            List<Integer> goodsIds = new ArrayList<>();
+            goodsIds.add(replacementInstrumentActivity.getInstrumentsId());
+            sellOrderService.initSellOrder(studentPaymentOrder,null,goodsIds,null);
             try {
                 contractService.transferProduceContract(userId, null, studentPaymentOrder.getType());
             } catch (Exception e) {
@@ -554,7 +557,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
         pageInfo.setRows(dataList);
         return pageInfo;
     }
-
+/*
     private List<SellOrder> addSellOrder(StudentPaymentOrder order, ReplacementInstrumentActivity replacementInstrumentActivity) {
         if (replacementInstrumentActivity.getGoodsId() == null) {
             return null;
@@ -574,7 +577,6 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
         List<Integer> goodsIds = new ArrayList<>();
         goodsIds.add(goods.getId());
         List<SellOrder> sellOrders = goodsService.subtractStock(goodsIds, accountType);
-
         BigDecimal hasRouteSellOrderExpectAmount = BigDecimal.ZERO; //已分配预计金额
         BigDecimal hasRouteSellOrderBalance = BigDecimal.ZERO; //已分配余额
 
@@ -616,7 +618,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
             sellOrderService.syncSellOrder2Mall(sellOrders,order);
         }
         return sellOrders;
-    }
+    }*/
 
     @Transactional(rollbackFor = Exception.class)
     public void resultSync() {

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SchoolServiceImpl.java

@@ -6,6 +6,7 @@ import com.ym.mec.biz.dal.entity.School;
 import com.ym.mec.biz.dal.page.SchoolQueryInfo;
 import com.ym.mec.biz.service.SchoolService;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.dto.SchoolDto;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
@@ -76,4 +77,15 @@ public class SchoolServiceImpl extends BaseServiceImpl<Integer, School>  impleme
 	public List<School> querySchoolExportList(SchoolQueryInfo queryInfo) {
 		return schoolDao.querySchoolExportList(queryInfo);
 	}
+
+    @Override
+    public List<SchoolDto> schoolListByIds(List<Integer> schoolIds) {
+		List<School> schools = schoolDao.getSchools(schoolIds);
+		return schools.stream().map(e -> {
+			SchoolDto schoolDto = new SchoolDto();
+			schoolDto.setId(e.getId());
+			schoolDto.setName(e.getName());
+			return schoolDto;
+		}).collect(Collectors.toList());
+    }
 }

+ 237 - 34
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -2,14 +2,13 @@ package com.ym.mec.biz.service.impl;
 
 
 import static com.ym.mec.biz.dal.enums.GroupType.GOODS_SELL;
+import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.*;
+import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.ORGAN_SHARE_PROFIT;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import com.alibaba.fastjson.JSON;
@@ -19,7 +18,11 @@ import com.ym.mec.biz.dal.mapper.GoodsSubMapper;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.api.CommonResult;
 import com.ym.mec.common.dto.OrderCreate;
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
+import com.ym.mec.common.dto.ReturnApplyDto;
 import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.mall.MallFeignService;
 import org.apache.commons.collections.CollectionUtils;
@@ -82,7 +85,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     }
 
 
-    @Override
+ /*   @Override
     @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
     public List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance, BigDecimal couponRemitFee) {
         if (goodsIds == null || goodsIds.size() <= 0) {
@@ -262,37 +265,65 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         }
         return sellOrderList;
     }
-
+*/
     @Override
-    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+    @Transactional(rollbackFor = Exception.class)
     public List<SellOrder> addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails,
-                                                    StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup,BigDecimal musicRemitFee) {
-        Integer tenantId = studentPaymentOrder.getTenantId();
-        List<SellOrder> sellOrders = new ArrayList<>();
-        //总余额支付
-        BigDecimal totalBalance = studentPaymentOrder.getBalancePaymentAmount() != null ? studentPaymentOrder.getBalancePaymentAmount() : BigDecimal.ZERO;
-        //总价格
-        BigDecimal totalPrice = studentPaymentOrder.getExpectAmount();
-        //商品总付款
-        BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
-        //商品销售占的余额
-        BigDecimal detailTotalBalance = detailTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
-                detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_DOWN);
-
-        int i = 1;
-        BigDecimal detailRouteBalance = BigDecimal.ZERO;
+                                                    StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup,BigDecimal balancePaymentAmount) {
+        //过去非商品详情
+        List<StudentPaymentOrderDetail> goodsOrderDetails = orderDetails.stream().filter(e -> StringUtils.isEmpty(e.getGoodsIdList())).collect(Collectors.toList());
+        if(CollectionUtils.isEmpty(goodsOrderDetails)){
+            throw new BizException("商品详情为空");
+        }
+        //获取总减免金额
+        BigDecimal detailTotalRemitPrice = goodsOrderDetails.stream().map(StudentPaymentOrderDetail::getRemitFee).reduce(BigDecimal.ZERO, BigDecimal::add);
+        //获取总金额
+        BigDecimal detailTotalPrice = goodsOrderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 
-        AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(studentPaymentOrder.getPaymentChannel()), studentPaymentOrder.getMerNos(), tenantId);
+        List<SellOrder> sellOrders = new ArrayList<>();
 
-        for (StudentPaymentOrderDetail orderDetail : orderDetails) {
-            BigDecimal detailBalance = orderDetail.getPrice().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
-                    orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice, 2, BigDecimal.ROUND_DOWN);
-            if (i == orderDetails.size()) {
-                detailBalance = detailTotalBalance.subtract(detailRouteBalance);
+        //剩余待分配的余额
+        BigDecimal subDetailBalance = balancePaymentAmount;
+        //剩余待分配的优惠券金额
+        BigDecimal subDetailCouponRemitFee = detailTotalRemitPrice;
+        //剩余待分配现金
+        BigDecimal subDetailActualAmount = detailTotalPrice.subtract(balancePaymentAmount);
+        for (int i = 0; i < goodsOrderDetails.size(); i++) {
+            StudentPaymentOrderDetail orderDetail = orderDetails.get(i);
+            //获取支付金额比例
+            BigDecimal ratioAmount = orderDetail.getPrice().divide(detailTotalPrice, 6, BigDecimal.ROUND_HALF_UP);
+            //获取优惠券金额比例
+            BigDecimal ratioCouponAmount = orderDetail.getRemitFee().divide(detailTotalRemitPrice, 6, BigDecimal.ROUND_HALF_UP);
+            //获取分配的余额
+            BigDecimal detailBalance;
+            //获取分配的优惠券金额
+            BigDecimal couponRemitFee;
+            //获取剩余待分配的现金
+            BigDecimal detailActualAmount;
+            if (i == goodsOrderDetails.size() - 1) {
+                //获取分配的余额
+                detailBalance = subDetailBalance;
+                //获取分配的优惠券金额
+                couponRemitFee = subDetailCouponRemitFee;
+                //获取剩余待分配的现金
+                detailActualAmount = subDetailActualAmount;
+            } else {
+                //获取分配的余额
+                detailBalance = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_DOWN);
+                subDetailBalance = subDetailBalance.subtract(detailBalance);
+                //获取分配的优惠券金额
+                couponRemitFee = orderDetail.getRemitFee().multiply(ratioCouponAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+                subDetailCouponRemitFee = subDetailCouponRemitFee.subtract(couponRemitFee);
+                //获取剩余待分配的现金
+                detailActualAmount = orderDetail.getPrice().subtract(detailBalance);
+                subDetailActualAmount = subDetailActualAmount.subtract(detailActualAmount);
             }
-            detailRouteBalance = detailRouteBalance.add(detailBalance);
-            i++;
+            List<Integer> goodsIds = Arrays.asList(orderDetail.getGoodsIdList().split(",")).stream().map(Integer::parseInt).collect(Collectors.toList());
+            sellOrders.addAll(this.initSellOrder(studentPaymentOrder, musicGroup.getId(), goodsIds, null,
+                    detailBalance, orderDetail.getPrice(), couponRemitFee, detailActualAmount, false));
+        }
 
+/*
             BigDecimal goodsTotalPrice = orderDetail.getGoodsList().stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
             BigDecimal routePrice = BigDecimal.ZERO;
             BigDecimal routeBalance = BigDecimal.ZERO;
@@ -416,7 +447,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 }
             }
             sellOrderDao.batchInsert(sellOrders);
-        }
+        }*/
         return sellOrders;
     }
 
@@ -456,13 +487,16 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             }
         }
         //3、退货
-        if (sellOrders.get(0).getAccountType() != null) {
+        /*if (sellOrders.get(0).getAccountType() != null) {
             goodsService.increaseStock(sellOrders, sellOrders.get(0).getAccountType());
-        }
+        }*/
+        //4退货同步到商城
+        this.mallRefundByOrderId(sellOrders);
         return sellOrders;
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public List<SellOrder> refundByOrderId(Long orderId, Boolean reBackFee) {
         List<SellOrder> sellOrders = sellOrderDao.getSellOrderByParentGoodsId(orderId, null);
         if (sellOrders.size() <= 0) {
@@ -576,6 +610,175 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         }
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void mallRefundByOrderId(List<SellOrder> sellOrders) {
+        String skuIds = sellOrders.stream().map(e -> e.getGoodsSkuId().toString()).collect(Collectors.joining(","));
+        ReturnApplyDto returnApply = new ReturnApplyDto();
+        returnApply.setOrderSn(sellOrders.get(0).getOrderNo());
+        returnApply.setReason("管乐迷商品更换退货");
+        returnApply.setSkuIds(skuIds);
+        CommonResult<Boolean> result = mallFeignService.returnApply(returnApply);
+        if (result.getCode() != 200){
+            throw new BizException("商城订单退货失败",result.getMessage());
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,
+                                         BigDecimal totalBalance, BigDecimal expectTotalAmount, BigDecimal couponRemitAmount, BigDecimal actualTotalAmount,Boolean saveFlag) {
+        //可用优惠券金额
+        BigDecimal subCouponRemitAmount = couponRemitAmount;
+        //可用总金额
+        BigDecimal subExpectTotalAmount = expectTotalAmount;
+        //可用总余额
+        BigDecimal subTotalBalance = totalBalance;
+        //实际金额
+        BigDecimal subTotalActualAmount = actualTotalAmount;
+        Integer tenantId = order.getTenantId();
+        MusicGroup musicGroup = new MusicGroup();
+        if (StringUtils.isNotBlank(musicGroupId)) {
+            musicGroup = musicGroupDao.get(musicGroupId);
+        }
+        List<Goods> goodies = goodsDao.getGoodies(goodsIds);
+        BigDecimal goodsTotalPrice = goodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(order.getPaymentChannel()), order.getMerNos(), order.getTenantId());
+        PmsProductQueryParamDto paramDto = new PmsProductQueryParamDto();
+        String skuIds = goodsSubService.lambdaQuery().in(GoodsSub::getGoodsId, goodies.stream().map(Goods::getId).collect(Collectors.toList())).list()
+                .stream().map(e->e.getSku().toString()).collect(Collectors.joining(","));
+        paramDto.setSkuStockIds(skuIds);
+        PageInfo<PmsProductDto> productList = mallFeignService.getProductList(paramDto);
+        if (org.springframework.util.CollectionUtils.isEmpty(productList.getRows())) {
+            throw new BizException("商城商品不存在");
+        }
+        Map<Integer,PmsProductDto> skuIdProductMap = productList.getRows().stream().collect(Collectors.toMap(PmsProductDto::getSkuStockId, Function.identity()));
+        List<SellOrder> sellOrderList = new ArrayList<>();
+        for (int i = 0; i < goodies.size(); i++) {
+            Goods nowGoods = goodies.get(i);
+            //获取比例
+            BigDecimal goodsRatioAmount = BigDecimal.ZERO;
+            //预计金额
+            BigDecimal expectAmount;
+            //余额
+            BigDecimal goodsBalance;
+            //减免金额
+            BigDecimal remitAmount;
+            //实际金额
+            BigDecimal actualAmount;
+
+            if (goodsTotalPrice.compareTo(BigDecimal.ZERO) > 0) {
+                goodsRatioAmount = nowGoods.getGroupPurchasePrice().divide(goodsTotalPrice, 6, RoundingMode.HALF_UP);
+            }
+            if(i == goodies.size() - 1){
+                expectAmount = subExpectTotalAmount;
+                goodsBalance = subTotalBalance;
+                remitAmount = subCouponRemitAmount;
+                actualAmount = subTotalActualAmount;
+            }else {
+                expectAmount = goodsRatioAmount.multiply(expectTotalAmount).setScale(2, RoundingMode.HALF_UP);
+                subExpectTotalAmount = subExpectTotalAmount.subtract(expectAmount);
+                goodsBalance = goodsRatioAmount.multiply(totalBalance).setScale(2, RoundingMode.HALF_UP);
+                subTotalBalance = subTotalBalance.subtract(goodsBalance);
+                remitAmount = goodsRatioAmount.multiply(couponRemitAmount).setScale(2, RoundingMode.HALF_UP);
+                subCouponRemitAmount = subCouponRemitAmount.subtract(remitAmount);
+                actualAmount = expectAmount.subtract(goodsBalance).subtract(remitAmount);
+                subTotalActualAmount = subTotalActualAmount.subtract(actualAmount);
+            }
+            //剩余预计金额
+            BigDecimal subExpectAmount = expectAmount;
+            //剩余余额
+            BigDecimal subGoodsBalance = goodsBalance;
+            //剩余减免金额
+            BigDecimal subRemitAmount = remitAmount;
+            //剩余实际金额
+            BigDecimal subActualAmount = actualAmount;
+            //租赁、免费的没有销售收入,有销售成本
+            if (nowGoods.getType().equals(GoodsType.INSTRUMENT) && (kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.LEASE) || kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.FREE))) {
+                goodsBalance = BigDecimal.ZERO;
+                expectAmount = BigDecimal.ZERO;
+            }
+
+            List<GoodsSub> goodsSubs = goodsSubService.lambdaQuery().eq(GoodsSub::getGoodsId, nowGoods.getId()).list();
+            //商品原始总价
+            BigDecimal complementPrice = goodsSubs.stream().map(GoodsSub::getGoodsPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+            //生成sellOrder
+            for (int j = 0; j < goodsSubs.size(); j++) {
+                GoodsSub goodsSub = goodsSubs.get(j);
+                PmsProductDto productDto = skuIdProductMap.get(goodsSub.getSku());
+                if(Objects.isNull(productDto)){
+                    throw new BizException("商品["+nowGoods.getName()+"]子商品["+goodsSub.getSku()+"]不存在");
+                }
+                SellOrder sellOrder = new SellOrder();
+                //获取比例
+                BigDecimal ratioAmount = goodsSub.getGoodsPrice().divide(complementPrice, 6, RoundingMode.HALF_UP);
+                if (j == goodsSubs.size() - 1){
+                    sellOrder.setExpectAmount(subExpectAmount);
+                    sellOrder.setBalanceAmount(subGoodsBalance);
+                    sellOrder.setActualAmount(subActualAmount);
+                    sellOrder.setCouponRemitAmount(subRemitAmount);
+                }else {
+                    BigDecimal decimal = expectAmount.multiply(ratioAmount).setScale(2, RoundingMode.HALF_UP);
+                    sellOrder.setExpectAmount(decimal);
+                    subExpectAmount = subExpectAmount.subtract(decimal);
+                    BigDecimal balance = goodsBalance.multiply(ratioAmount).setScale(2, RoundingMode.HALF_UP);
+                    sellOrder.setBalanceAmount(balance);
+                    subGoodsBalance = subGoodsBalance.add(balance);
+                    BigDecimal actual = actualAmount.multiply(ratioAmount).setScale(2, RoundingMode.HALF_UP);
+                    sellOrder.setActualAmount(actual);
+                    subActualAmount = subActualAmount.subtract(actual);
+                    BigDecimal remit = remitAmount.multiply(ratioAmount).setScale(2, RoundingMode.HALF_UP);
+                    sellOrder.setCouponRemitAmount(remit);
+                    subRemitAmount = subRemitAmount.subtract(remit);
+                }
+                sellOrder.setParentGoodsId(nowGoods.getId());
+                sellOrder.setGoodsSkuId(goodsSub.getSku());
+                sellOrder.setNum(1);
+                sellOrder.setGoodsName(productDto.getName());
+                sellOrder.setAccountType(accountType);
+                sellOrder.setOrganSellCost(goodsSub.getGoodsPrice());
+                sellOrder.setOrganId(order.getOrganId());
+                sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
+                sellOrder.setEduTeacherId(musicGroup.getEducationalTeacherId());
+                sellOrder.setTransNo(order.getTransNo());
+                sellOrder.setOrderId(order.getId());
+                sellOrder.setOrderNo(order.getOrderNo());
+                sellOrder.setUserId(order.getUserId());
+                sellOrder.setPaymentChannel(order.getPaymentChannel());
+                sellOrder.setMerNo(order.getMerNos());
+                sellOrder.setSellTime(order.getCreateTime());
+                sellOrder.setTenantId(tenantId);
+                if (nowGoods.getType().equals(GoodsType.INSTRUMENT)) {
+                    sellOrder.setType(SellTypeEnum.INSTRUMENT);
+                } else if (nowGoods.getType().equals(GoodsType.ACCESSORIES)) {
+                    sellOrder.setType(SellTypeEnum.ACCESSORIES);
+                } else {
+                    sellOrder.setType(SellTypeEnum.OTHER);
+                }
+                sellOrderList.add(sellOrder);
+            }
+        }
+        if (saveFlag && !org.springframework.util.CollectionUtils.isEmpty(sellOrderList)) {
+            this.batchInsert(sellOrderList);
+            this.syncSellOrder2Mall(sellOrderList,order);
+        }
+        return sellOrderList;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,Boolean saveFlag) {
+        BigDecimal totalBalance = order.getBalancePaymentAmount();
+        if (totalBalance == null) {
+            totalBalance = BigDecimal.ZERO;
+        }
+        BigDecimal expectTotalAmount = order.getExpectAmount();
+        BigDecimal couponRemitAmount = order.getCouponRemitFee();
+        BigDecimal actualTotalAmount = order.getActualAmount();
+        return this.initSellOrder(order, musicGroupId, goodsIds, kitGroupPurchaseType, totalBalance, expectTotalAmount, couponRemitAmount, actualTotalAmount,saveFlag==null?true:saveFlag);
+    }
+
     public Map<String, BigDecimal> calcSellAmount(StudentPaymentOrder order,BigDecimal cloudBalanceIncome,BigDecimal cloudIncome) {
         List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetail(order.getId());
         //总余额支付

+ 9 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -637,7 +637,6 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
         //SurplusCourseFee
         Integer userId = studentPaymentOrder.getUserId();
         Long orderId = studentPaymentOrder.getId();
-        String musicGroupId = musicGroup.getId();
         Integer tenantId = studentPaymentOrder.getTenantId();
         List<StudentPaymentOrderDetail> allDetails = this.findByOrderId(orderId);
         BigDecimal courseFee = allDetails.stream().filter(o -> !(o.getType() == MUSICAL)
@@ -689,29 +688,30 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
 
         //销售订单详情
         if (allDetails.size() > 0 && (detailTypeEnums.contains(MUSICAL) || detailTypeEnums.contains(ACCESSORIES) || detailTypeEnums.contains(TEACHING))) {
-            BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
-            if (couponRemitFee.compareTo(BigDecimal.ZERO) > 0) {
+            BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount();
+            if (balancePaymentAmount.compareTo(BigDecimal.ZERO) > 0) {
                 BigDecimal musicFee = allDetails.stream()
                         .filter(o -> o.getType() == MUSICAL || o.getType() == ACCESSORIES || o.getType() == TEACHING)
                         .map(StudentPaymentOrderDetail::getPrice)
                         .reduce(BigDecimal.ZERO, BigDecimal::add);
                 BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
-                
+
 				BigDecimal organShareProfit = allDetails.stream().filter(o -> o.getType() == ORGAN_SHARE_PROFIT).map(StudentPaymentOrderDetail::getPrice)
 						.reduce(BigDecimal.ZERO, BigDecimal::add);
-				
+
 				if(organShareProfit != null){
 					expectAmount = expectAmount.subtract(organShareProfit);
 				}
-                
                 //获取比例
                 BigDecimal ratioAmount = musicFee.divide(expectAmount, 6, BigDecimal.ROUND_HALF_UP);
                 //获取分配的减免金额
-                couponRemitFee = couponRemitFee.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+                balancePaymentAmount = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
             }
-            List<SellOrder> sellOrders = sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup, couponRemitFee);
+            List<SellOrder> sellOrders = sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup, balancePaymentAmount);
+            sellOrderService.batchInsert(sellOrders);
+            sellOrderService.syncSellOrder2Mall(sellOrders, studentPaymentOrder);
             //同步销售订单到商城
-            sellOrderService.syncSellOrder2Mall(sellOrders,studentPaymentOrder);
+//            sellOrderService.syncSellOrder2Mall(sellOrders,studentPaymentOrder);
         }
 
         //活动小课包处理

+ 7 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -250,9 +250,10 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                         goodsIdList.add(goodsId);
                     }
                 }
-                List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
-
-                int i = 1;
+//                List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
+                List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, null, goodsIdList, null, false);
+                sellOrderService.batchInsert(sellOrders);
+                /*int i = 1;
                 for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
                     Integer goodsId = Integer.parseInt(goodsMap.getKey());
                     Integer nums = Integer.parseInt(goodsMap.getValue().toString());
@@ -312,8 +313,8 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                         sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
                     }
                 }
-                sellOrderDao.batchInsert(sellOrderList);
-                if(calender != null && calender.getPaymentType() != MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
+                sellOrderDao.batchInsert(sellOrderList);*/
+                if(calender == null || calender.getPaymentType() != MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
                     OrderCreate mallOrder = new OrderCreate();
                     mallOrder.setOrchestraId(studentPaymentOrder.getMusicGroupId());
                     mallOrder.setStatus(3);
@@ -339,7 +340,7 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                     if(studentPaymentRouteOrder.getType() == OrderTypeEnum.OTHER){
                         mallOrder.setSourceType(4);
                     }
-                    List<OrderCreate.OrderItem> items = sellOrderService.convertMallOrder(sellOrderList);
+                    List<OrderCreate.OrderItem> items = sellOrderService.convertMallOrder(sellOrders);
                     mallOrder.setOrderItemList(items);
                     CommonResult<Boolean> result = mallFeignService.productOrderCreate(mallOrder);
                     if (result.getCode() != 200) {

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

@@ -1530,12 +1530,14 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 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(),
+                    /*List<SellOrder> sellOrders = sellOrderService.addSellOrder(studentPaymentOrder.getId(),
                             null,
                             goodsIds,
                             studentPaymentOrder.getExpectAmount().add(repairInfo.getExemptionAmount()),
-                            studentPaymentOrder.getBalancePaymentAmount(), couponRemitFee);
-                    sellOrderService.syncSellOrder2Mall(sellOrders, studentPaymentOrder);
+                            studentPaymentOrder.getBalancePaymentAmount(), couponRemitFee);*/
+                    studentPaymentOrder.setExpectAmount(studentPaymentOrder.getExpectAmount().add(repairInfo.getExemptionAmount()));
+                    studentPaymentOrder.setCouponRemitFee(couponRemitFee);
+                    sellOrderService.initSellOrder(studentPaymentOrder,null,goodsIds,null);
                 }
             }
 

+ 15 - 191
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -4,18 +4,17 @@ import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
 import static com.ym.mec.biz.dal.enums.GroupType.SUBJECT_CHANGE;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.math.RoundingMode;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.service.*;
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
+import com.ym.mec.mall.MallFeignService;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,20 +37,6 @@ import com.ym.mec.biz.dal.dao.SubjectChangeDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dao.SysUserCashAccountLogDao;
 import com.ym.mec.biz.dal.dto.SubjectChangeParamDto;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.GoodsProcurement;
-import com.ym.mec.biz.dal.entity.MusicGroup;
-import com.ym.mec.biz.dal.entity.MusicGroupPurchaseList;
-import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan;
-import com.ym.mec.biz.dal.entity.SellOrder;
-import com.ym.mec.biz.dal.entity.Student;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
-import com.ym.mec.biz.dal.entity.StudentRegistration;
-import com.ym.mec.biz.dal.entity.SubjectChange;
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
-import com.ym.mec.biz.dal.entity.SysUserCashAccountLog;
 import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.CouponDetailTypeEnum;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
@@ -68,23 +53,6 @@ import com.ym.mec.biz.dal.enums.SellTypeEnum;
 import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
 import com.ym.mec.biz.dal.enums.SubjectChangeStatusEnum;
 import com.ym.mec.biz.dal.page.SubjectChangeQueryInfo;
-import com.ym.mec.biz.service.ContractService;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
-import com.ym.mec.biz.service.PayService;
-import com.ym.mec.biz.service.SellOrderService;
-import com.ym.mec.biz.service.StudentInstrumentService;
-import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
-import com.ym.mec.biz.service.StudentRegistrationService;
-import com.ym.mec.biz.service.SubjectChangeService;
-import com.ym.mec.biz.service.SysConfigService;
-import com.ym.mec.biz.service.SysCouponCodeService;
-import com.ym.mec.biz.service.SysMessageService;
-import com.ym.mec.biz.service.SysPaymentConfigService;
-import com.ym.mec.biz.service.SysUserCashAccountDetailService;
-import com.ym.mec.biz.service.SysUserCashAccountService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
@@ -93,6 +61,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import org.springframework.util.CollectionUtils;
 
 @Service
 public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectChange> implements SubjectChangeService {
@@ -155,6 +124,10 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
     private SysUserCashAccountLogDao sysUserCashAccountLogDao;
     @Autowired
     private GoodsProcurementDao goodsProcurementDao;
+    @Autowired
+    private GoodsSubService goodsSubService;
+    @Autowired
+    private MallFeignService mallFeignService;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -1048,7 +1021,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());
-                //TODO 退原订单商品
+                //处理退货
                 if (subjectChange.getOriginalOrderId() != null) {
                     sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue(), false);
                 }
@@ -1286,155 +1259,6 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
         if (goodsIds == null || goodsIds.size() <= 0) {
             return null;
         }
-        BigDecimal balance = order.getBalancePaymentAmount();
-        if (balance == null) {
-            balance = BigDecimal.ZERO;
-        }
-        Long orderId = order.getId();
-        BigDecimal totalAmount = order.getExpectAmount();
-        BigDecimal couponRemitAmount = order.getCouponRemitFee();
-        Integer tenantId = order.getTenantId();
-        MusicGroup musicGroup = new MusicGroup();
-        if (StringUtils.isNotBlank(musicGroupId)) {
-            musicGroup = musicGroupDao.get(musicGroupId);
-        }
-        int goodsNum = goodsIds.size();
-        BigDecimal goodsTotalPrice = BigDecimal.ZERO;
-        List<Goods> goodies = goodsDao.getGoodies(goodsIds);
-        int i = 1;
-        for (Integer goodsId : goodsIds) {
-            for (Goods goods : goodies) {
-                if (goods.getId().equals(goodsId)) {
-                    goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice());
-                    break;
-                }
-            }
-        }
-
-        BigDecimal hasRouteBalance = BigDecimal.ZERO;
-        BigDecimal hasRouteExpectAmount = BigDecimal.ZERO;
-
-        AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(order.getPaymentChannel()), order.getMerNos(), order.getTenantId());
-        List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
-
-        for (Integer goodsId : goodsIds) {
-            BigDecimal goodsPrice = BigDecimal.ZERO;
-            Goods nowGoods = new Goods();
-            for (Goods goods : goodies) {
-                if (goods.getId().equals(goodsId)) {
-                    nowGoods = goods;
-                    break;
-                }
-            }
-            goodsPrice = nowGoods.getGroupPurchasePrice();
-            BigDecimal expectAmount = BigDecimal.ZERO;
-            BigDecimal goodsBalance = BigDecimal.ZERO;
-
-            if (goodsTotalPrice.compareTo(BigDecimal.ZERO) > 0) {
-                goodsBalance = balance.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
-                expectAmount = totalAmount.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
-            }
-            if (i == goodsNum) {
-                goodsBalance = balance.subtract(hasRouteBalance);
-                expectAmount = totalAmount.subtract(hasRouteExpectAmount);
-            }
-            //租赁、免费的没有销售收入,有销售成本
-            if (nowGoods.getType().equals(GoodsType.INSTRUMENT) && (kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.LEASE) || kitGroupPurchaseType.equals(KitGroupPurchaseTypeEnum.FREE))) {
-                goodsBalance = BigDecimal.ZERO;
-                expectAmount = BigDecimal.ZERO;
-            }
-
-            hasRouteBalance = hasRouteBalance.add(goodsBalance);
-            hasRouteExpectAmount = hasRouteExpectAmount.add(expectAmount);
-            i++;
-
-            int complementGoodsNum = nowGoods.getComplementGoodsIdList() == null ? 1 : nowGoods.getComplementGoodsIdList().split(",").length;
-            BigDecimal complementPrice = nowGoods.getGroupPurchasePrice();
-            Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
-            complementGoodsPrice.put(nowGoods.getId(), nowGoods.getGroupPurchasePrice());
-            if (nowGoods.getComplementGoodsIdList() != null) {
-                List<Goods> complementGoodies = goodsDao.findGoodsByIds(nowGoods.getComplementGoodsIdList());
-                complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
-                complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
-            }
-
-            BigDecimal hasRouteSellOrderExpectAmount = BigDecimal.ZERO;
-            BigDecimal hasRouteSellOrderBalance = BigDecimal.ZERO;
-            for (SellOrder sellOrder : sellOrderList) {
-                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) {
-                    sellOrderExpectAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(expectAmount).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
-                    sellOrderBalance = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(goodsBalance).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
-                }
-                complementGoodsNum = complementGoodsNum - sellOrder.getNum();
-                if (complementGoodsNum <= 0) {
-                    sellOrderExpectAmount = expectAmount.subtract(hasRouteSellOrderExpectAmount);
-                    sellOrderBalance = goodsBalance.subtract(hasRouteSellOrderBalance);
-                }
-                hasRouteSellOrderExpectAmount = hasRouteSellOrderExpectAmount.add(sellOrderExpectAmount);
-                hasRouteSellOrderBalance = hasRouteSellOrderBalance.add(sellOrderBalance);
-
-                sellOrder.setExpectAmount(sellOrderExpectAmount);
-                sellOrder.setBalanceAmount(sellOrderBalance);
-                sellOrder.setActualAmount(sellOrderExpectAmount.subtract(sellOrderBalance));
-                sellOrder.setOrganId(order.getOrganId());
-                sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
-                sellOrder.setEduTeacherId(musicGroup.getEducationalTeacherId());
-                sellOrder.setTransNo(order.getTransNo());
-                sellOrder.setOrderId(order.getId());
-                sellOrder.setOrderNo(order.getOrderNo());
-                sellOrder.setUserId(order.getUserId());
-                sellOrder.setPaymentChannel(order.getPaymentChannel());
-                sellOrder.setMerNo(order.getMerNos());
-                sellOrder.setSellTime(order.getCreateTime());
-                sellOrder.setCreateIme(new Date());
-                sellOrder.setUpdateTime(new Date());
-                sellOrder.setTenantId(tenantId);
-                if (nowGoods.getType().equals(GoodsType.INSTRUMENT)) {
-                    sellOrder.setType(SellTypeEnum.INSTRUMENT);
-                } else if (nowGoods.getType().equals(GoodsType.ACCESSORIES)) {
-                    sellOrder.setType(SellTypeEnum.ACCESSORIES);
-                } else {
-                    sellOrder.setType(SellTypeEnum.OTHER);
-                }
-                sellOrder.setHasRoute(true);
-                if (complementGoodsNum <= 0) {
-                    break;
-                }
-            }
-        }
-        if (sellOrderList.size() > 0) {
-            //如果有优惠券金额
-            if (couponRemitAmount.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 = couponRemitAmount;
-                for (int j = 0; j < sellOrders.size(); j++) {
-                    SellOrder sellOrder = sellOrders.get(j);
-                    //如果是最后一件商品
-                    if (j == sellOrders.size() - 1) {
-                        sellOrder.setCouponRemitAmount(subCouponMarketAmount);
-                    } else {
-                        //获取比例
-                        BigDecimal ratioAmount = sellOrder.getExpectAmount().divide(reduce, 6, BigDecimal.ROUND_HALF_UP);
-                        //获取分配的减免金额
-                        BigDecimal multiply = couponRemitAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
-                        subCouponMarketAmount = subCouponMarketAmount.subtract(multiply);
-                        sellOrder.setCouponRemitAmount(multiply);
-                    }
-                }
-            }
-            sellOrderService.batchInsert(sellOrderList);
-            sellOrderService.syncSellOrder2Mall(sellOrderList,order);
-        }
-        return sellOrderList;
+        return sellOrderService.initSellOrder(order,musicGroupId,goodsIds,kitGroupPurchaseType);
     }
 }

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

@@ -21,6 +21,7 @@
         <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="parent_goods_id_" property="parentGoodsId"/>
         <result column="goods_id_" property="goodsId"/>
+        <result column="goods_sku_id_" property="goodsSkuId"/>
         <result column="goods_name_" property="goodsName"/>
         <result column="sell_cost_" property="sellCost"/>
         <result column="organ_sell_cost_" property="organSellCost"/>
@@ -51,7 +52,7 @@
         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_, refund_time_,sell_time_, create_ime_,
-        update_time_,coupon_remit_amount_,organ_sell_cost_,delivery_time_
+        update_time_,coupon_remit_amount_,organ_sell_cost_,delivery_time_,goods_sku_id_
     </sql>
     <select id="get" parameterType="java.lang.Integer" resultMap="SellOrder">
         <!--@mbg.generated-->
@@ -72,13 +73,13 @@
         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_, refund_time_,sell_time_,
-        create_ime_, update_time_,coupon_remit_amount_,tenant_id_,organ_sell_cost_,delivery_time_)
+        create_ime_, update_time_,coupon_remit_amount_,tenant_id_,organ_sell_cost_,delivery_time_,goods_sku_id_)
         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},
-        #{refundTime},#{sellTime}, #{createIme}, #{updateTime}, #{couponRemitAmount},#{tenantId},#{organSellCost},#{deliveryTime})
+        #{refundTime},#{sellTime}, #{createIme}, #{updateTime}, #{couponRemitAmount},#{tenantId},#{organSellCost},#{deliveryTime},#{goodsSkuId})
     </insert>
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.SellOrder">
         <!--@mbg.generated-->
@@ -174,6 +175,9 @@
             <if test="updateTime != null">
                 update_time_ = #{updateTime},
             </if>
+            <if test="goodsSkuId != null">
+                goods_sku_id_ = #{goodsSkuId},
+            </if>
         </set>
         where id_ = #{id} and tenant_id_ = #{tenantId}
     </update>
@@ -263,6 +267,9 @@
                 <if test="sellOrder.createIme != null">
                     create_ime_ = #{sellOrder.createIme},
                 </if>
+                <if test="sellOrder.goodsSkuId != null">
+                    goods_sku_id_ = #{sellOrder.goodsSkuId},
+                </if>
                 update_time_ = NOW()
             </set>
             where id_ = #{sellOrder.id} and tenant_id_ = #{sellOrder.tenantId}
@@ -279,7 +286,8 @@
         insert into sell_order (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_,edu_teacher_id_, create_ime_, update_time_,coupon_remit_amount_,tenant_id_,organ_sell_cost_,delivery_time_)
+        mer_no_,batch_no_,stock_type_,account_type_, sell_time_,edu_teacher_id_, create_ime_,
+                                update_time_,coupon_remit_amount_,tenant_id_,organ_sell_cost_,delivery_time_,goods_sku_id_)
         VALUE
         <foreach collection="sellOrders" separator="," item="sellOrder">
             (#{sellOrder.organId},#{sellOrder.cooperationOrganId},#{sellOrder.transNo},#{sellOrder.orderId},#{sellOrder.orderNo},
@@ -287,7 +295,8 @@
             #{sellOrder.goodsName},#{sellOrder.sellCost},#{sellOrder.sellCost2},#{sellOrder.num},#{sellOrder.userId},
             #{sellOrder.paymentChannel},#{sellOrder.merNo},#{sellOrder.batchNo},
             #{sellOrder.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{sellOrder.accountType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-            #{sellOrder.sellTime},#{sellOrder.eduTeacherId},NOW(),NOW(),#{sellOrder.couponRemitAmount},#{sellOrder.tenantId},#{sellOrder.organSellCost},#{sellOrder.deliveryTime})
+            #{sellOrder.sellTime},#{sellOrder.eduTeacherId},NOW(),NOW(),#{sellOrder.couponRemitAmount},#{sellOrder.tenantId},
+            #{sellOrder.organSellCost},#{sellOrder.deliveryTime},#{sellOrder.goodsSkuId})
         </foreach>
     </insert>
 

+ 1 - 1
mec-client-api/src/main/java/com/ym/mec/web/WebFeignService.java

@@ -96,5 +96,5 @@ public interface WebFeignService {
 
     // 获取学校信息
     @PostMapping("/api/schoolListByIds")
-    HttpResponseResult<List<SchoolDto>> schoolListByIds(List<Long> schoolIds);
+    HttpResponseResult<List<SchoolDto>> schoolListByIds(@RequestBody List<Integer> schoolIds);
 }

+ 1 - 1
mec-client-api/src/main/java/com/ym/mec/web/fallback/WebFeignServiceFallback.java

@@ -124,7 +124,7 @@ public class WebFeignServiceFallback implements WebFeignService {
 	}
 
     @Override
-    public  HttpResponseResult<List<SchoolDto>> schoolListByIds(List<Long> schoolIds) {
+    public  HttpResponseResult<List<SchoolDto>> schoolListByIds(List<Integer> schoolIds) {
         return null;
     }
 }

+ 1 - 1
mec-common/common-core/src/main/java/com/ym/mec/common/dto/SchoolDto.java

@@ -16,7 +16,7 @@ import java.util.List;
 public class SchoolDto {
 
     // 学校ID
-    private Long id;
+    private Integer id;
 
     // 学校名称
     private String name;

+ 4 - 4
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

@@ -92,7 +92,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         List<OrderVo> list = orderDao.getList(queryParam);
 
         // 过滤出学校订单,查询学校信息
-        List<Long> schoolIds = list.stream().filter(o->o.getSourceType() ==2).map(OmsOrder::getMemberId).collect(Collectors.toList());
+        List<Integer> schoolIds = list.stream().filter(o->o.getSourceType() ==2).map(e->e.getMemberId().intValue()).collect(Collectors.toList());
         for (OrderVo orderVo : list) {
             if (orderVo.getSourceType() == 2 ||orderVo.getSourceType() == 4) {
                 orderVo.setPhone("");
@@ -103,10 +103,10 @@ public class OmsOrderServiceImpl implements OmsOrderService {
             try {
                 HttpResponseResult<List<SchoolDto>> schoolDtoHttpResponseResult = webFeignService.schoolListByIds(schoolIds);
                 if (schoolDtoHttpResponseResult.getCode() == 200 && schoolDtoHttpResponseResult.getStatus()) {
-                    Map<Long, SchoolDto> schoolDtoMap = schoolDtoHttpResponseResult.getData().stream().collect(Collectors.toMap(SchoolDto::getId, o -> o));
+                    Map<Integer, SchoolDto> schoolDtoMap = schoolDtoHttpResponseResult.getData().stream().collect(Collectors.toMap(SchoolDto::getId, o -> o));
                     list.forEach(o->{
                         if (o.getSourceType() == 2) {
-                            SchoolDto schoolDto = schoolDtoMap.get(o.getMemberId());
+                            SchoolDto schoolDto = schoolDtoMap.get(o.getMemberId().intValue());
                             if (schoolDto != null) {
                                 o.setUsername(schoolDto.getName());
                             } else {
@@ -367,7 +367,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         // 学校订单查询学校信息
         try {
             if (detail.getSourceType() == 2) {
-                HttpResponseResult<List<SchoolDto>> schoolDtoHttpResponseResult = webFeignService.schoolListByIds(Lists.newArrayList(detail.getMemberId()));
+                HttpResponseResult<List<SchoolDto>> schoolDtoHttpResponseResult = webFeignService.schoolListByIds(Lists.newArrayList(detail.getMemberId().intValue()));
                 if (schoolDtoHttpResponseResult.getCode() == 200 && schoolDtoHttpResponseResult.getStatus()) {
                     List<SchoolDto> data = schoolDtoHttpResponseResult.getData();
                     if (!CollectionUtils.isEmpty(data)) {