修复订单支付时由于商品库存不足引起订单创建失败问题,库存不足提示 xxx库存不足
This commit is contained in:
@ -54,11 +54,7 @@ import co.yixiang.modules.shop.entity.YxStoreCart;
|
|||||||
import co.yixiang.modules.shop.entity.YxStoreCouponUser;
|
import co.yixiang.modules.shop.entity.YxStoreCouponUser;
|
||||||
import co.yixiang.modules.shop.mapper.YxStoreCartMapper;
|
import co.yixiang.modules.shop.mapper.YxStoreCartMapper;
|
||||||
import co.yixiang.modules.shop.mapper.YxStoreCouponUserMapper;
|
import co.yixiang.modules.shop.mapper.YxStoreCouponUserMapper;
|
||||||
import co.yixiang.modules.shop.service.YxStoreCouponUserService;
|
import co.yixiang.modules.shop.service.*;
|
||||||
import co.yixiang.modules.shop.service.YxStoreProductReplyService;
|
|
||||||
import co.yixiang.modules.shop.service.YxStoreProductService;
|
|
||||||
import co.yixiang.modules.shop.service.YxSystemConfigService;
|
|
||||||
import co.yixiang.modules.shop.service.YxSystemStoreService;
|
|
||||||
import co.yixiang.modules.shop.web.vo.YxStoreCartQueryVo;
|
import co.yixiang.modules.shop.web.vo.YxStoreCartQueryVo;
|
||||||
import co.yixiang.modules.shop.web.vo.YxSystemStoreQueryVo;
|
import co.yixiang.modules.shop.web.vo.YxSystemStoreQueryVo;
|
||||||
import co.yixiang.modules.user.entity.YxUser;
|
import co.yixiang.modules.user.entity.YxUser;
|
||||||
@ -172,7 +168,8 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OrderMap orderMap;
|
private OrderMap orderMap;
|
||||||
|
@Autowired
|
||||||
|
private YxStoreCartService yxStoreCartService;
|
||||||
//@Autowired
|
//@Autowired
|
||||||
//private MqProducer mqProducer;
|
//private MqProducer mqProducer;
|
||||||
|
|
||||||
@ -1255,6 +1252,10 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
|||||||
int bargainId = 0;
|
int bargainId = 0;
|
||||||
|
|
||||||
for (YxStoreCartQueryVo cart : cartInfo) {
|
for (YxStoreCartQueryVo cart : cartInfo) {
|
||||||
|
yxStoreCartService.checkProductStock(uid,cart.getProductId(),cart.getCartNum(),
|
||||||
|
cart.getProductAttrUnique(), cart.getCombinationId(),cart.getSeckillId(),cart.getBargainId());
|
||||||
|
|
||||||
|
|
||||||
combinationId = cart.getCombinationId();
|
combinationId = cart.getCombinationId();
|
||||||
seckillId = cart.getSeckillId();
|
seckillId = cart.getSeckillId();
|
||||||
bargainId = cart.getBargainId();
|
bargainId = cart.getBargainId();
|
||||||
|
@ -44,5 +44,16 @@ public interface YxStoreCartService extends BaseService<YxStoreCart> {
|
|||||||
*/
|
*/
|
||||||
YxStoreCartQueryVo getYxStoreCartById(Serializable id);
|
YxStoreCartQueryVo getYxStoreCartById(Serializable id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证产品库存是否足够
|
||||||
|
* @param uid 用户ID
|
||||||
|
* @param productId 产品ID
|
||||||
|
* @param cartNum 购买数量
|
||||||
|
* @param productAttrUnique 商品属性Unique
|
||||||
|
* @param combinationId 拼团产品ID
|
||||||
|
* @param seckillId 秒杀产品ID
|
||||||
|
* @param bargainId 砍价产品ID
|
||||||
|
*/
|
||||||
|
void checkProductStock(int uid, int productId, int cartNum, String productAttrUnique,
|
||||||
|
int combinationId, int seckillId, int bargainId);
|
||||||
}
|
}
|
||||||
|
@ -268,51 +268,8 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<YxStoreCartMapper, Y
|
|||||||
@Override
|
@Override
|
||||||
public int addCart(int uid, int productId, int cartNum, String productAttrUnique,
|
public int addCart(int uid, int productId, int cartNum, String productAttrUnique,
|
||||||
String type, int isNew, int combinationId, int seckillId, int bargainId) {
|
String type, int isNew, int combinationId, int seckillId, int bargainId) {
|
||||||
//todo 拼团
|
|
||||||
if(combinationId > 0){
|
|
||||||
boolean isStock = storeCombinationService.judgeCombinationStock(combinationId
|
|
||||||
,cartNum);
|
|
||||||
if(!isStock) throw new ErrorRequestException("该产品库存不足");
|
|
||||||
|
|
||||||
YxStoreCombination storeCombination = storeCombinationService.getCombination(combinationId);
|
|
||||||
if(ObjectUtil.isNull(storeCombination)) throw new ErrorRequestException("该产品已下架或删除");
|
|
||||||
}else if(seckillId > 0){//秒杀
|
|
||||||
YxStoreSeckill yxStoreSeckill = storeSeckillService.getSeckill(seckillId);
|
|
||||||
if(ObjectUtil.isNull(yxStoreSeckill)){
|
|
||||||
throw new ErrorRequestException("该产品已下架或删除");
|
|
||||||
}
|
|
||||||
if(yxStoreSeckill.getStock() < cartNum){
|
|
||||||
throw new ErrorRequestException("该产品库存不足");
|
|
||||||
}
|
|
||||||
int seckillOrderCount = storeOrderService.count(new QueryWrapper<YxStoreOrder>()
|
|
||||||
.eq("uid", uid).eq("paid",1).eq("seckill_id",seckillId));
|
|
||||||
if(yxStoreSeckill.getNum() <= seckillOrderCount || yxStoreSeckill.getNum() < cartNum){
|
|
||||||
throw new ErrorRequestException("每人限购:"+yxStoreSeckill.getNum()+"件");
|
|
||||||
}
|
|
||||||
|
|
||||||
}else if(bargainId > 0){//砍价
|
|
||||||
YxStoreBargain yxStoreBargain = storeBargainService.getBargain(bargainId);
|
|
||||||
if(ObjectUtil.isNull(yxStoreBargain)){
|
|
||||||
throw new ErrorRequestException("该产品已下架或删除");
|
|
||||||
}
|
|
||||||
if(yxStoreBargain.getStock() < cartNum){
|
|
||||||
throw new ErrorRequestException("该产品库存不足");
|
|
||||||
}
|
|
||||||
|
|
||||||
}else{
|
|
||||||
YxStoreProductQueryVo productQueryVo = productService
|
|
||||||
.getYxStoreProductById(productId);
|
|
||||||
if(ObjectUtil.isNull(productQueryVo)){
|
|
||||||
throw new ErrorRequestException("该产品已下架或删除");
|
|
||||||
}
|
|
||||||
|
|
||||||
int stock = productService.getProductStock(productId,productAttrUnique);
|
|
||||||
if(stock < cartNum){
|
|
||||||
throw new ErrorRequestException("该产品库存不足"+cartNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
checkProductStock(uid,productId,cartNum,productAttrUnique,combinationId,seckillId,bargainId);
|
||||||
QueryWrapper<YxStoreCart> wrapper = new QueryWrapper<>();
|
QueryWrapper<YxStoreCart> wrapper = new QueryWrapper<>();
|
||||||
wrapper.eq("uid",uid).eq("type",type).eq("is_pay",0).eq("is_del",0)
|
wrapper.eq("uid",uid).eq("type",type).eq("is_pay",0).eq("is_del",0)
|
||||||
.eq("product_id",productId)
|
.eq("product_id",productId)
|
||||||
@ -365,6 +322,53 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<YxStoreCartMapper, Y
|
|||||||
return yxStoreCartMapper.getYxStoreCartById(id);
|
return yxStoreCartMapper.getYxStoreCartById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkProductStock(int uid, int productId, int cartNum, String productAttrUnique, int combinationId, int seckillId, int bargainId) {
|
||||||
|
//todo 拼团
|
||||||
|
if(combinationId > 0){
|
||||||
|
boolean isStock = storeCombinationService.judgeCombinationStock(combinationId
|
||||||
|
,cartNum);
|
||||||
|
if(!isStock) throw new ErrorRequestException("该产品库存不足");
|
||||||
|
|
||||||
|
YxStoreCombination storeCombination = storeCombinationService.getCombination(combinationId);
|
||||||
|
if(ObjectUtil.isNull(storeCombination)) throw new ErrorRequestException("该产品已下架或删除");
|
||||||
|
}else if(seckillId > 0){//秒杀
|
||||||
|
YxStoreSeckill yxStoreSeckill = storeSeckillService.getSeckill(seckillId);
|
||||||
|
if(ObjectUtil.isNull(yxStoreSeckill)){
|
||||||
|
throw new ErrorRequestException("该产品已下架或删除");
|
||||||
|
}
|
||||||
|
if(yxStoreSeckill.getStock() < cartNum){
|
||||||
|
throw new ErrorRequestException("该产品库存不足");
|
||||||
|
}
|
||||||
|
int seckillOrderCount = storeOrderService.count(new QueryWrapper<YxStoreOrder>()
|
||||||
|
.eq("uid", uid).eq("paid",1).eq("seckill_id",seckillId));
|
||||||
|
if(yxStoreSeckill.getNum() <= seckillOrderCount || yxStoreSeckill.getNum() < cartNum){
|
||||||
|
throw new ErrorRequestException("每人限购:"+yxStoreSeckill.getNum()+"件");
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(bargainId > 0){//砍价
|
||||||
|
YxStoreBargain yxStoreBargain = storeBargainService.getBargain(bargainId);
|
||||||
|
if(ObjectUtil.isNull(yxStoreBargain)){
|
||||||
|
throw new ErrorRequestException("该产品已下架或删除");
|
||||||
|
}
|
||||||
|
if(yxStoreBargain.getStock() < cartNum){
|
||||||
|
throw new ErrorRequestException("该产品库存不足");
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
YxStoreProductQueryVo productQueryVo = productService
|
||||||
|
.getYxStoreProductById(productId);
|
||||||
|
if(ObjectUtil.isNull(productQueryVo)){
|
||||||
|
throw new ErrorRequestException("该产品已下架或删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
int stock = productService.getProductStock(productId,productAttrUnique);
|
||||||
|
if(stock < cartNum){
|
||||||
|
throw new ErrorRequestException(productQueryVo.getStoreName()+"库存不足"+cartNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user