Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop

This commit is contained in:
Chopper 2021-05-21 17:06:04 +08:00
commit 2c58b91c45
3 changed files with 38 additions and 7 deletions

View File

@ -122,4 +122,11 @@ public interface GoodsService extends IService<Goods> {
* @param quantity 库存数量 * @param quantity 库存数量
*/ */
void updateStock(String goodsId, Integer quantity); void updateStock(String goodsId, Integer quantity);
/**
* 更新SKU评价数量
*
* @param goodsId 商品ID
*/
void updateGoodsCommentNum(String goodsId);
} }

View File

@ -2,6 +2,7 @@ package cn.lili.modules.goods.serviceimpl;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException; import cn.lili.common.exception.ServiceException;
@ -23,6 +24,9 @@ import cn.lili.modules.goods.entity.vos.GoodsSkuVO;
import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.mapper.GoodsMapper; import cn.lili.modules.goods.mapper.GoodsMapper;
import cn.lili.modules.goods.service.*; import cn.lili.modules.goods.service.*;
import cn.lili.modules.member.entity.dos.MemberEvaluation;
import cn.lili.modules.member.entity.enums.EvaluationGradeEnum;
import cn.lili.modules.member.service.MemberEvaluationService;
import cn.lili.modules.store.entity.vos.StoreVO; import cn.lili.modules.store.entity.vos.StoreVO;
import cn.lili.modules.store.service.StoreService; import cn.lili.modules.store.service.StoreService;
import cn.lili.modules.system.entity.dos.Setting; import cn.lili.modules.system.entity.dos.Setting;
@ -73,6 +77,8 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
//店铺详情 //店铺详情
@Autowired @Autowired
private StoreService storeService; private StoreService storeService;
@Autowired
private MemberEvaluationService memberEvaluationService;
//rocketMq //rocketMq
@Autowired @Autowired
private RocketMQTemplate rocketMQTemplate; private RocketMQTemplate rocketMQTemplate;
@ -80,6 +86,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
@Autowired @Autowired
private RocketmqCustomProperties rocketmqCustomProperties; private RocketmqCustomProperties rocketmqCustomProperties;
@Override @Override
public void underStoreGoods(String storeId) { public void underStoreGoods(String storeId) {
this.baseMapper.underStoreGoods(storeId); this.baseMapper.underStoreGoods(storeId);
@ -313,6 +320,26 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
this.update(lambdaUpdateWrapper); this.update(lambdaUpdateWrapper);
} }
@Override
public void updateGoodsCommentNum(String goodsId) {
//获取商品信息
Goods goods = this.getById(goodsId);
//修改商品评价数量
goods.setCommentNum(goods.getCommentNum() + 1);
//修改商品好评率
LambdaQueryWrapper<MemberEvaluation> goodEvaluationQueryWrapper = new LambdaQueryWrapper<>();
goodEvaluationQueryWrapper.eq(MemberEvaluation::getId, goodsId);
goodEvaluationQueryWrapper.eq(MemberEvaluation::getGrade, EvaluationGradeEnum.GOOD.name());
// 好评数量
int highPraiseNum = memberEvaluationService.count(goodEvaluationQueryWrapper);
// 好评率
double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goods.getCommentNum().doubleValue(), 2), 100);
goods.setGrade(grade);
this.updateById(goods);
}
/** /**
* 添加商品默认图片 * 添加商品默认图片
* *

View File

@ -413,18 +413,15 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
goodsSku.setCommentNum(goodsSku.getCommentNum() != null ? goodsSku.getCommentNum() + 1 : 1); goodsSku.setCommentNum(goodsSku.getCommentNum() != null ? goodsSku.getCommentNum() + 1 : 1);
// 好评率 // 好评率
double grade = NumberUtil.div(highPraiseNum, goodsSku.getCommentNum().doubleValue(), 2) * 100; double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goodsSku.getCommentNum().doubleValue(), 2), 100);
goodsSku.setGrade(grade); goodsSku.setGrade(grade);
//修改规格 //修改规格
this.update(goodsSku); this.update(goodsSku);
//修改规格索引 //修改规格索引
goodsIndexService.updateIndexCommentNum(goodsSku.getId(), goodsSku.getCommentNum(), (int) highPraiseNum, grade); goodsIndexService.updateIndexCommentNum(goodsSku.getId(), goodsSku.getCommentNum(), (int) highPraiseNum, grade);
//修改商品评价数量 //修改商品的评价数量
Goods goods = goodsService.getById(goodsSku.getGoodsId()); goodsService.updateGoodsCommentNum(goodsSku.getGoodsId());
goods.setCommentNum(goods.getCommentNum() + 1);
goodsService.updateById(goods);
} }
/** /**