|
@@ -446,11 +446,6 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
throw new BizException("已有未支付的声部更改,请勿重复创建");
|
|
|
}
|
|
|
|
|
|
- /*studentWaitPay = subjectChangeDao.getStudentLastChange(subjectChange.getStudentId(), musicGroupId);
|
|
|
- if (studentWaitPay != null) {
|
|
|
- throw new BizException("声部更换只能操作一次,请勿重复操作");
|
|
|
- }*/
|
|
|
-
|
|
|
Set<String> musicGroupIds = new HashSet<String>();
|
|
|
musicGroupIds.add(musicGroupId);
|
|
|
|
|
@@ -527,15 +522,8 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
} else {
|
|
|
subjectChange.setChangeAccessories(null);
|
|
|
}
|
|
|
- BigDecimal goodsPrice = BigDecimal.ZERO;
|
|
|
List<Goods> goodies = goodsDao.findGoodsByIds(goodsIds);
|
|
|
- for (Goods goods : goodies) {
|
|
|
- goodsPrice = goodsPrice.add(goods.getDiscountPrice());
|
|
|
- }
|
|
|
- subjectChange.setChangeCost(goodsPrice);
|
|
|
-
|
|
|
- Map<Integer,Goods> goodsMap = goodies.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
-
|
|
|
+ subjectChange.setChangeCost(goodies.stream().map(Goods::getDiscountPrice).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
subjectChange.setCostMargin(subjectChange.getChangeCost().subtract(subjectChange.getOriginalCost()));
|
|
|
//差价 <= 0
|
|
|
BigDecimal amountMargin = subjectChange.getGoodsMargin().add(subjectChange.getCourseMargin());
|
|
@@ -552,7 +540,6 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
subjectChangeDao.insert(subjectChange);
|
|
|
//差价小于0退到余额
|
|
|
if (amountMargin.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- //sysUserCashAccountService.updateBalance(subjectChange.getStudentId(), amountMargin.negate(), PlatformCashAccountDetailTypeEnum.REFUNDS, "声部更换退还");
|
|
|
if (amountMargin.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
SysUserCashAccountLog sysUserCashAccountLog = new SysUserCashAccountLog();
|
|
|
sysUserCashAccountLog.setUserId(subjectChange.getStudentId());
|
|
@@ -592,205 +579,50 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
|
|
|
//添加订单详情
|
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
|
|
|
- StudentPaymentOrderDetail studentPaymentOrderDetail = null;
|
|
|
- Goods goods = null;
|
|
|
- List<Integer> minuendStockGoodsIdList = null;
|
|
|
- GoodsProcurement goodsProcurement = null;
|
|
|
- Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
|
|
|
- Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
|
|
|
-
|
|
|
- for(String goodsIdStr : goodsIds.split(",")){
|
|
|
- if(StringUtils.isBlank(goodsIdStr)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
-
|
|
|
- if(goods != null){
|
|
|
- studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
- studentPaymentOrderDetail.setCreateTime(nowDate);
|
|
|
- if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
- studentPaymentOrderDetail.setKitGroupPurchaseType(subjectChange.getKitGroupPurchaseType());
|
|
|
- }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
- }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
- }else{
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
- }
|
|
|
- studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
- studentPaymentOrderDetail.setPrice(BigDecimal.ZERO);
|
|
|
- studentPaymentOrderDetail.setUpdateTime(nowDate);
|
|
|
- studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
-
|
|
|
- //忽略的分部
|
|
|
- List<Integer> ignoreOrganList = Arrays.asList(4, 55, 59);
|
|
|
-
|
|
|
- //查询商品收款账户配置
|
|
|
- String goodsSellReceiptMerNo = sysConfigDao.findConfigValue("goodsSellReceiptMerNo");
|
|
|
-
|
|
|
- if(!ignoreOrganList.contains(subjectChange.getOrganId()) && StringUtils.isNotBlank(goodsSellReceiptMerNo)){
|
|
|
- //扣减库存
|
|
|
-
|
|
|
- BigDecimal totalGroupPurchaseAmount = BigDecimal.ZERO;
|
|
|
-
|
|
|
- BigDecimal groupPurchaseAmount = BigDecimal.ZERO;
|
|
|
-
|
|
|
- minuendStockGoodsIdList = new ArrayList<Integer>();
|
|
|
-
|
|
|
- // 是否是组合商品
|
|
|
- if(StringUtils.isNotBlank(goods.getComplementGoodsIdList())){
|
|
|
- List<Goods> goodsList = goodsService.getGoodsWithLocked(goods.getComplementGoodsIdList());
|
|
|
- totalGroupPurchaseAmount = totalGroupPurchaseAmount.add(goodsList.stream().map(Goods :: getGroupPurchasePrice).reduce(BigDecimal.ZERO,BigDecimal :: add));
|
|
|
-
|
|
|
- for(Goods subGoods : goodsList){
|
|
|
-
|
|
|
- if(batchUpdateGoodsMap.get(subGoods.getId()) != null){
|
|
|
- subGoods = batchUpdateGoodsMap.get(subGoods.getId());
|
|
|
- }
|
|
|
- //判断是否有内部库存
|
|
|
- if(subGoods.getStockCount() > 0){
|
|
|
-
|
|
|
- groupPurchaseAmount = groupPurchaseAmount.add(subGoods.getGroupPurchasePrice());
|
|
|
- subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).decrementAndGet());
|
|
|
- subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).incrementAndGet());
|
|
|
- subGoods.setUpdateTime(nowDate);
|
|
|
-
|
|
|
- batchUpdateGoodsMap.put(subGoods.getId(), subGoods);
|
|
|
-
|
|
|
- minuendStockGoodsIdList.add(subGoods.getId());
|
|
|
-
|
|
|
- goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
|
|
|
- if(goodsProcurement != null){
|
|
|
- if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
|
|
|
- goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
|
|
|
- }
|
|
|
- goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
|
|
|
- goodsProcurement.setUpdateTime(nowDate);
|
|
|
- goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- totalGroupPurchaseAmount = totalGroupPurchaseAmount.add(goods.getGroupPurchasePrice());
|
|
|
-
|
|
|
- if(batchUpdateGoodsMap.get(goods.getId()) != null){
|
|
|
- goods = batchUpdateGoodsMap.get(goods.getId());
|
|
|
- }
|
|
|
-
|
|
|
- //判断是否有内部库存
|
|
|
- if(goods.getStockCount() > 0){
|
|
|
-
|
|
|
- groupPurchaseAmount = groupPurchaseAmount.add(goods.getGroupPurchasePrice());
|
|
|
- goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
|
|
|
- goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());
|
|
|
- goods.setUpdateTime(nowDate);
|
|
|
- batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
-
|
|
|
- minuendStockGoodsIdList.add(goods.getId());
|
|
|
-
|
|
|
- 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()).incrementAndGet());
|
|
|
- goodsProcurement.setUpdateTime(nowDate);
|
|
|
- goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (minuendStockGoodsIdList.size() > 0) {
|
|
|
- studentPaymentOrderDetail.setIncomeItem(OrderDetailTypeEnum.CLOUD_TEACHER.name());
|
|
|
- studentPaymentOrderDetail.setIncome(BigDecimal.ZERO);
|
|
|
- studentPaymentOrderDetail.setBalanceIncome(BigDecimal.ZERO);
|
|
|
- if(minuendStockGoodsIdList.size() > 0){
|
|
|
- studentPaymentOrderDetail.setMinuendStockGoodsIdList(minuendStockGoodsIdList.stream().map(t -> t.toString()).collect(Collectors.joining(",")));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- studentPaymentOrderDetail.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
-
|
|
|
- studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
-
|
|
|
- //分部分润
|
|
|
- if(subjectChange.getChangeCourseFee().compareTo(BigDecimal.ZERO) > 0 && studentPaymentOrderDetail.getKitGroupPurchaseType() == KitGroupPurchaseTypeEnum.GROUP) {
|
|
|
- StudentPaymentOrderDetail spod = new StudentPaymentOrderDetail();
|
|
|
- spod.setType(OrderDetailTypeEnum.ORGAN_SHARE_PROFIT);
|
|
|
- spod.setPrice(subjectChange.getChangeCourseFee());
|
|
|
- spod.setRemitFee(BigDecimal.ZERO);
|
|
|
- spod.setCreateTime(nowDate);
|
|
|
- spod.setUpdateTime(nowDate);
|
|
|
- spod.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
- spod.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
- studentPaymentOrderDetailList.add(spod);
|
|
|
- }
|
|
|
- }
|
|
|
+ for (Goods goods : goodies) {
|
|
|
+ StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(nowDate);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ studentPaymentOrderDetail.setKitGroupPurchaseType(subjectChange.getKitGroupPurchaseType());
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goods.getId().toString());
|
|
|
+ studentPaymentOrderDetail.setPrice(BigDecimal.ZERO);
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(nowDate);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+ studentPaymentOrderDetail.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ //分部分润
|
|
|
+ if(subjectChange.getChangeCourseFee().compareTo(BigDecimal.ZERO) > 0 && studentPaymentOrderDetail.getKitGroupPurchaseType() == KitGroupPurchaseTypeEnum.GROUP) {
|
|
|
+ StudentPaymentOrderDetail spod = new StudentPaymentOrderDetail();
|
|
|
+ spod.setType(OrderDetailTypeEnum.ORGAN_SHARE_PROFIT);
|
|
|
+ spod.setPrice(subjectChange.getChangeCourseFee());
|
|
|
+ spod.setRemitFee(BigDecimal.ZERO);
|
|
|
+ spod.setCreateTime(nowDate);
|
|
|
+ spod.setUpdateTime(nowDate);
|
|
|
+ spod.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+ spod.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
+ studentPaymentOrderDetailList.add(spod);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- //原始订单的库存要归还
|
|
|
- List<StudentPaymentOrderDetail> originalStudentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
|
|
|
- if(subjectChange.getOriginalOrderId() != null){
|
|
|
- originalStudentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(subjectChange.getOriginalOrderId().longValue());
|
|
|
- }
|
|
|
- String originalGoodsIds = originalStudentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
- if(StringUtils.isNotBlank(originalGoodsIds)){
|
|
|
- List<Goods> goodsList = goodsService.getGoodsWithLocked(originalGoodsIds);
|
|
|
- goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
-
|
|
|
- for(String goodsIdStr : originalGoodsIds.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(studentPaymentOrderDetailList.size() > 0){
|
|
|
+ if(!CollectionUtils.isEmpty(studentPaymentOrderDetailList)){
|
|
|
studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
}
|
|
|
-
|
|
|
- if(goodsProcurementMap.size() > 0){
|
|
|
- goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
|
|
|
- }
|
|
|
-
|
|
|
- if(batchUpdateGoodsMap.size() > 0){
|
|
|
- goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
- }
|
|
|
-
|
|
|
//退原订单商品
|
|
|
if(subjectChange.getOriginalOrderId() != null) {
|
|
|
sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue(), false);
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(goodsIds)) {
|
|
|
- List<Integer> goodsIdList = Arrays.stream(goodsIds.split(",")).map(Integer::parseInt).collect(Collectors.toList());
|
|
|
+ List<Integer> goodsIdList = goodies.stream().map(Goods::getId).collect(Collectors.toList());
|
|
|
//添加新订单
|
|
|
- this.addSellOrder(studentPaymentOrder,
|
|
|
- subjectChange.getMusicGroupId(),
|
|
|
- goodsIdList,
|
|
|
- subjectChange.getKitGroupPurchaseType());
|
|
|
+ sellOrderService.initSellOrder(studentPaymentOrder,musicGroupId,goodsIdList,subjectChange.getKitGroupPurchaseType(),true);
|
|
|
}
|
|
|
//乐保处理
|
|
|
studentInstrumentService.subjectChangeUpdateInstrument(subjectChange);
|