feat 新增积分判断

This commit is contained in:
LittleBoy 2022-12-01 08:21:31 +08:00
parent 56c69c3ff8
commit 2e2b5d4cdc

View File

@ -9,11 +9,8 @@ import me.xiaoyan.point.api.pojo.OrderInfo;
import me.xiaoyan.point.api.pojo.UserInfo;
import me.xiaoyan.point.api.pojo.dto.OrderStatus;
import me.xiaoyan.point.api.pojo.vo.CreateOrderData;
import me.xiaoyan.point.api.service.GoodsService;
import me.xiaoyan.point.api.service.OrderInfoService;
import me.xiaoyan.point.api.service.UserInfoService;
import me.xiaoyan.point.api.service.*;
import me.xiaoyan.point.api.util.OrderIdGenerator;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -33,6 +30,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
private UserInfoService userInfoService;
@Resource
private GoodsService goodsService;
@Resource
private PointRecordService pointRecordService;
@Transactional
@Override
@ -49,12 +48,17 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (goods.getOnlineTime().getTime() > now || goods.getOfflineTime().getTime() < now) {
throw BizException.create("商品未上架或已下架");
}
// TODO 需要判断积分
if (goods.getStock() < data.getBuyCount()) throw BizException.create("商品存库不足");
// 判断购买数量的限制
if(goods.getLimitCount() > 0 && buyHistoryCount(uid,data.getGoodsId()) + data.getBuyCount() > goods.getLimitCount()){
throw BizException.create("最多兑换" + goods.getLimitCount() + "");
// 需要判断积分
if (goods.getPrice() > 0 && user.getPointInfo().getTotalPoint() < goods.getPrice()) {
throw BizException.create("积分不足,兑换失败");
}
// 判断购买数量的限制
if (goods.getLimitCount() > 0 && buyHistoryCount(uid, data.getGoodsId()) + data.getBuyCount() > goods.getLimitCount()) {
throw BizException.create("最多兑换" + goods.getLimitCount() + "");
}
// 扣减积分
pointRecordService.record(uid, 0 - goods.getPrice(), "兑换商品 " + goods.getTitle());
// 3.减库存
if (!goodsService.deductStock(data.getGoodsId(), data.getBuyCount())) {
throw BizException.create("商品库存不足");