From a3aa71fd0ba1b48fe52f080e8d2776f50c5ed514 Mon Sep 17 00:00:00 2001
From: CeDo <cedoogle@gmail.com>
Date: 星期二, 27 四月 2021 11:32:36 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopStoreServiceImpl.java |   91 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 76 insertions(+), 15 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopStoreServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopStoreServiceImpl.java
index bb925ad..7ecccad 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopStoreServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopStoreServiceImpl.java
@@ -19,14 +19,20 @@
 import com.panzhihua.service_community.dao.ComShopStoreDAO;
 import com.panzhihua.service_community.model.dos.ComShopGoodsAttrDO;
 import com.panzhihua.service_community.model.dos.ComShopGoodsDO;
+import com.panzhihua.service_community.model.dos.ComShopOrderDO;
 import com.panzhihua.service_community.model.dos.ComShopStoreDO;
+import com.panzhihua.service_community.service.ComShopOrderService;
 import com.panzhihua.service_community.service.ComShopStoreService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * @auther lyq
@@ -42,8 +48,9 @@
     @Resource
     private ComShopGoodsAttrDAO comShopGoodsAttrDAO;
     @Resource
+    private ComShopOrderService orderService;
+    @Resource
     private UserService userService;
-
     /**
      * 查询店铺列表
      *
@@ -54,7 +61,27 @@
     @Override
     public R pageStoreList(PageComShopStoreDTO pageComShopStoreDTO) {
         Page page = new Page<>(pageComShopStoreDTO.getPageNum(), pageComShopStoreDTO.getPageSize());
-        IPage<PageShopStoreVO> comShopStoreVOIPage = this.baseMapper.pageShopStoreByAdmin(page, pageComShopStoreDTO);
+        IPage<PageShopStoreVO> comShopStoreVOIPage = this.baseMapper.pageShopStore(page, pageComShopStoreDTO);
+        if(comShopStoreVOIPage!=null){
+            Optional.ofNullable(comShopStoreVOIPage.getRecords()).orElse(new ArrayList<>()).forEach(shopStoreVO ->{
+                List<Integer> notDoneOrderStatus = new ArrayList<>();
+                notDoneOrderStatus.add(1);
+                notDoneOrderStatus.add(2);
+                notDoneOrderStatus.add(3);
+                notDoneOrderStatus.add(4);
+                Integer orderCount = orderService.getBaseMapper()
+                        .selectCount(new LambdaQueryWrapper<ComShopOrderDO>()
+                                .eq(ComShopOrderDO::getStoreId, shopStoreVO.getId())
+                                .eq(ComShopOrderDO::getDeleteStatus, 1)
+                                .in(ComShopOrderDO::getStatus, notDoneOrderStatus)
+                        );
+                if(orderCount==null || orderCount.intValue() <= 0){
+                    shopStoreVO.setOrderDone(true);
+                }else{
+                    shopStoreVO.setOrderDone(false);
+                }
+            });
+        }
         return R.ok(comShopStoreVOIPage);
     }
 
@@ -133,8 +160,10 @@
         ComShopStoreDO oldComShopStoreDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopStoreDO>()
                 .eq(ComShopStoreDO::getStoreAccount, storeVO.getStoreAccount()).eq(ComShopStoreDO::getDeleteStatus,ComShopStoreDO.deleteStatus.no));
         if (oldComShopStoreDO != null) {
-            return R.fail("商家已注册");
+            return R.fail("商家账号已注册");
         }
+        //TODO 判断用户
+        //this.baseMapper.select(storeVO.getPhone());
         //新增店铺先判断是否拥有已删除的店铺
         ComShopStoreDO comShopStoreDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopStoreDO>()
                 .eq(ComShopStoreDO::getStoreAccount, storeVO.getStoreAccount()).eq(ComShopStoreDO::getDeleteStatus,ComShopStoreDO.deleteStatus.yes));
@@ -162,23 +191,52 @@
 
     @Override
     public R editStore(Long id, ShopStoreVO storeVO) {
-        if (storeVO == null) {
-            return R.ok("500", "数据为空!");
+        ComShopStoreDO storeDO = this.baseMapper.selectById(id);
+        if(storeDO == null){
+            return R.fail("商家不存在");
         }
-        LambdaQueryWrapper<ComShopStoreDO> query = new LambdaQueryWrapper<ComShopStoreDO>().eq(ComShopStoreDO::getId, id);
-        ComShopStoreDO storeDO = new ComShopStoreDO();
         BeanUtils.copyProperties(storeVO, storeDO);
-        int update = this.baseMapper.update(storeDO, query);
-        return update > 0 ? R.ok() : R.fail();
+        if(this.baseMapper.updateById(storeDO) > 0){
+            return R.ok();
+        }else{
+            return R.fail();
+        }
     }
 
     @Override
     public R deleteStore(Long[] id) {
         LambdaQueryWrapper<ComShopStoreDO> query = new LambdaQueryWrapper<ComShopStoreDO>().in(ComShopStoreDO::getId, id);
         List<ComShopStoreDO> comShopStoreDO = this.baseMapper.selectList(query);
-        for (ComShopStoreDO shopStoreDO:comShopStoreDO) {
-            shopStoreDO.setDeleteStatus(2);
-            int update = this.baseMapper.updateById(shopStoreDO);
+        if(!comShopStoreDO.isEmpty()){
+            for (ComShopStoreDO shopStoreDO:comShopStoreDO) {
+                //判断店铺下是否拥有正常的商品
+                List<ComShopGoodsDO> shopGoodsList = shopGoodsDAO.selectList(new QueryWrapper<ComShopGoodsDO>()
+                        .lambda().eq(ComShopGoodsDO::getStoreId,shopStoreDO.getId())
+                        .eq(ComShopGoodsDO::getDeleteStatus,ComShopGoodsDO.deleteStatus.no)
+                        .eq(ComShopGoodsDO::getStatus,ComShopGoodsDO.status.sell));
+                if(!shopGoodsList.isEmpty()){//如果有正常商品则提示无法删除
+                    return R.fail("店铺下有商品正在出售,无法删除店铺");
+                }
+                List<ComShopOrderDO> comShopOrderDOS = orderService.getBaseMapper().selectList(new LambdaQueryWrapper<ComShopOrderDO>()
+                        .eq(ComShopOrderDO::getStoreId,shopStoreDO.getId()));
+                List<ComShopOrderDO> filterOrder = comShopOrderDOS.stream()
+                        .filter(order -> order.getStatus() < ComShopOrderDO.status.dpj)
+                        .collect(Collectors.toList());
+                if(!filterOrder.isEmpty()){
+                    return R.fail("该商家还有订单未完成,不能删除");
+                }
+                //删除商家下的订单
+                comShopOrderDOS.forEach(order->{
+                    order.setDeleteStatus(ComShopOrderDO.deleteStatus.yes);
+                    orderService.getBaseMapper().updateById(order);
+                });
+                shopStoreDO.setDeleteStatus(2);
+                this.baseMapper.updateById(shopStoreDO);
+                //删除sys_user 物理删除
+                this.baseMapper.deleteSysUserBySysUserId(shopStoreDO.getSysUserId());
+            }
+        }else {
+            return R.fail("未查询到店铺");
         }
         return R.ok();
     }
@@ -187,7 +245,7 @@
     public R getOneInfo(Long id) {
         ComShopStoreDO comShopStoreDO = this.baseMapper.selectById(id);
         if (comShopStoreDO == null) {
-            R.fail(500, "商铺不存在");
+            return R.fail(500, "商铺不存在");
         }
         ShopStoreVO shopStoreVO = new ShopStoreVO();
         BeanUtils.copyProperties(comShopStoreDO, shopStoreVO);
@@ -198,7 +256,7 @@
     public R getUserStoreInfo(Long userId) {
         ComShopStoreDO comShopStoreDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopStoreDO>().eq(ComShopStoreDO::getDeleteStatus, 1).eq(ComShopStoreDO::getSysUserId, userId));
         if (comShopStoreDO == null) {
-            R.fail(500, "商铺不存在");
+            return R.fail(500, "商铺不存在");
         }
         ShopStoreVO shopStoreVO = new ShopStoreVO();
         BeanUtils.copyProperties(comShopStoreDO, shopStoreVO);
@@ -211,10 +269,13 @@
             R<LoginUserInfoVO> loginUserInfoVOR = userService.getUserInfo(account+"_5");
             LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(loginUserInfoVOR.getData()), LoginUserInfoVO.class);
 
+            if(loginUserInfoVO==null){
+                return R.fail(500, "该账号不存在");
+            }
             ComShopStoreDO comShopStoreDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopStoreDO>()
                     .eq(ComShopStoreDO::getDeleteStatus, 1).eq(ComShopStoreDO::getSysUserId, loginUserInfoVO.getUserId()));
             if (comShopStoreDO == null) {
-                R.fail(500, "商铺不存在");
+                return  R.fail(500, "该账号不存在");
             }
             ShopStoreVO shopStoreVO = new ShopStoreVO();
             BeanUtils.copyProperties(comShopStoreDO, shopStoreVO);

--
Gitblit v1.7.1