FengChaoYu 10 mesiacov pred
rodič
commit
5d75ac0270

+ 2 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/material/WebsitSalesGoodsVO.java

@@ -50,4 +50,6 @@ public class WebsitSalesGoodsVO {
     @ApiModelProperty(value = "是否入师傅库存 NO=否 YES=是")
     private String manageWorkerStock;
 
+    @ApiModelProperty(value = "配件类型")
+    private String partType;
 }

+ 12 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/material/WebsitShoppingCartList.java

@@ -92,4 +92,16 @@ public class WebsitShoppingCartList {
     private String goodsSpecification;
 
     private Date createTime;
+
+    @ApiModelProperty(value = "转换师傅单价")
+    private BigDecimal convertPrice;
+
+    @ApiModelProperty(value = "原配件单价")
+    private BigDecimal origPartsPrice;
+
+    @ApiModelProperty(value = "师傅商品id")
+    private String workerGoodsId;
+
+    @ApiModelProperty(value = "师傅商品名称")
+    private String workerGoodsName;
 }

+ 84 - 6
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/material/WebsitSalesLogic.java

@@ -73,6 +73,10 @@ public class WebsitSalesLogic {
     AdminWebsitPayConfigService adminWebsitPayConfigService;
     @Resource
     WebsitSalesPayMapService websitSalesPayMapService;
+    @Resource
+    MaterialConfigService materialConfigService;
+    @Resource
+    WorkerGoodsRelaService workerGoodsRelaService;
 
     public IPage<SalesOrderBean> buyList(String flag, Integer pageNum, Integer pageSize, HttpServletRequest request) {
         CurrentCompanyWechat wechat = commonLogic.getCurrentCompanyWechat(request);
@@ -157,6 +161,29 @@ public class WebsitSalesLogic {
             goodsList = materialMapper.existStockGoods(wechat.getCurrentCompanyWechatId(), websitId, type, categoryId, goodsName);
         } else {
             goodsList = materialMapper.notStockGoods(wechat.getCurrentCompanyWechatId(), websitId, type, categoryId, goodsName);
+            if (CollectionUtil.isNotEmpty(goodsList)) {
+                final MaterialConfig config = materialConfigService.lambdaQuery()
+                        .eq(MaterialConfig::getCompanyWechatId, wechat.getUser().getCompanyWechatId())
+                        .one();
+                // 市场价乘于倍率
+                for (WebsitSalesGoodsVO vo : goodsList) {
+                    BigDecimal afterPrice;
+                    switch (vo.getPartType()) {
+                        case "空调":
+                            afterPrice = vo.getPrice().multiply(config.getPriceRate1());
+                            break;
+                        case "冰箱":
+                            afterPrice = vo.getPrice().multiply(config.getPriceRate2());
+                            break;
+                        case "生活电器":
+                            afterPrice = vo.getPrice().multiply(config.getPriceRate3());
+                            break;
+                        default:
+                            throw new RemoteServiceException("未找到对应配件类型倍率");
+                    }
+                    vo.setPrice(afterPrice);
+                }
+            }
         }
 
 
@@ -281,13 +308,8 @@ public class WebsitSalesLogic {
             shoppingCart.setGoodsStockUnit(goods.getGoodsStockUnit());
             shoppingCart.setGoodsSpecification(goods.getGoodsSpecification());
 
-            BigDecimal convertQty = shoppingCart.getSalesQty().divide(goods.getGoodsSalesConvertQty(), goods.getConvertBitScale(), BigDecimal.ROUND_UP);
-
-            if (shoppingCart.getGoodsType().equals(WebsitGoodsTypeEnum.P.toString()) || goods.getGoodsSalesConvertQty().compareTo(BigDecimal.ONE) == 0) {
-                convertQty = shoppingCart.getSalesQty();
-            }
+            this.goodsConditionHandle(shoppingCart, goods);
 
-            shoppingCart.setConvertQty(convertQty);
             shoppingCart.setCreateTime(DateUtil.date());
 
             shoppingCarts.add(shoppingCart);
@@ -297,6 +319,57 @@ public class WebsitSalesLogic {
         return this.queryShoppingCart(wechat.getUserId(), websitId, shoppingCartBean.getGoodsType());
     }
 
+    private void goodsConditionHandle(WebsitShoppingCart shoppingCart, WebsitGoods goods) {
+        // 商品类型为配件时单价要先乘倍率
+        if (shoppingCart.getGoodsType().equals(WebsitGoodsTypeEnum.P.toString())) {
+            final MaterialConfig config = materialConfigService.lambdaQuery()
+                    .eq(MaterialConfig::getCompanyWechatId, goods.getCompanyWechatId())
+                    .one();
+            BigDecimal afterPrice;
+            switch (goods.getPartType()) {
+                case "空调":
+                    afterPrice = goods.getMarketPrice().multiply(config.getPriceRate1());
+                    break;
+                case "冰箱":
+                    afterPrice = goods.getMarketPrice().multiply(config.getPriceRate2());
+                    break;
+                case "生活电器":
+                    afterPrice = goods.getMarketPrice().multiply(config.getPriceRate3());
+                    break;
+                default:
+                    throw new RemoteServiceException("未找到对应配件类型倍率");
+            }
+            shoppingCart.setPrice(afterPrice);
+            shoppingCart.setOrigPartsPrice(goods.getMarketPrice());
+        }
+
+        BigDecimal convertQty = shoppingCart.getSalesQty().divide(goods.getGoodsSalesConvertQty(), 1, BigDecimal.ROUND_UP);
+        BigDecimal totalSaleValue = shoppingCart.getSalesQty().multiply(shoppingCart.getPrice());
+        BigDecimal convertPrice = totalSaleValue.divide(convertQty, 2, BigDecimal.ROUND_DOWN);
+
+        if (shoppingCart.getGoodsType().equals(WebsitGoodsTypeEnum.P.toString()) || goods.getGoodsSalesConvertQty().compareTo(BigDecimal.ONE) == 0) {
+            convertQty = shoppingCart.getSalesQty();
+            convertPrice = shoppingCart.getPrice();
+            shoppingCart.setSaleAmount(totalSaleValue);
+        }
+
+        // 类型为辅材时注入师傅辅材id
+        if (shoppingCart.getGoodsType().equals(WebsitGoodsTypeEnum.M.toString())
+                && (StringUtils.isBlank(shoppingCart.getManageWorkerStock()) || shoppingCart.getManageWorkerStock().equals(IsYesNoEnum.YES.getKey()))) {
+            final WorkerGoodsRela goodsRela = workerGoodsRelaService.lambdaQuery()
+                    .eq(WorkerGoodsRela::getCompanyWechatId, goods.getCompanyWechatId())
+                    .eq(WorkerGoodsRela::getWebsitGoodsId, goods.getGoodsId())
+                    .one();
+            if (Objects.nonNull(goodsRela)) {
+                shoppingCart.setWorkerGoodsId(goodsRela.getWorkerGoodsId())
+                        .setWorkerGoodsName(goodsRela.getWorkerGoodsName());
+            }
+        }
+
+        shoppingCart.setConvertQty(convertQty)
+                .setConvertPrice(convertPrice);
+    }
+
     public void clearShoppingCart(String workerId, String websitId, String goodsType) {
         websitShoppingCartService.lambdaUpdate()
                 .eq(WebsitShoppingCart::getWorkerId, workerId)
@@ -378,6 +451,11 @@ public class WebsitSalesLogic {
             detail.setConvertBitScale(bean.getConvertBitScale());
             detail.setManageWorkerStock(bean.getManageWorkerStock());
             detail.setConvertQty(bean.getConvertQty());
+            detail.setConvertPrice(bean.getConvertPrice());
+            detail.setWorkerGoodsId(bean.getWorkerGoodsId());
+            detail.setWorkerGoodsName(bean.getWorkerGoodsName());
+            detail.setOrigPartsPrice(bean.getOrigPartsPrice());
+
             orderDetails.add(detail);
 
             sales.setCompanyWechatId(bean.getCompanyWechatId());

+ 1 - 0
mall-miniapp-service/src/main/resources/mapper/MaterialMapper.xml

@@ -93,6 +93,7 @@
         b.convert_bit_scale,
         b.goods_sales_convert_qty,
         b.manage_worker_stock,
+        b.part_type,
         0 AS qty
         FROM
             websit_goods b