|
|
@@ -28,8 +28,10 @@ import com.zhongzheng.modules.goods.service.IGoodsCourseService;
|
|
|
import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
import com.zhongzheng.modules.goods.vo.*;
|
|
|
import com.zhongzheng.modules.grade.vo.ClassGradeVo;
|
|
|
+import com.zhongzheng.modules.order.bo.OrderGoodsQueryBo;
|
|
|
import com.zhongzheng.modules.order.domain.OrderGoods;
|
|
|
import com.zhongzheng.modules.order.service.IOrderGoodsService;
|
|
|
+import com.zhongzheng.modules.order.vo.OrderGoodsVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -68,6 +70,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
@Autowired
|
|
|
private IOrderGoodsService iOrderGoodsService;
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public GoodsVo queryById(Long goodsId){
|
|
|
Goods db = this.baseMapper.selectById(goodsId);
|
|
|
@@ -320,7 +323,30 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
throw new CustomException("该商品已被购买过,无法改变状态");
|
|
|
}
|
|
|
}
|
|
|
- if(entity.getGoodsType().longValue()==1&&entity.getGoodsId().longValue()>0){
|
|
|
+ if(entity.getGoodsType().longValue()==1&&Validator.isNotEmpty(entity.getStudyCount())&&entity.getGoodsId().longValue()>0){
|
|
|
+ //判断学习次数有没有变化
|
|
|
+ GoodsVo old = this.queryById(entity.getGoodsId());
|
|
|
+ if(Validator.isEmpty(old.getStudyCount())){
|
|
|
+ old.setStudyCount(0L);
|
|
|
+ }
|
|
|
+ if(entity.getStudyCount().longValue()>old.getStudyCount().longValue()){
|
|
|
+ Long addNum = entity.getStudyCount() - old.getStudyCount();
|
|
|
+ //增加购买用户的学习次数
|
|
|
+ OrderGoodsQueryBo bo = new OrderGoodsQueryBo();
|
|
|
+ bo.setGoodsId(entity.getGoodsId());
|
|
|
+ List<OrderGoodsVo> goodsList = iOrderGoodsService.queryList(bo);
|
|
|
+ for(OrderGoodsVo vo : goodsList){
|
|
|
+ //增加学习次数
|
|
|
+ OrderGoods orderGoods = new OrderGoods();
|
|
|
+ orderGoods.setOrderGoodsId(vo.getOrderGoodsId());
|
|
|
+ orderGoods.setStudyCount(vo.getStudyCount()+addNum);
|
|
|
+ orderGoods.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iOrderGoodsService.updateById(orderGoods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(entity.getStudyCount().longValue()<old.getStudyCount().longValue()){
|
|
|
+ throw new CustomException("学习次数不允许变小");
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|