浏览代码

销售单配件类型明细单价乘倍率

FengChaoYu 9 月之前
父节点
当前提交
159917199b

+ 3 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/base/WebsitGoodsBean.java

@@ -93,6 +93,9 @@ public class WebsitGoodsBean {
     @ApiModelProperty(value = "更新时间")
     private Date updateTime;
 
+    @ApiModelProperty(value = "配件类型")
+    private String partType;
+
     @ApiModelProperty(value = "自有库存师傅分账金额")
     private BigDecimal selfWorkerAmount;
 

+ 5 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/base/WebsitGoodsLogic.java

@@ -127,6 +127,11 @@ public class WebsitGoodsLogic {
                 && StringUtils.isBlank(bean.getNormType())) {
             throw new RemoteServiceException("收费类型不能为空");
         }
+        if (bean.getGoodsType().equals(WebsitGoodsTypeEnum.P.getKey())
+                && bean.getNormType().equals(NormTypeEnum.M.getKey())
+                && StringUtils.isBlank(bean.getPartType())) {
+            throw new RemoteServiceException("配件类型不能为空");
+        }
 
         bean.setGoodsId(null);
         if (Objects.nonNull(adminUser.getAdminCompanyWechat())) {

+ 32 - 4
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/manage/WebsitSalesLogic.java

@@ -76,6 +76,7 @@ public class WebsitSalesLogic {
     private final AllInPayLogic allInPayLogic;
     private final AdminWebsitPayConfigService adminWebsitPayConfigService;
     private final WorkerGoodsRelaService workerGoodsRelaService;
+    private final MaterialConfigService materialConfigService;
 
     public IPage<WebsitSalesVO> page(WebsitSalesParamBean zfireParamBean) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
@@ -175,13 +176,15 @@ public class WebsitSalesLogic {
                         .setSaleAmount(item.getPrice().multiply(item.getSalesQty()).setScale(2, BigDecimal.ROUND_HALF_UP));
 
                 itemList.add(item);
+            }
+
+            this.goodsConditionHandle(sales, itemList);
 
+            for (WebsitSalesItem item : itemList) {
                 totalAmount = totalAmount.add(item.getSaleAmount());
             }
             sales.setTotalAmount(totalAmount);
 
-            this.goodsConditionHandle(sales, itemList);
-
             websitSalesItemService.saveBatch(itemList);
         }
 
@@ -245,6 +248,28 @@ public class WebsitSalesLogic {
                     .setConvertBitScale(1)
                     .setManageWorkerStock(goods.getManageWorkerStock());
 
+            // 商品类型为配件时单价要先乘倍率
+            if (sales.getGoodsType().equals(WebsitGoodsTypeEnum.P.getKey())) {
+                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("未找到对应配件类型倍率");
+                }
+                item.setPrice(afterPrice);
+            }
+
             BigDecimal convertQty = item.getSalesQty().divide(goods.getGoodsSalesConvertQty(), 1, BigDecimal.ROUND_UP);
             BigDecimal totalSaleValue = item.getSalesQty().multiply(item.getPrice());
             BigDecimal convertPrice = totalSaleValue.divide(convertQty, 2, BigDecimal.ROUND_DOWN);
@@ -252,6 +277,7 @@ public class WebsitSalesLogic {
             if (sales.getGoodsType().equals(WebsitGoodsTypeEnum.P.getKey()) || goods.getGoodsSalesConvertQty().compareTo(BigDecimal.ONE) == 0) {
                 convertQty = item.getSalesQty();
                 convertPrice = item.getPrice();
+                item.setSaleAmount(totalSaleValue);
             }
 
             // 类型为辅材时注入师傅辅材id
@@ -321,13 +347,15 @@ public class WebsitSalesLogic {
                         .setGoodsType(sales.getGoodsType())
                         .setSaleAmount(item.getPrice().multiply(item.getSalesQty()).setScale(2, BigDecimal.ROUND_HALF_UP));
                 itemList.add(item);
+            }
 
+            this.goodsConditionHandle(sales, itemList);
+
+            for (WebsitSalesItem item : itemList) {
                 totalAmount = totalAmount.add(item.getSaleAmount());
             }
             sales.setTotalAmount(totalAmount);
 
-            this.goodsConditionHandle(sales, itemList);
-
             websitSalesItemService.saveBatch(itemList);
         }