zouxuan 5 rokov pred
rodič
commit
ff9bab5305

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsDao.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.dal.dao;
 
+import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.common.dal.BaseDAO;
 
@@ -102,4 +103,15 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
     String getInnerRepertoryWarnName(@Param("innerRepertoryWarnNum") String innerRepertoryWarnNum);
 
     String getOuterRepertoryWarnName(@Param("outerRepertoryWarnNum") String outerRepertoryWarnNum);
+
+    /**
+     * @describe 获取商品辅件列表
+     * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
+     * @author zouxuan
+     * @date 2020/10/13
+     * @time 15:09
+     * @param goodsId:
+     * @return java.util.List<com.ym.mec.biz.dal.dto.GoodsSellDto>
+     */
+    List<GoodsSellDto> queryGoodsSellDtos(@Param("goodsId") String goodsId);
 }

+ 23 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/GoodsSellDto.java

@@ -3,6 +3,7 @@ package com.ym.mec.biz.dal.dto;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 public class GoodsSellDto{
 	@ApiModelProperty(value = "商品数量", required = false)
@@ -26,6 +27,28 @@ public class GoodsSellDto{
 	@ApiModelProperty(value = "商品销售总价", required = false)
 	private BigDecimal totalGoodsPrice = BigDecimal.ZERO;
 
+    @ApiModelProperty(value = "辅件商品列表", required = false)
+    private String complementGoodsIdList;
+
+    public String getComplementGoodsIdList() {
+        return complementGoodsIdList;
+    }
+
+    public void setComplementGoodsIdList(String complementGoodsIdList) {
+        this.complementGoodsIdList = complementGoodsIdList;
+    }
+
+	@ApiModelProperty(value = "组合商品子商品", required = false)
+	private List<GoodsSellDto> goodsSellDtos;
+
+	public List<GoodsSellDto> getGoodsSellDtos() {
+		return goodsSellDtos;
+	}
+
+	public void setGoodsSellDtos(List<GoodsSellDto> goodsSellDtos) {
+		this.goodsSellDtos = goodsSellDtos;
+	}
+
 	public String getGoodsType() {
 		return goodsType;
 	}

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

@@ -106,4 +106,15 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @return void
      */
     void increaseStock(List<Integer> sellOrderIds, AccountType accountType);
+
+    /**
+     * @describe 获取辅件商品列表
+     * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
+     * @author zouxuan
+     * @date 2020/10/13
+     * @time 15:07
+     * @param goodsId:
+     * @return java.util.List<com.ym.mec.biz.dal.dto.GoodsSellDto>
+     */
+    List<GoodsSellDto> queryGoodsSellDtos(String goodsId);
 }

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -409,4 +409,9 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 //			goodsProcurementDao.update(goodsProcurement);
 //		}
 	}
+
+	@Override
+	public List<GoodsSellDto> queryGoodsSellDtos(String goodsId) {
+		return goodsDao.queryGoodsSellDtos(goodsId);
+	}
 }

+ 91 - 43
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -50,6 +50,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
     @Autowired
     private StudentPaymentOrderService studentPaymentOrderService;
     @Autowired
+    private SysPaymentConfigService sysPaymentConfigService;
+    @Autowired
     private MusicGroupDao musicGroupDao;
     @Autowired
     private SysUserCashAccountService sysUserCashAccountService;
@@ -134,6 +136,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         if (studentId == null) {
             throw new BizException("请指定学员");
         }
+
+        goodsSellDtos.forEach(e->{
+            if(StringUtils.isNotEmpty(e.getComplementGoodsIdList())){
+                e.setGoodsSellDtos(goodsService.queryGoodsSellDtos(e.getComplementGoodsIdList()));
+            }
+        });
         studentDao.lockUser(studentId);
         SysUser student = sysUserFeignService.queryUserById(studentId);
         //如果教务老师为空,代表学员自己创建的订单
@@ -738,6 +746,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(orderNo);
         String goodsJson = studentGoodsSell.getGoodsJson();
         List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(goodsJson, GoodsSellDto.class);
