fixed 数量限制

This commit is contained in:
LittleBoy 2022-11-28 12:13:03 +08:00
parent 6a2a8372ed
commit dc5119b234
2 changed files with 3 additions and 2 deletions

View File

@ -59,6 +59,7 @@ public class ShopOrderInfoController {
if (data.getGoodsId() <= 0 || data.getBuyCount() <= 0) { if (data.getGoodsId() <= 0 || data.getBuyCount() <= 0) {
throw BizException.create("订单参数不正确"); throw BizException.create("订单参数不正确");
} }
int uid = StpUtil.getLoginIdAsInt();
// 如果限制用户只能购买的数量可以添加一个map记录用户的请求数 // 如果限制用户只能购买的数量可以添加一个map记录用户的请求数
//1.内存判断 //1.内存判断
if (stockOutMap.size() > 0 && stockOutMap.get(data.getGoodsId())) { if (stockOutMap.size() > 0 && stockOutMap.get(data.getGoodsId())) {
@ -78,7 +79,7 @@ public class ShopOrderInfoController {
} }
//3.数据库 //3.数据库
try{ try{
return orderInfoService.create(StpUtil.getLoginIdAsInt(), data); return orderInfoService.create(uid, data);
}catch (BizException e){ }catch (BizException e){
//下单失败 对缓存进行库存 还原 //下单失败 对缓存进行库存 还原
stringRedisTemplate.opsForValue().increment(cacheKey(data.getGoodsId()),data.getBuyCount()); // stringRedisTemplate.opsForValue().increment(cacheKey(data.getGoodsId()),data.getBuyCount()); //

View File

@ -76,7 +76,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
public long buyHistoryCount(int uid, int gid) { public long buyHistoryCount(int uid, int gid) {
QueryWrapper q = new QueryWrapper(); QueryWrapper q = new QueryWrapper();
q.eq("uid", gid); q.eq("uid", uid);
q.eq("gid", gid); q.eq("gid", gid);
q.ge("status", OrderStatus.CONFIRM); // 状态为2(待确认)和3(已完成) q.ge("status", OrderStatus.CONFIRM); // 状态为2(待确认)和3(已完成)
return count(q); return count(q);