|
|
@@ -73,6 +73,10 @@ public class GoodsLogic {
|
|
|
GoodsDocumentsRelaService goodsDocumentsRelaService;
|
|
|
@Resource
|
|
|
AppMapper appMapper;
|
|
|
+ @Resource
|
|
|
+ UserLevelRelaService userLevelRelaService;
|
|
|
+ @Resource
|
|
|
+ UserLevelGoodsService userLevelGoodsService;
|
|
|
|
|
|
/**
|
|
|
* 商品列表
|
|
|
@@ -101,7 +105,10 @@ public class GoodsLogic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //补充标签
|
|
|
+ // 获取会员等级商品规格
|
|
|
+ Map<String, UserLevelGoods> userLevelGoodsMap = this.queryUserLevelGoodsMap(currentCompanyWechat);
|
|
|
+
|
|
|
+ //补充标签和会员等级商品规格价格
|
|
|
for (GoodsNewBean goodsNewBean : page.getRecords()) {
|
|
|
//查询上标签
|
|
|
List<GoodsTagRela> list1 = goodsTagRelaService.lambdaQuery().eq(GoodsTagRela::getGoodsId, goodsNewBean.getGoodsId())
|
|
|
@@ -119,6 +126,20 @@ public class GoodsLogic {
|
|
|
List<String> collect1 = list.stream().map(GoodsTagRela::getGoodsTagName).collect(Collectors.toList());
|
|
|
goodsNewBean.setTags2(collect1);
|
|
|
}
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(userLevelGoodsMap)) {
|
|
|
+ final GoodsSpec goodsSpec = goodsSpecService.lambdaQuery()
|
|
|
+ .select(GoodsSpec::getGoodsSpecId, GoodsSpec::getGoodsCode)
|
|
|
+ .eq(GoodsSpec::getGoodsId, goodsNewBean.getGoodsId())
|
|
|
+ .orderByAsc(GoodsSpec::getPrice)
|
|
|
+ .last("limit 1")
|
|
|
+ .one();
|
|
|
+
|
|
|
+ if (Objects.nonNull(goodsSpec) && userLevelGoodsMap.containsKey(goodsNewBean.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode())) {
|
|
|
+ final UserLevelGoods userLevelGoods = userLevelGoodsMap.get(goodsNewBean.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode());
|
|
|
+ goodsNewBean.setGoodsSpecNewPrice(userLevelGoods.getGoodsSpecNewPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -130,7 +151,7 @@ public class GoodsLogic {
|
|
|
|
|
|
User user = userService.getById(userId);
|
|
|
|
|
|
- GoodsBean goodsBean = this.commonDetail(goodsId, user, storageId);
|
|
|
+ GoodsBean goodsBean = this.commonDetail(goodsId, user, storageId, currentCompanyWechat);
|
|
|
|
|
|
//补充标签
|
|
|
//查询上标签
|
|
|
@@ -177,7 +198,7 @@ public class GoodsLogic {
|
|
|
* @param goodsId
|
|
|
* @return
|
|
|
*/
|
|
|
- public GoodsBean commonDetail(String goodsId, User user, String storageId) throws RemoteServiceException {
|
|
|
+ public GoodsBean commonDetail(String goodsId, User user, String storageId, CurrentCompanyWechat currentCompanyWechat) throws RemoteServiceException {
|
|
|
Goods goods = goodsService.lambdaQuery()
|
|
|
.eq(Goods::getGoodsId, goodsId)
|
|
|
.eq(Goods::getDel, false)
|
|
|
@@ -190,6 +211,9 @@ public class GoodsLogic {
|
|
|
|
|
|
//商品规格
|
|
|
List<GoodsSpecSecBean> goodsSpecs = goodsSpecDetailMapper.querySpecSec(goodsId);
|
|
|
+ // 商品规格按价格排升序
|
|
|
+ goodsSpecs = goodsSpecs.stream().sorted(Comparator.comparing(GoodsSpecSecBean::getPrice)).collect(Collectors.toList());
|
|
|
+
|
|
|
final List<String> goodsMaterialIds = goodsSpecs.stream().map(GoodsSpecSecBean::getGoodsCode).collect(Collectors.toList());
|
|
|
|
|
|
// 获取规格库存
|
|
|
@@ -206,6 +230,9 @@ public class GoodsLogic {
|
|
|
.eq(GoodsFavorite::getUserId, user.getUserId())
|
|
|
.count();
|
|
|
|
|
|
+ // 获取会员等级商品规格
|
|
|
+ Map<String, UserLevelGoods> userLevelGoodsMap = this.queryUserLevelGoodsMap(currentCompanyWechat);
|
|
|
+ BigDecimal goodsSpecNewPrice = null;
|
|
|
for (GoodsSpecSecBean goodsSpec : goodsSpecs) {
|
|
|
final Integer stockQty = goodsMaterialStorageMap.get(goodsSpec.getGoodsCode());
|
|
|
goodsSpec.setStockNum(Objects.isNull(stockQty) ? 0 : stockQty);
|
|
|
@@ -234,6 +261,14 @@ public class GoodsLogic {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(userLevelGoodsMap) && userLevelGoodsMap.containsKey(goodsId + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode())) {
|
|
|
+ final UserLevelGoods userLevelGoods = userLevelGoodsMap.get(goodsId + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode());
|
|
|
+ goodsSpec.setGoodsSpecNewPrice(userLevelGoods.getGoodsSpecNewPrice());
|
|
|
+ if (Objects.isNull(goodsSpecNewPrice)) {
|
|
|
+ goodsSpecNewPrice = userLevelGoods.getGoodsSpecNewPrice();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 总商品库存
|
|
|
@@ -252,10 +287,30 @@ public class GoodsLogic {
|
|
|
goodsBean.setStock(goodsStock);
|
|
|
goodsBean.setCommonTemplate(goodsSpecDetailMapper.queryCommonTemplate(goodsId));
|
|
|
goodsBean.setPubCommonTemplate(pubTemplateService.getById(goods.getCompanyWechatId()));
|
|
|
+ goodsBean.setGoodsSpecNewPrice(goodsSpecNewPrice);
|
|
|
|
|
|
return goodsBean;
|
|
|
}
|
|
|
|
|
|
+ private Map<String, UserLevelGoods> queryUserLevelGoodsMap(CurrentCompanyWechat currentCompanyWechat) {
|
|
|
+ if (Objects.nonNull(currentCompanyWechat.getUser())) {
|
|
|
+ // 检查是否有会员等级
|
|
|
+ UserLevelRela userLevelRela = userLevelRelaService.lambdaQuery()
|
|
|
+ .eq(UserLevelRela::getCompanyWechatId, currentCompanyWechat.getCurrentCompanyWechatId())
|
|
|
+ .eq(UserLevelRela::getUserId, currentCompanyWechat.getUserId())
|
|
|
+ .one();
|
|
|
+
|
|
|
+ List<UserLevelGoods> userLevelGoodsList = userLevelGoodsService.lambdaQuery()
|
|
|
+ .eq(UserLevelGoods::getUserLevelId, userLevelRela.getUserLevelId())
|
|
|
+ .list();
|
|
|
+ if (CollectionUtil.isNotEmpty(userLevelGoodsList)) {
|
|
|
+ return userLevelGoodsList.stream()
|
|
|
+ .collect(Collectors.toMap(v -> v.getGoodsId() + v.getGoodsSpecId() + v.getGoodsSpecCode(), Function.identity()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取商品
|
|
|
*
|