|
@@ -469,6 +469,9 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
for (Goods goods : goodies) {
|
|
|
goodsPrice = goodsPrice.add(goods.getDiscountPrice());
|
|
|
}
|
|
|
+
|
|
|
+ Map<Integer,Goods> goodsMap = goodies.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+
|
|
|
subjectChange.setChangeCost(goodsPrice);
|
|
|
subjectChange.setCostMargin(subjectChange.getChangeCost().subtract(subjectChange.getOriginalCost()));
|
|
|
//差价 <= 0
|
|
@@ -521,6 +524,160 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
|
|
|
subjectChange.setOrderNo(orderNo);
|
|
|
subjectChangeDao.update(subjectChange);
|
|
|
|
|
|
+ //添加订单详情
|
|
|
+ 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);
|
|
|
+ }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());
|
|
|
+
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+
|
|
|
+ //扣减库存
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //原始订单的库存要归还
|
|
|
+ List<StudentPaymentOrderDetail> 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){
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
//退原订单商品
|
|
|
sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue(), false);
|
|
|
|