huanghongfa
2021-04-21 970ed0f8df6a19e4e3dae062c4e2e2232a0b97d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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.service_community.dao.ComShopGoodsAttrDAO;
import com.panzhihua.service_community.dao.ComShopGoodsDAO;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
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.ComShopStoreDO;
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.List;
 
/**
 * @auther lyq
 * @create 2021-04-14 15:03:55
 * @describe 店铺表服务实现类
 */
@Slf4j
@Service
public class ComShopStoreServiceImpl extends ServiceImpl<ComShopStoreDAO, ComShopStoreDO> implements ComShopStoreService {
 
    @Resource
    private ComShopGoodsDAO shopGoodsDAO;
    @Resource
    private ComShopGoodsAttrDAO comShopGoodsAttrDAO;
 
    /**
     * 查询店铺列表
     *
     * @param pageComShopStoreDTO 请求参数
     * @return 店铺列表
     */
 
    @Override
    public R pageStoreList(PageComShopStoreDTO pageComShopStoreDTO) {
        Page page = new Page<>(pageComShopStoreDTO.getPageNum(), pageComShopStoreDTO.getPageSize());
        IPage<PageShopStoreVO> comShopStoreVOIPage = this.baseMapper.pageShopStore(page, pageComShopStoreDTO);
        return R.ok(comShopStoreVOIPage);
    }
 
    /**
     * 查询店铺详情
     *
     * @param comShopStoreDTO 请求参数
     * @return 店铺详情
     */
    @Override
    public R shopStoreDetail(PageComShopStoreDTO comShopStoreDTO) {
        //查询店铺
        ComShopStoreDO storeDO = this.baseMapper.selectById(comShopStoreDTO.getStoreId());
        if (storeDO == null) {
            return R.fail(401, "店铺不存在");
        }
        if (storeDO.getStatus().equals(ComShopStoreDO.status.no)) {
            return R.fail(402, "店铺已被禁用");
        }
        PageShopStoreVO shopStoreVO = new PageShopStoreVO();
        BeanUtils.copyProperties(storeDO, shopStoreVO);
 
        //查询店铺下商品信息
        Page page = new Page<>(comShopStoreDTO.getPageNum(), comShopStoreDTO.getPageSize());
 
        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);
 
    }
 
    @Override
    public R saveStore(ShopStoreVO storeVO) {
        if (storeVO == null) {
            return R.ok("500", "数据为空!");
        }
        ComShopStoreDO comShopStoreDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopStoreDO>()
                .eq(ComShopStoreDO::getStoreAccount, storeVO.getStoreAccount()));
        if (comShopStoreDO != null) {
            return R.ok("500", "商家账号存在");
        }
        ComShopStoreDO storeDO = new ComShopStoreDO();
        BeanUtils.copyProperties(storeVO, storeDO);
        storeDO.setSale(0);
        this.baseMapper.insert(storeDO);
        return R.ok();
    }
 
    @Override
    public R editStore(Long id, ShopStoreVO storeVO) {
        if (storeVO == null) {
            return R.ok("500", "数据为空!");
        }
        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();
    }
 
    @Override
    public R deleteStore(Long[] id) {
        LambdaQueryWrapper<ComShopStoreDO> query = new LambdaQueryWrapper<ComShopStoreDO>().in(ComShopStoreDO::getId, id);
        List<ComShopStoreDO> comShopStoreDO = this.baseMapper.selectList(query);
        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();
    }
 
    @Override
    public R getOneInfo(Long id) {
        ComShopStoreDO comShopStoreDO = this.baseMapper.selectById(id);
        if (comShopStoreDO == null) {
            R.fail(500, "商铺不存在");
        }
        ShopStoreVO shopStoreVO = new ShopStoreVO();
        BeanUtils.copyProperties(comShopStoreDO, shopStoreVO);
        return R.ok(shopStoreVO);
    }
 
    @Override
    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, "商铺不存在");
        }
        ShopStoreVO shopStoreVO = new ShopStoreVO();
        BeanUtils.copyProperties(comShopStoreDO, shopStoreVO);
        return R.ok(shopStoreVO);
    }
}