+        //用户选择的商品
         Map<Integer, List<GoodsSellDto>> collect = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
         List<Integer> goodsId = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
 
@@ -747,34 +756,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 goodsIds.add(e.getGoodsId());
             }
         });
-        List<GoodsSellDto> goodsSellDtoList = new ArrayList<>();
-        //扣减库存
-        List<GoodsProcurement> goodsBatchNoDtos = goodsService.subtractStock(goodsIds, AccountType.EXTERNAL);
-
-        Map<String, List<GoodsProcurement>> listMap = goodsBatchNoDtos.stream().collect(Collectors.groupingBy(GoodsProcurement::getBatchNo));
-        Set<String> listMapKeys = listMap.keySet();
-        listMapKeys.forEach(e->{
-            listMap.get(e).forEach(z->{
-                GoodsSellDto goodsSellDto1 = collect.get(z.getGoodsId()).get(0);
-                GoodsSellDto goodsSellDto = new GoodsSellDto();
-                if(StringUtils.isEmpty(z.getBatchNo())){
-                    goodsSellDto.setGoodsNum(1);
-                    goodsSellDto.setTotalGoodsPrice(goodsSellDto1.getGoodsPrice());
-                    goodsSellDto.setGoodsPrice(goodsSellDto1.getGoodsPrice());
-                    goodsSellDto.setGoodsId(goodsSellDto1.getGoodsId());
-                    goodsSellDto.setGoodsName(goodsSellDto1.getGoodsName());
-                    goodsSellDto.setGoodsType(goodsSellDto1.getGoodsType());
-                    goodsSellDto.setImage(goodsSellDto1.getImage());
-                }else {
-
-                }
-            });
-        });
-
-        List<Goods> goodsByIds = goodsService.findGoodsByIds(StringUtils.join(goodsId, ","));
-        Map<Integer, List<Goods>> goodsMap = goodsByIds.stream().collect(Collectors.groupingBy(Goods::getId));
+        AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(orderByOrderNo.getPaymentChannel()), orderByOrderNo.getMerNos());
+        //实际扣减的库存商品
+        List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
         Map<String, BigDecimal> costMap = new HashMap<>(2);
-        List<SellOrder> sellOrders = new ArrayList<>();
         BigDecimal balancePaymentAmount = orderByOrderNo.getBalancePaymentAmount();
         //可用余额
         BigDecimal usableBalance = balancePaymentAmount;
