|
|
@@ -711,7 +711,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
} else {
|
|
|
lockKey = "livePayConfirm:lock:" + System.currentTimeMillis();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
boolean lockAcquired = false;
|
|
|
Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
|
|
|
try {
|
|
|
@@ -1654,6 +1654,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
userService.subLiveTuiMoney(liveOrder);
|
|
|
}
|
|
|
}
|
|
|
+ // 删除限购记录
|
|
|
+ deletePurchaseLimitRecordsForLiveOrder(order);
|
|
|
|
|
|
return R.ok();
|
|
|
}
|
|
|
@@ -3661,6 +3663,12 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
this.payConfirm(1, null, payment.getPayCode(), payment.getTradeNo(), payment.getBankSerialNo(), payment.getBankSerialNo());
|
|
|
}
|
|
|
|
|
|
+ public void deStockIncSale(List<FsStoreCartQueryVO> cartInfo) {
|
|
|
+ for (FsStoreCartQueryVO storeCartVO : cartInfo) {
|
|
|
+ fsStoreProductService.decProductStock(storeCartVO.getProductId(),
|
|
|
+ storeCartVO.getProductAttrValueId(), storeCartVO.getCartNum());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
@@ -3690,27 +3698,19 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if(!"1".equals(fsStoreProduct.getIsAudit()) ) return R.error("商品已下架,购买失败");
|
|
|
if(liveOrder.getTotalNum() == null || StringUtils.isEmpty(liveOrder.getTotalNum())) liveOrder.setTotalNum("1");
|
|
|
if(goods.getStock() == null) return R.error("直播间商品库存不足");
|
|
|
- if(fsStoreProduct.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || goods.getStock() < Integer.parseInt(liveOrder.getTotalNum())) return R.error("抱歉,这款商品已被抢光,暂时无库存~");
|
|
|
+ FsStoreProductAttrValueScrm attrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueById(liveOrder.getAttrValueId());
|
|
|
+ if(fsStoreProduct.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || goods.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || attrValue.getStock() < Integer.parseInt(liveOrder.getTotalNum())){
|
|
|
+ return R.error("抱歉,这款商品已被抢光,暂时无库存~");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// 检查限购
|
|
|
Long userId = Long.parseLong(liveOrder.getUserId());
|
|
|
Integer purchaseNum = Integer.parseInt(liveOrder.getTotalNum());
|
|
|
checkPurchaseLimitForLiveOrder(userId, liveOrder.getProductId(), purchaseNum);
|
|
|
|
|
|
- FsStoreProductAttrValueScrm attrValue = null;
|
|
|
- if (!Objects.isNull(liveOrder.getAttrValueId())) {
|
|
|
- attrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueById(liveOrder.getAttrValueId());
|
|
|
- }
|
|
|
- if (attrValue != null) {
|
|
|
- attrValue.setStock(attrValue.getStock() - Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
- attrValue.setSales(attrValue.getSales() + Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
- fsStoreProductAttrValueMapper.updateFsStoreProductAttrValue(attrValue);
|
|
|
- }
|
|
|
- // 更改店铺库存
|
|
|
- fsStoreProduct.setStock(fsStoreProduct.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
- fsStoreProduct.setSales(fsStoreProduct.getSales()+Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
- fsStoreProductScrmMapper.incStockDecSales(Long.valueOf("-" + liveOrder.getTotalNum()),fsStoreProduct.getProductId());
|
|
|
-
|
|
|
+ // 使用 deStockIncSale 方法处理库存和销量
|
|
|
+ deStockIncSale(liveOrder.getProductId(), liveOrder.getAttrValueId(), purchaseNum);
|
|
|
// 更新直播间库存
|
|
|
goods.setStock(goods.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
goods.setSales(goods.getSales()+Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
@@ -3738,6 +3738,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
BigDecimal payPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
|
|
|
if (attrValue != null) {
|
|
|
payPrice = attrValue.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
|
|
|
+ fsStoreProduct.setPrice(payPrice);
|
|
|
}
|
|
|
// 直播不需要服务费 0915 1735 左
|
|
|
// String config=configService.selectConfigByKey("store.config");
|
|
|
@@ -3796,11 +3797,13 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
dto.setBarCode(fsStoreProductAttrValue.getBarCode());
|
|
|
dto.setGroupBarCode(fsStoreProductAttrValue.getGroupBarCode());
|
|
|
}
|
|
|
+ dto.setPrice(fsStoreProduct.getPrice());
|
|
|
if (attrValue != null) {
|
|
|
dto.setBarCode(attrValue.getBarCode());
|
|
|
dto.setGroupBarCode(attrValue.getGroupBarCode());
|
|
|
+ dto.setPrice(attrValue.getPrice());
|
|
|
}
|
|
|
- dto.setPrice(fsStoreProduct.getPrice());
|
|
|
+ //dto.setPrice(fsStoreProduct.getPrice());
|
|
|
dto.setProductName(fsStoreProduct.getProductName());
|
|
|
dto.setNum(Long.valueOf(liveOrder.getTotalNum()));
|
|
|
|
|
|
@@ -3812,7 +3815,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
liveOrderItem.setJsonInfo(JSON.toJSONString(dto));
|
|
|
liveOrderItemMapper.insertLiveOrderItem(liveOrderItem);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
redisCache.deleteObject("orderKey:" + liveOrder.getOrderKey());
|
|
|
//添加支付到期时间
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
@@ -3983,8 +3986,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
goods.setStock(goods.getStock()+Long.parseLong(liveOrder.getTotalNum()));
|
|
|
// 更新商品库存
|
|
|
liveGoodsMapper.updateLiveGoods(goods);
|
|
|
- // 删除限购记录
|
|
|
- deletePurchaseLimitRecordsForLiveOrder(liveOrder);
|
|
|
+
|
|
|
// 退券
|
|
|
this.refundCoupon(order);
|
|
|
TemplateBean templateBean = TemplateBean.builder()
|
|
|
@@ -4008,25 +4010,33 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
* @param productId 商品ID
|
|
|
* @param num 购买数量
|
|
|
*/
|
|
|
+ /**
|
|
|
+ * 减库存加销量(直播订单)
|
|
|
+ */
|
|
|
+ private void deStockIncSale(Long productId, Long attrValueId, Integer num) {
|
|
|
+ // 使用 productService.decProductStock 方法,该方法已包含库存检查逻辑
|
|
|
+ fsStoreProductService.decProductStock(productId, attrValueId, num);
|
|
|
+ }
|
|
|
+
|
|
|
private void checkPurchaseLimitForLiveOrder(Long userId, Long productId, Integer num) {
|
|
|
// 查询商品信息
|
|
|
FsStoreProductScrm product = fsStoreProductService.selectFsStoreProductById(productId);
|
|
|
if (product == null) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 如果商品没有设置限购,直接返回
|
|
|
if (product.getPurchaseLimit() == null || product.getPurchaseLimit() <= 0) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 查询用户已购买的数量
|
|
|
FsStoreProductPurchaseLimitScrm purchaseLimit = purchaseLimitService.selectByProductIdAndUserId(productId, userId);
|
|
|
int purchasedNum = 0;
|
|
|
if (purchaseLimit != null) {
|
|
|
purchasedNum = purchaseLimit.getNum();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查是否超过限购数量
|
|
|
if (purchasedNum + num > product.getPurchaseLimit()) {
|
|
|
int productTotalNum = purchasedNum + num;
|