记得上下班打卡 | git大法好,push需谨慎

Commit 5e30ec20 authored by jiangxiulong's avatar jiangxiulong

下单 用户购买数量问题;回滚库存问题;

parent 78b7d9c8
......@@ -91,6 +91,16 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
} else if (null != saleStopTime && nowTime.isAfter(saleStopTime)) {
return ResponseDto.failure("该商品已停售~");
}
// 判断数量限购 盲盒暂时没限购但是要记录购买数量 所以也放在这里 这样既能都记录限购数量又不至于判断处理麻烦
int limitCount = skuVo.getBuyLimit();
// 是否限购都记录一个购买数量 防止中间增加限购 开始没加后面判断库存减了也是有问题的 或者放在最后也行 因为对单用户限流了
int buyCount = goblinRedisUtils.incrSkuCountByUid(uid, skuId, number);
if (!Objects.equals(0, limitCount)) {
if (buyCount > limitCount) {
goblinRedisUtils.decrSkuCountByUid(uid, skuId, number);
return ResponseDto.failure("您已超出限购数量~");
}
}
// 权限限购
/*String mobile = StringUtils.defaultString(((String) CurrentUtil.getTokenClaims().get(CurrentUtil.TOKEN_MOBILE)), "");
boolean isVip = nftOrderUtils.isVipMember(uid);
......@@ -105,6 +115,8 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
return ResponseDto.failure("平台券与店铺券不可一起使用哦~");
}*/
String boxSkuId = "";
// 盲盒回滚抽到的库存 购买回滚购买的库存
String backSkuId = skuId;
if (skuVo.getUnbox().equals("1")) {// 盲盒逻辑
GoblinGoodsInfoVo spuInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
List<String> skuIdList = spuInfoVo.getSkuIdList();
......@@ -116,21 +128,13 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
return ResponseDto.failure("盲盒库存不足啦~");
}
boxSkuId = skuInfoVo.getSkuId();
backSkuId = boxSkuId;
}
} else {// 普通藏品逻辑
// 判断数量限购
int limitCount = skuVo.getBuyLimit();
if (!Objects.equals(0, limitCount)) {
String isOutLimit = goblinOrderUtils.judgeOrderLimit(uid, skuId, number, limitCount);
if (!StringUtils.isEmpty(isOutLimit)) {
goblinRedisUtils.decrSkuCountByUid(uid, skuId, number);
return ResponseDto.failure("您已超出限购数量~");
}
}
// 判断库存
int surplusGeneral = nftOrderUtils.decrSkuStock(skuId, number);
if (surplusGeneral < 0) {
nftOrderUtils.backSkuCountAndStock(uid, skuId, number);
nftOrderUtils.backSkuCountAndStock(uid, backSkuId, number);
return ResponseDto.failure("库存不足啦~");
}
}
......@@ -170,14 +174,14 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
// 下单数据
GoblinNftOrder nftOrder = order(payParam, skuVo.getStoreId(), uid, spuId, number, orderId, orderCode, totalPrice, voucherPrice, storeVoucherPrice, boxSkuId);
if (null == nftOrder) {
nftOrderUtils.backSkuCountAndStock(uid, skuId, number);
nftOrderUtils.backSkuCountAndStock(uid, backSkuId, number);
return ResponseDto.failure("下单失败~");
}
// 下单唤起支付
GoblinNftPayResultVo nftPayResultVo = payOrder(nftOrder, uid, payParam);
if (null == nftPayResultVo) {
nftOrderUtils.backSkuCountAndStock(uid, skuId, number);
nftOrderUtils.backSkuCountAndStock(uid, backSkuId, number);
return ResponseDto.failure("下单失败啦~");
}
return ResponseDto.success(nftPayResultVo);
......
......@@ -61,10 +61,10 @@ public class GoblinNftOrderUtils {
// 回滚用户sku购买个数和库存
public void backSkuCountAndStock(String uid, String skuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BUY_COUNT.concat(uid + ":skuId:" + skuId);
long decr = redisUtil.decr(redisKey, number);
String redisKey2 = GoblinRedisConst.REAL_STOCK_SKU.concat(skuId);
long incr = redisUtil.incr(redisKey2, number);
// 减少用户购买个数
goblinRedisUtils.decrSkuCountByUid(uid, skuId, number);
// 增加库存
incrSkuStock(skuId, number);
}
// 订单详情vo
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment