DESKTOP-71BH0QO\L、ming
2021-04-21 3ffa739e77cdafdc4be1aa153acb3423071cd102
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopStoreServiceImpl.java
@@ -1,17 +1,20 @@
package com.panzhihua.service_community.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.shop.PageComShopStoreDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.shop.*;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.service_community.dao.ComShopGoodsAttrDAO;
import com.panzhihua.service_community.dao.ComShopGoodsDAO;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.common.model.vos.shop.ShopStoreVO;
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.ComShopGoodsAttrDO;
import com.panzhihua.service_community.model.dos.ComShopStoreDO;
import com.panzhihua.service_community.service.ComShopStoreService;
import lombok.extern.slf4j.Slf4j;
@@ -32,6 +35,8 @@
    @Resource
    private ComShopGoodsDAO shopGoodsDAO;
    @Resource
    private ComShopGoodsAttrDAO comShopGoodsAttrDAO;
    /**
     * 查询店铺列表
@@ -68,8 +73,18 @@
        //查询店铺下商品信息
        Page page = new Page<>(comShopStoreDTO.getPageNum(), comShopStoreDTO.getPageSize());
        shopStoreVO.setGoodsList(shopGoodsDAO.pageShopGoodsByStoreId(page, comShopStoreDTO).getRecords());
        List<ComShopGoodsVO> goodsList = shopGoodsDAO.pageShopGoodsByStoreId(page, comShopStoreDTO).getRecords();
        if(!goodsList.isEmpty()){
            //查询商品规格列表
            goodsList.forEach(goods -> {
                List<ComShopGoodsAttrVO> goodsAttrList = comShopGoodsAttrDAO.getGoodsAttr(goods.getId());
                if(!goodsAttrList.isEmpty()){
                    goods.setGoodsAttrList(goodsAttrList);
                }
            });
        }
        shopStoreVO.setGoodsList(goodsList);
        return R.ok(shopStoreVO);
    }
@@ -77,12 +92,12 @@
    @Override
    public R saveStore(ShopStoreVO storeVO) {
        if (storeVO == null) {
            return R.ok("500", "数据为空!");
            return R.fail("500", "数据为空!");
        }
        ComShopStoreDO comShopStoreDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopStoreDO>()
                .eq(ComShopStoreDO::getStoreAccount, storeVO.getStoreAccount()));
        if (comShopStoreDO != null) {
            return R.ok("500", "商家账号存在");
            return R.fail("500", "商家账号存在");
        }
        ComShopStoreDO storeDO = new ComShopStoreDO();
        BeanUtils.copyProperties(storeVO, storeDO);
@@ -94,7 +109,7 @@
    @Override
    public R editStore(Long id, ShopStoreVO storeVO) {
        if (storeVO == null) {
            return R.ok("500", "数据为空!");
            return R.fail("500", "数据为空!");
        }
        LambdaQueryWrapper<ComShopStoreDO> query = new LambdaQueryWrapper<ComShopStoreDO>().eq(ComShopStoreDO::getId, id);
        ComShopStoreDO storeDO = new ComShopStoreDO();
@@ -107,9 +122,23 @@
    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("店铺下有商品正在出售,无法删除店铺");
                }
                shopStoreDO.setDeleteStatus(2);
                this.baseMapper.updateById(shopStoreDO);
            }
        }else {
            return R.fail("未查询到店铺");
        }
        return R.ok();
    }
@@ -135,4 +164,15 @@
        BeanUtils.copyProperties(comShopStoreDO, shopStoreVO);
        return R.ok(shopStoreVO);
    }
    @Override
    public R getStoreByPhone(String phone) {
        LambdaQueryWrapper<ComShopStoreDO> query = new LambdaQueryWrapper<ComShopStoreDO>();
        query.eq(ComShopStoreDO::getPhone, phone);
        query.eq(ComShopStoreDO::getDeleteStatus, 1);
        ComShopStoreDO comShopStoreDO = this.baseMapper.selectOne(query);
        ShopStoreVO shopStoreVO = new ShopStoreVO();
        BeanUtils.copyProperties(comShopStoreDO, shopStoreVO);
        return R.ok(shopStoreVO);
    }
}