@@ -783,6 +768,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         BigDecimal usableMarketAmount = marketAmount;
         //包含减免余额的总金额
         BigDecimal totalAmount = goodsSellDtos.stream().map(e -> e.getTotalGoodsPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
+        //组合商品减免金额
+        Map<Integer,BigDecimal> parentGoodsCutTotalPriceMap = new HashMap<>();
+        //组合商品附加金额
+        Map<Integer,BigDecimal> parentGoodsAddTotalPriceMap = new HashMap<>();
         //应付总额
         BigDecimal totalActual = totalAmount.subtract(marketAmount);
         //可用应付
@@ -791,23 +780,83 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         BigDecimal realityAmount = totalActual.subtract(usableBalance);
         //可用实付总额
         BigDecimal usableAmount = realityAmount;
-        for (int i = 0; i < goodsId.size(); i++) {
-            Integer e = goodsId.get(i);
-            GoodsSellDto goodsSellDto = collect.get(e).get(0);
-            Goods goods = goodsMap.get(e).get(0);
+        //可用组合商品总减免金额
+        BigDecimal usableParentGoodsCutTotalPrice;
+        //可用组合商品总附加金额
+        BigDecimal usableParentGoodsAddTotalPrice;
+
+        //获取组合商品列表
+        List<SellOrder> orderList = sellOrderList.stream().filter(sellOrder -> sellOrder.getParentGoodsId() != null).collect(Collectors.toList());
+        for (SellOrder sellOrder : orderList) {
+            //获取组合商品销售总价
+            GoodsSellDto goodsSellDto = collect.get(sellOrder.getParentGoodsId()).get(0);
+            BigDecimal parentTotalGoodsPrice = goodsSellDto.getTotalGoodsPrice();
+            BigDecimal totalGoodsPrice = BigDecimal.ZERO;
+            //获取单个商品销售总价
+            for (GoodsSellDto sellDto : goodsSellDto.getGoodsSellDtos()) {
+                totalGoodsPrice = totalGoodsPrice.add(sellDto.getTotalGoodsPrice());
+            }
+            //如果组合价大于预计总价
+            if (parentTotalGoodsPrice.compareTo(totalGoodsPrice) == 1){
+                parentGoodsAddTotalPriceMap.put(sellOrder.getParentGoodsId(),parentTotalGoodsPrice.subtract(totalGoodsPrice));
+            }else if(parentTotalGoodsPrice.compareTo(totalGoodsPrice) == -1){//小于
+                parentGoodsCutTotalPriceMap.put(sellOrder.getParentGoodsId(),totalGoodsPrice.subtract(parentTotalGoodsPrice));
+            }
+        }
+        noAmount:for (SellOrder sellOrder : orderList) {
+            GoodsSellDto goodsSellDto = collect.get(sellOrder.getParentGoodsId()).get(0);
+            List<GoodsSellDto> goodsSellDtoList = goodsSellDto.getGoodsSellDtos();
+            BigDecimal addTotalPrice = parentGoodsAddTotalPriceMap.get(sellOrder.getParentGoodsId());
+            usableParentGoodsAddTotalPrice = addTotalPrice;
+            BigDecimal cutTotalPrice = parentGoodsCutTotalPriceMap.get(sellOrder.getParentGoodsId());
+            usableParentGoodsCutTotalPrice = cutTotalPrice;
+            for (int i = 0; i < goodsSellDtoList.size(); i++) {
+                GoodsSellDto sellDto = goodsSellDtoList.get(i);
+                //获取比例
+                BigDecimal ratioAmount = sellDto.getTotalGoodsPrice().divide(goodsSellDto.getTotalGoodsPrice(), 2, BigDecimal.ROUND_HALF_UP);
+
+                if(addTotalPrice.doubleValue() > 0l){
+                    //如果是最后一件商品
+                    if(i == goodsId.size() - 1){
+                        sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(usableParentGoodsAddTotalPrice));
+                    }else {
+                        //获取分配的附加
+                        BigDecimal multiply = ratioAmount.multiply(addTotalPrice).setScale(2,BigDecimal.ROUND_HALF_UP);
+                        sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(multiply));
+                        usableParentGoodsAddTotalPrice = usableParentGoodsAddTotalPrice.subtract(multiply);
+                    }
+                }else if(cutTotalPrice.doubleValue() > 0l){
+                    //如果是最后一件商品
+                    if(i == goodsId.size() - 1){
+                        sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(usableParentGoodsCutTotalPrice));
+                    }else {
+                        //获取分配的组合减免金额
+                        BigDecimal multiply = ratioAmount.multiply(cutTotalPrice).setScale(2,BigDecimal.ROUND_HALF_UP);
+                        sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(multiply));
+                        usableParentGoodsCutTotalPrice = usableParentGoodsCutTotalPrice.subtract(multiply);
+                    }
+                }else {
+                    continue noAmount;
+                }
+            }
+        }
 
