|
@@ -58,6 +58,8 @@ public class GoodsLogic {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
GoodsTagRelaService goodsTagRelaService;
|
|
GoodsTagRelaService goodsTagRelaService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ GoodsMaterialStorageService goodsMaterialStorageService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 商品列表
|
|
* 商品列表
|
|
@@ -112,18 +114,17 @@ public class GoodsLogic {
|
|
|
/**
|
|
/**
|
|
|
* 商品详情
|
|
* 商品详情
|
|
|
*/
|
|
*/
|
|
|
- public GoodsBean detail(HttpServletRequest request, String goodsId,String userId,String wxSceneId){
|
|
|
|
|
|
|
+ public GoodsBean detail(HttpServletRequest request, String goodsId, String userId, String storageId) {
|
|
|
CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
|
|
|
|
|
|
User user = userService.getById(userId);
|
|
User user = userService.getById(userId);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- GoodsBean goodsBean = this.commonDetail(goodsId, user,wxSceneId);
|
|
|
|
|
|
|
+ GoodsBean goodsBean = this.commonDetail(goodsId, user, storageId);
|
|
|
|
|
|
|
|
//补充标签
|
|
//补充标签
|
|
|
//查询上标签
|
|
//查询上标签
|
|
|
List<GoodsTagRela> list1 = goodsTagRelaService.lambdaQuery().eq(GoodsTagRela::getGoodsId, goodsBean.getGoodsId())
|
|
List<GoodsTagRela> list1 = goodsTagRelaService.lambdaQuery().eq(GoodsTagRela::getGoodsId, goodsBean.getGoodsId())
|
|
|
- .eq(GoodsTagRela::getType,1).list();
|
|
|
|
|
|
|
+ .eq(GoodsTagRela::getType, 1).list();
|
|
|
if (list1.size() > 0) {
|
|
if (list1.size() > 0) {
|
|
|
List<String> collect1 = list1.stream().map(GoodsTagRela::getGoodsTagName).collect(Collectors.toList());
|
|
List<String> collect1 = list1.stream().map(GoodsTagRela::getGoodsTagName).collect(Collectors.toList());
|
|
|
goodsBean.setTags1(collect1);
|
|
goodsBean.setTags1(collect1);
|
|
@@ -132,7 +133,7 @@ public class GoodsLogic {
|
|
|
//查询活动专区标签 //查询下标签
|
|
//查询活动专区标签 //查询下标签
|
|
|
//活动商品
|
|
//活动商品
|
|
|
List<GoodsTagRela> list2 = goodsTagRelaService.lambdaQuery().eq(GoodsTagRela::getGoodsId, goodsBean.getGoodsId())
|
|
List<GoodsTagRela> list2 = goodsTagRelaService.lambdaQuery().eq(GoodsTagRela::getGoodsId, goodsBean.getGoodsId())
|
|
|
- .eq(GoodsTagRela::getType,2).list();
|
|
|
|
|
|
|
+ .eq(GoodsTagRela::getType, 2).list();
|
|
|
if (list2.size() > 0) {
|
|
if (list2.size() > 0) {
|
|
|
List<String> collect1 = list2.stream().map(GoodsTagRela::getGoodsTagName).collect(Collectors.toList());
|
|
List<String> collect1 = list2.stream().map(GoodsTagRela::getGoodsTagName).collect(Collectors.toList());
|
|
|
goodsBean.setTags2(collect1);
|
|
goodsBean.setTags2(collect1);
|
|
@@ -140,17 +141,15 @@ public class GoodsLogic {
|
|
|
|
|
|
|
|
|
|
|
|
|
//记录用户浏览记录
|
|
//记录用户浏览记录
|
|
|
- if(user != null) {
|
|
|
|
|
|
|
+ if (user != null) {
|
|
|
GoodsVisit goodsVisit = new GoodsVisit();
|
|
GoodsVisit goodsVisit = new GoodsVisit();
|
|
|
goodsVisit.setGoodsId(goodsId);
|
|
goodsVisit.setGoodsId(goodsId);
|
|
|
goodsVisit.setGoodsName(goodsBean.getGoodsName());
|
|
goodsVisit.setGoodsName(goodsBean.getGoodsName());
|
|
|
goodsVisit.setUserId(userId);
|
|
goodsVisit.setUserId(userId);
|
|
|
goodsVisit.setUserName(user.getNickName());
|
|
goodsVisit.setUserName(user.getNickName());
|
|
|
goodsVisit.setUserPhone(user.getMobile());
|
|
goodsVisit.setUserPhone(user.getMobile());
|
|
|
- goodsVisit.setPromotionGroupId(goodsBean.getPromotionGroupId());
|
|
|
|
|
goodsVisit.setGoodsPrice(goodsBean.getGoodsPrice());
|
|
goodsVisit.setGoodsPrice(goodsBean.getGoodsPrice());
|
|
|
goodsVisit.setGoodsStatus(goodsBean.getStatus());
|
|
goodsVisit.setGoodsStatus(goodsBean.getStatus());
|
|
|
- goodsVisit.setShareUserId(goodsBean.getGroupUserId());
|
|
|
|
|
goodsVisit.setGoodsImg(goodsBean.getImgUrl());
|
|
goodsVisit.setGoodsImg(goodsBean.getImgUrl());
|
|
|
goodsVisit.setCompanyWechatId(currentCompanyWechat.getCurrentCompanyWechatId());
|
|
goodsVisit.setCompanyWechatId(currentCompanyWechat.getCurrentCompanyWechatId());
|
|
|
goodsVisit.setCompanyName(currentCompanyWechat.getCurrentCompanyName());
|
|
goodsVisit.setCompanyName(currentCompanyWechat.getCurrentCompanyName());
|
|
@@ -167,18 +166,8 @@ public class GoodsLogic {
|
|
|
* @param goodsId
|
|
* @param goodsId
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public GoodsBean commonDetail(String goodsId,User user,String wxSceneId) throws RemoteServiceException {
|
|
|
|
|
- User service = null;
|
|
|
|
|
- String serviceId = null;
|
|
|
|
|
- AdminCompanyWechat adminCompanyWechat = null;
|
|
|
|
|
- if(user != null) {
|
|
|
|
|
- serviceId = user.getServiceId();
|
|
|
|
|
- if (user.getType().equals(UserTypeEnum.SERVICE.toString())) {
|
|
|
|
|
- serviceId = user.getUserId();
|
|
|
|
|
- }
|
|
|
|
|
- service = userService.getById(serviceId);
|
|
|
|
|
- adminCompanyWechat = commonLogic.getAdminCompanyWechat(user.getCompanyWechatId());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public GoodsBean commonDetail(String goodsId, User user, String storageId) throws RemoteServiceException {
|
|
|
|
|
+ AdminCompanyWechat adminCompanyWechat = commonLogic.getAdminCompanyWechat(user.getCompanyWechatId());
|
|
|
|
|
|
|
|
Goods goods = goodsService.lambdaQuery()
|
|
Goods goods = goodsService.lambdaQuery()
|
|
|
.eq(Goods::getGoodsId, goodsId)
|
|
.eq(Goods::getGoodsId, goodsId)
|
|
@@ -188,33 +177,38 @@ public class GoodsLogic {
|
|
|
if (goods == null) {
|
|
if (goods == null) {
|
|
|
throw new RemoteServiceException("商品不存在或已下架");
|
|
throw new RemoteServiceException("商品不存在或已下架");
|
|
|
}
|
|
}
|
|
|
- //商品规格(包含秒杀商品)
|
|
|
|
|
|
|
+ //商品规格
|
|
|
List<GoodsSpecSecBean> goodsSpecs = goodsSpecDetailMapper.querySpecSec(goodsId);
|
|
List<GoodsSpecSecBean> goodsSpecs = goodsSpecDetailMapper.querySpecSec(goodsId);
|
|
|
- //是否有收藏
|
|
|
|
|
- Integer goodsFavoritesCount = 0;
|
|
|
|
|
- if (Objects.nonNull(user)) {
|
|
|
|
|
- // 有user对象再查找
|
|
|
|
|
- goodsFavoritesCount = goodsFavoriteService.lambdaQuery()
|
|
|
|
|
- .eq(GoodsFavorite::getGoodsId, goodsId)
|
|
|
|
|
- .eq(GoodsFavorite::getUserId, user.getUserId())
|
|
|
|
|
- .count();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ final List<String> goodsMaterialIds = goodsSpecs.stream().map(GoodsSpecSecBean::getGoodsCode).collect(Collectors.toList());
|
|
|
|
|
|
|
|
- //商品库存
|
|
|
|
|
- Integer goodsStock = goodsSpecs.stream().mapToInt(GoodsSpec::getStockNum).sum();
|
|
|
|
|
- GoodsBean goodsBean = new GoodsBean();
|
|
|
|
|
- BeanUtils.copyProperties(goods, goodsBean);
|
|
|
|
|
|
|
+ // 获取规格库存
|
|
|
|
|
+ final Map<String, Integer> goodsMaterialStorageMap = goodsMaterialStorageService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsMaterialStorage::getStorageId, storageId)
|
|
|
|
|
+ .in(GoodsMaterialStorage::getGoodsMaterialId, goodsMaterialIds)
|
|
|
|
|
+ .list()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .collect(Collectors.toMap(GoodsMaterialStorage::getGoodsMaterialId, GoodsMaterialStorage::getStockQty));
|
|
|
|
|
+
|
|
|
|
|
+ //是否有收藏
|
|
|
|
|
+ Integer goodsFavoritesCount = goodsFavoriteService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsFavorite::getGoodsId, goodsId)
|
|
|
|
|
+ .eq(GoodsFavorite::getUserId, user.getUserId())
|
|
|
|
|
+ .count();
|
|
|
|
|
|
|
|
- //内部人员、秒杀活动、让利分享 等对价格分佣金额产生的影响处理
|
|
|
|
|
for (GoodsSpecSecBean goodsSpec : goodsSpecs) {
|
|
for (GoodsSpecSecBean goodsSpec : goodsSpecs) {
|
|
|
|
|
+ final Integer stockQty = goodsMaterialStorageMap.get(goodsSpec.getGoodsCode());
|
|
|
|
|
+ goodsSpec.setStockNum(Objects.isNull(stockQty) ? 0 : stockQty);
|
|
|
if (goodsSpec.getOrgPrice().doubleValue() == 0) {
|
|
if (goodsSpec.getOrgPrice().doubleValue() == 0) {
|
|
|
goodsSpec.setOrgPrice(goodsSpec.getOrgGoodsPrice());
|
|
goodsSpec.setOrgPrice(goodsSpec.getOrgGoodsPrice());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(adminCompanyWechat != null) {
|
|
|
|
|
- goodsBean.setIsMaster(StringUtils.equals(adminCompanyWechat.getLinkPhone(), user.getMobile()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 总商品库存
|
|
|
|
|
+ Integer goodsStock = goodsSpecs.stream().mapToInt(GoodsSpec::getStockNum).sum();
|
|
|
|
|
+ GoodsBean goodsBean = new GoodsBean();
|
|
|
|
|
+ BeanUtils.copyProperties(goods, goodsBean);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
goodsBean.setGoodsSpecs(goodsSpecs);
|
|
goodsBean.setGoodsSpecs(goodsSpecs);
|
|
|
goodsBean.setImages(commonLogic.queryFileByObjId(goods.getGoodsId(), Constant.Img.GOODS_IMG));
|
|
goodsBean.setImages(commonLogic.queryFileByObjId(goods.getGoodsId(), Constant.Img.GOODS_IMG));
|
|
|
goodsBean.setFavorite(goodsFavoritesCount > 0);
|
|
goodsBean.setFavorite(goodsFavoritesCount > 0);
|