jiangqs
2023-05-05 aa8f41d3b4fcc7aae0bd50fdea92b126f22485df
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package com.ruoyi.order.service.impl.goods;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.order.domain.dto.*;
import com.ruoyi.order.domain.pojo.goods.Goods;
import com.ruoyi.order.domain.pojo.goods.GoodsFile;
import com.ruoyi.order.domain.pojo.goods.ShopGoods;
import com.ruoyi.order.domain.vo.AppGoodsInfoVo;
import com.ruoyi.order.domain.vo.AppSimpleActivityGoodsVo;
import com.ruoyi.order.domain.vo.AppSimpleGoodsVo;
import com.ruoyi.order.domain.vo.MerGoodsPageVo;
import com.ruoyi.order.mapper.goods.GoodsMapper;
import com.ruoyi.order.service.activity.ActivityGoodsService;
import com.ruoyi.order.service.goods.GoodsFileService;
import com.ruoyi.order.service.goods.GoodsService;
import com.ruoyi.order.service.goods.ShopGoodsService;
import com.ruoyi.system.api.RemoteActivityService;
import com.ruoyi.system.api.constant.AppErrorConstant;
import com.ruoyi.system.api.domain.poji.activity.ActivityGoods;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.StringJoiner;
 
/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author jqs
 * @since 2023-04-25
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
 
    @Resource
    private GoodsMapper goodsMapper;
 
    @Resource
    private ActivityGoodsService activityGoodsService;
 
    @Resource
    private ShopGoodsService shopGoodsService;
 
    @Resource
    private GoodsFileService goodsFileService;
 
    /**
     * 获取推荐商品列表
     * @param page
     * @return
     */
    @Override
    public List<AppSimpleGoodsVo> pageRecommendGoods(Page page, Long shopId){
        List<AppSimpleGoodsVo> appSimpleGoodsVoList = goodsMapper.pageRecommendGoods(page,shopId);
        return appSimpleGoodsVoList;
    }
 
    /**
     * 获取商城商品列表
     * @param page
     * @param appShopGoodsPageDto
     * @return
     */
    @Override
    public List<AppSimpleGoodsVo> pageShopGoods(Page page, AppShopGoodsPageDto appShopGoodsPageDto){
        List<AppSimpleGoodsVo> appSimpleGoodsVoList = goodsMapper.pageShopGoods(page,appShopGoodsPageDto);
        return appSimpleGoodsVoList;
    }
 
    /**
     * 获取搜索商品列表
     * @param page
     * @param appSearchGoodsPageDto
     * @return
     */
    @Override
    public List<AppSimpleGoodsVo> pageSearchGoods(Page page, AppSearchGoodsPageDto appSearchGoodsPageDto){
        List<AppSimpleGoodsVo> appSimpleGoodsVoList = goodsMapper.pageSearchGoods(page,appSearchGoodsPageDto);
        return appSimpleGoodsVoList;
    }
 
    /**
     * 获取搜索商品列表
     * @param page
     * @param appSearchGoodsPageDto
     * @return
     */
    @Override
    public List<AppSimpleActivityGoodsVo> pageSearchActivityGoods(Page page, AppSearchGoodsPageDto appSearchGoodsPageDto){
        List<AppSimpleActivityGoodsVo> appSimpleGoodsVoList = goodsMapper.pageSearchActivityGoods(page,appSearchGoodsPageDto);
        Integer activityNumber;
        BigDecimal activityNumberBig;
        Integer salesNumber;
        BigDecimal salesNumberBig;
        BigDecimal salesPercent;
        for(AppSimpleActivityGoodsVo appSimpleActivityGoodsVo : appSimpleGoodsVoList){
            activityNumber = appSimpleActivityGoodsVo.getActivityNumber();
            salesNumber = appSimpleActivityGoodsVo.getSalesNumber();
            activityNumberBig = BigDecimal.valueOf(activityNumber);
            salesNumberBig = BigDecimal.valueOf(salesNumber);
            salesPercent = salesNumberBig.divide(activityNumberBig,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100.00"));
            appSimpleActivityGoodsVo.setSalesPercent(salesPercent);
        }
        return appSimpleGoodsVoList;
    }
 
    /**
     * 获取商品详情
     * @param appGoodsInfoGetDto
     * @return
     */
    @Override
    public AppGoodsInfoVo getGoodsInfo(AppGoodsInfoGetDto appGoodsInfoGetDto){
        AppGoodsInfoVo appGoodsInfoVo = new AppGoodsInfoVo();
        Goods goods = this.getById(appGoodsInfoGetDto.getId());
        BeanUtils.copyProperties(goods, appGoodsInfoVo);
        //商户定制价格
        ShopGoods shopGoods = shopGoodsService.getByShopIdAndGoodsId(appGoodsInfoGetDto.getShopId(),goods.getGoodsId());
        if(shopGoods!=null){
            appGoodsInfoVo.setSalesPrice(shopGoods.getSalesPrice());
            appGoodsInfoVo.setSalesNum(shopGoods.getServiceNum());
        }
        //活动商品判断
        if(appGoodsInfoGetDto.getActivityFlag()==1){
            ActivityGoods activityGoods = activityGoodsService.getByGoodsId(goods.getGoodsId());
            //原价取较大值
            if(shopGoods!=null&&goods.getSalesPrice().compareTo(shopGoods.getSalesPrice())>0){
                appGoodsInfoVo.setSalesPrice(goods.getSalesPrice());
            }
            appGoodsInfoVo.setActivityFlag(1);
            appGoodsInfoVo.setActivityPrice(activityGoods.getActivityPrice());
            appGoodsInfoVo.setSalesNum(activityGoods.getSalesNumber());
            appGoodsInfoVo.setActivityDeadline(activityGoods.getActivityDeadline());
            //售罄判断
            if(activityGoods.getActivityNumber()==activityGoods.getSalesNumber()){
                appGoodsInfoVo.setSellOutFlag(1);
            }else{
                appGoodsInfoVo.setSellOutFlag(0);
            }
        }else{
            appGoodsInfoVo.setActivityFlag(0);
        }
        //商品图片
        List<GoodsFile> goodsFileList = goodsFileService.listByGoodsId(goods.getGoodsId());
        StringJoiner bannerSJ = new StringJoiner(",");
        if(goodsFileList!=null&&!goodsFileList.isEmpty()){
            for(GoodsFile goodsFile : goodsFileList){
                if(goodsFile.getFileType()==2){
                    appGoodsInfoVo.setGoodsVideo(goodsFile.getFileUrl());
                }else if(goodsFile.getFileType()==3){
                    bannerSJ.add(goodsFile.getFileUrl());
                }
            }
            if(bannerSJ!=null&&bannerSJ.length()>0){
                appGoodsInfoVo.setGoodsBanners(bannerSJ.toString());
            }
        }
        return appGoodsInfoVo;
    }
 
    /**
     * 分页商户商品列表
     * @param merGoodsPageDto
     * @return
     */
    @Override
    public List<MerGoodsPageVo> pageMerShopGoods(Page page,MerGoodsPageDto merGoodsPageDto){
        List<MerGoodsPageVo> merGoodsPageVoList = goodsMapper.pageMerShopGoods(page,merGoodsPageDto);
        return merGoodsPageVoList;
 
    }
 
 
    /**
     * 修改商户商品
     * @param merShopGoodsEditDto
     */
    @Override
    public void editMerShopGoods(MerShopGoodsEditDto merShopGoodsEditDto){
        Goods goods = this.getById(merShopGoodsEditDto.getGoodsId());
        if(merShopGoodsEditDto.getSalePrice().compareTo(goods.getMininumPrice())<0){
            throw new ServiceException(AppErrorConstant.SALESPRICE_MIN+goods.getMininumPrice().toString()+"元");
        }
        //商户定制价格
        ShopGoods shopGoods = shopGoodsService.getByShopIdAndGoodsId(merShopGoodsEditDto.getShopId(),goods.getGoodsId());
        if(shopGoods!=null){
            shopGoods.setSalesPrice(merShopGoodsEditDto.getSalePrice());
            shopGoods.setServiceNum(merShopGoodsEditDto.getServiceNum());
            shopGoods.setUpdateTime(new Date());
            shopGoods.setUpdateUserId(merShopGoodsEditDto.getUserId());
        }else{
            shopGoods = new ShopGoods();
            shopGoods.setDelFlag(0);
            shopGoods.setShopId(merShopGoodsEditDto.getShopId());
            shopGoods.setGoodsId(merShopGoodsEditDto.getGoodsId());
            shopGoods.setSalesPrice(merShopGoodsEditDto.getSalePrice());
            shopGoods.setServiceNum(merShopGoodsEditDto.getServiceNum());
            shopGoods.setUpdateTime(new Date());
            shopGoods.setUpdateUserId(merShopGoodsEditDto.getUserId());
        }
        shopGoodsService.saveOrUpdate(shopGoods);
    }
}