-            costMap.put("sellCost", goods.getDiscountPrice());
-            if (goods.getAgreeCostPrice() != null) {
-                costMap.put("SellCost2", goods.getAgreeCostPrice());
+        for (int i = 0; i < sellOrderList.size(); i++) {
+            SellOrder sellOrder = sellOrderList.get(i);
+            Integer e = null;
+            if(sellOrder.getParentGoodsId() != null){
+                e = sellOrder.getParentGoodsId();
+            }else {
+                e = sellOrder.getGoodsId();
             }
-            SellOrder sellOrder = new SellOrder();
+            GoodsSellDto goodsSellDto = collect.get(e).get(0);
             sellOrder.setOrganId(orderByOrderNo.getOrganId());
             sellOrder.setTransNo(orderByOrderNo.getTransNo());
             sellOrder.setOrderId(orderByOrderNo.getId());
             sellOrder.setOrderNo(orderByOrderNo.getOrderNo());
+            goodsSellDto.setTotalGoodsPrice(goodsSellDto.getGoodsPrice().multiply(new BigDecimal(sellOrder.getNum())));
             //获取比例
             BigDecimal ratioAmount = goodsSellDto.getTotalGoodsPrice().divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP);
-
             //如果有减免金额
             if(marketAmount.doubleValue() > 0l){
                 //如果是最后一件商品
@@ -815,7 +864,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                     goodsSellDto.setTotalGoodsPrice(goodsSellDto.getTotalGoodsPrice().subtract(usableMarketAmount));
                 }else {
                     //获取分配的减免金额
-                    BigDecimal multiply = ratioAmount.multiply(usableMarketAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
+                    BigDecimal multiply = ratioAmount.multiply(marketAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
                     goodsSellDto.setTotalGoodsPrice(goodsSellDto.getTotalGoodsPrice().subtract(multiply));
                     usableMarketAmount = usableMarketAmount.subtract(multiply);
                 }
@@ -843,11 +892,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 }
             }
             sellOrder.setExpectAmount(sellOrder.getActualAmount().add(sellOrder.getBalanceAmount()));
-            sellOrder.setSellCost(goods.getDiscountPrice());
+//            sellOrder.setSellCost(goods.getDiscountPrice());
             sellOrder.setSellCost2(JSONObject.toJSONString(costMap));
-            sellOrder.setType(SellTypeEnum.valueOf(goods.getType().getCode()));
+            sellOrder.setType(SellTypeEnum.valueOf(goodsSellDto.getGoodsType()));
             sellOrder.setGoodsId(e);
-            sellOrder.setGoodsName(goods.getName());
+            sellOrder.setGoodsName(goodsSellDto.getGoodsName());
             sellOrder.setNum(goodsSellDto.getGoodsNum());
             sellOrder.setUserId(studentGoodsSell.getUserId());
             sellOrder.setPaymentChannel(orderByOrderNo.getPaymentChannel());
@@ -855,10 +904,9 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             sellOrder.setSellTime(orderByOrderNo.getPayTime());
             sellOrder.setEduTeacherId(studentGoodsSell.getTeacherId());
             sellOrder.setCooperationOrganId(studentGoodsSell.getCooperationOrganId());
-            sellOrders.add(sellOrder);
         }
-        if(sellOrders.size() > 0){
-            sellOrderService.batchInsert(sellOrders);
+        if(sellOrderList.size() > 0){
+            sellOrderService.batchInsert(sellOrderList);
         }
     }
 

+ 11 - 0
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -323,4 +323,15 @@
     <select id="getWithComplementGoodsAndStatus" resultMap="Goods">
         SELECT * FROM goods WHERE status_ = #{status} AND FIND_IN_SET(#{goodsId}, complement_goods_id_list_)
     </select>
+    <resultMap id="GoodsSellDtoMap" type="com.ym.mec.biz.dal.dto.GoodsSellDto">
+        <result property="goodsId" column="id_"/>
+        <result property="image" column="image_"/>
+        <result property="goodsName" column="name_"/>
+        <result property="goodsType" column="type_"/>
+        <result property="goodsPrice" column="market_price_"/>
+        <result property="totalGoodsPrice" column="market_price_"/>
+    </resultMap>
+    <select id="queryGoodsSellDtos" resultMap="GoodsSellDtoMap">
+        SELECT id_,image_,name_,type_,market_price_,market_price_ FROM goods WHERE FIND_IN_SET(id_,#{goodsId})
+    </select>
 </mapper>