‘linchangsheng’ il y a 3 semaines
Parent
commit
16c5e3131c

+ 11 - 0
src/main/java/com/gree/mall/manager/controller/goods/GoodsApplyController.java

@@ -86,4 +86,15 @@ public class GoodsApplyController {
         return ResponseHelper.success();
     }
 
+
+    @PostMapping("/approve")
+    @ApiOperation(value = "审批")
+    public ResponseHelper<GoodsApplyDetail> approve(
+            @ApiParam(value = "申请id") @RequestParam(required = false) String goodsApplyId,
+            @ApiParam(value = "WAIT 待审核 OK 通过  FAIL 驳回") @RequestParam(required = false) String status,
+            HttpServletRequest request
+    ) throws RemoteServiceException {
+        goodsApplyLogic.approve(goodsApplyId,status);
+        return ResponseHelper.success();
+    }
 }

+ 46 - 1
src/main/java/com/gree/mall/manager/logic/goods/GoodsApplyLogic.java

@@ -3,10 +3,13 @@ package com.gree.mall.manager.logic.goods;
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.bean.goods.*;
 import com.gree.mall.manager.commonmapper.CustomGoodsApplyMapper;
+import com.gree.mall.manager.enums.ExamineStatusEnum;
+import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.logic.common.CommonLogic;
 import com.gree.mall.manager.plus.entity.Goods;
 import com.gree.mall.manager.plus.entity.GoodsApply;
@@ -100,14 +103,20 @@ public class GoodsApplyLogic {
 
     @Transactional(rollbackFor = Exception.class)
     public void add(GoodsApplyAddUp goodsApplyAddUp, HttpServletRequest request) {
+        goodsApplyAddUp.setGoodsApplyId(IdWorker.getIdStr());
+
+        if (goodsApplyService.lambdaQuery().eq(GoodsApply::getWebsitId,goodsApplyAddUp.getWebsitId())
+        .eq(GoodsApply::getGoodsId,goodsApplyAddUp.getGoodsId()).count() > 0)
+            throw new RemoteServiceException("商品存在价格调整,请去申请调整修改");
 
-        goodsApplyAddUp.insert();
 
         List<GoodsSpec> goodsSpecs = goodsSpecService.lambdaQuery().eq(GoodsSpec::getGoodsId, goodsApplyAddUp.getGoodsId())
                 .list();
 
         List<GoodsApplyItem> goodsApplyItemList = new ArrayList<>();
 
+        Boolean ifStatus = true;
+
         for (GoodsSpec goodsSpec : goodsSpecs) {
             List<GoodsApplyItem> goodsApplyItems = goodsApplyAddUp.getGoodsApplyItems().stream()
                     .filter(item -> item.getGoodsSpecId().equals(goodsSpec.getGoodsSpecId()))
@@ -117,6 +126,11 @@ public class GoodsApplyLogic {
                 goodsApplyItems.get(0).setGoodsId(goodsSpec.getGoodsId());
                 goodsApplyItems.get(0).setGoodsApplyId(goodsApplyAddUp.getGoodsApplyId());
                 goodsApplyItemList.add(goodsApplyItems.get(0));
+
+                if (goodsSpec.getMinPrice().doubleValue() > goodsApplyItems.get(0).getApplyPrice().doubleValue() || goodsSpec.getMaxPrice().doubleValue() < goodsApplyItems.get(0).getApplyPrice().doubleValue())
+                    ifStatus = false;
+
+
             }else {
                 GoodsApplyItem goodsApplyItem = new GoodsApplyItem();
                 goodsApplyItem.setGoodsId(goodsSpec.getGoodsId());
@@ -124,9 +138,20 @@ public class GoodsApplyLogic {
                 goodsApplyItem.setGoodsSpecId(goodsSpec.getGoodsSpecId());
                 goodsApplyItem.setGoodsApplyId(goodsApplyAddUp.getGoodsApplyId());
                 goodsApplyItemList.add(goodsApplyItem);
+
+                if (goodsSpec.getMinPrice().doubleValue() > goodsApplyItem.getApplyPrice().doubleValue() || goodsSpec.getMaxPrice().doubleValue() < goodsApplyItem.getApplyPrice().doubleValue())
+                    ifStatus = false;
             }
+
         }
 
+        if (ifStatus)
+            goodsApplyAddUp.setStatus(ExamineStatusEnum.OK.getKey());
+        else
+            goodsApplyAddUp.setStatus(ExamineStatusEnum.WAIT.getKey());
+
+        goodsApplyAddUp.insert();
+
         goodsApplyItemService.saveBatch(goodsApplyItemList);
     }
 
@@ -142,6 +167,8 @@ public class GoodsApplyLogic {
 
         List<GoodsApplyItem> goodsApplyItemList = new ArrayList<>();
 
+        Boolean ifStatus = true;
+
         for (GoodsSpec goodsSpec : goodsSpecs) {
             List<GoodsApplyItem> goodsApplyItems = goodsApplyAddUp.getGoodsApplyItems().stream()
                     .filter(item -> item.getGoodsSpecId().equals(goodsSpec.getGoodsSpecId()))
@@ -151,6 +178,9 @@ public class GoodsApplyLogic {
                 goodsApplyItems.get(0).setGoodsId(goodsSpec.getGoodsId());
                 goodsApplyItems.get(0).setGoodsApplyId(goodsApplyAddUp.getGoodsApplyId());
                 goodsApplyItemList.add(goodsApplyItems.get(0));
+
+                if (goodsSpec.getMinPrice().doubleValue() > goodsApplyItems.get(0).getApplyPrice().doubleValue() || goodsSpec.getMaxPrice().doubleValue() < goodsApplyItems.get(0).getApplyPrice().doubleValue())
+                    ifStatus = false;
             }else {
                 GoodsApplyItem goodsApplyItem = new GoodsApplyItem();
                 goodsApplyItem.setGoodsId(goodsSpec.getGoodsId());
@@ -158,9 +188,24 @@ public class GoodsApplyLogic {
                 goodsApplyItem.setGoodsSpecId(goodsSpec.getGoodsSpecId());
                 goodsApplyItem.setGoodsApplyId(goodsApplyAddUp.getGoodsApplyId());
                 goodsApplyItemList.add(goodsApplyItem);
+
+                if (goodsSpec.getMinPrice().doubleValue() > goodsApplyItem.getApplyPrice().doubleValue() || goodsSpec.getMaxPrice().doubleValue() < goodsApplyItem.getApplyPrice().doubleValue())
+                    ifStatus = false;
             }
         }
 
+        if (ifStatus)
+            goodsApplyAddUp.setStatus(ExamineStatusEnum.OK.getKey());
+        else
+            goodsApplyAddUp.setStatus(ExamineStatusEnum.WAIT.getKey());
+
         goodsApplyItemService.saveBatch(goodsApplyItemList);
     }
+
+    public void approve(String goodsApplyId, String status) {
+        GoodsApply goodsApply = new GoodsApply();
+        goodsApply.setGoodsApplyId(goodsApplyId);
+        goodsApply.setStatus(status);
+        goodsApply.updateById();
+    }
 }