|
|
@@ -863,7 +863,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (userId == null || productAttrValueId == null) {
|
|
|
return 0;
|
|
|
}
|
|
|
- return fsStoreOrderMapper.selectUserPurchasedCount(userId, productAttrValueId);
|
|
|
+ // 获取商品ID(通过规格ID查询)
|
|
|
+ FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(productAttrValueId);
|
|
|
+ if (attrValue == null || attrValue.getProductId() == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ // 按商品ID统计购买数量,不区分规格
|
|
|
+ return fsStoreOrderMapper.selectUserPurchasedCountByProductId(userId, attrValue.getProductId());
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -4368,6 +4374,25 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
return R.error("正在支付中...");
|
|
|
}
|
|
|
|
|
|
+ // 支付前检查限购
|
|
|
+ List<FsStoreOrderItemVO> orderItems = fsStoreOrderItemMapper.selectFsStoreOrderItemListByOrderId(order.getId());
|
|
|
+ for (FsStoreOrderItemVO item : orderItems) {
|
|
|
+ FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(item.getProductAttrValueId());
|
|
|
+ if (attrValue != null && attrValue.getPurchaseLimit() != null && attrValue.getPurchaseLimit() > 0) {
|
|
|
+ // 查询用户已购买该商品的数量(按商品ID统计)
|
|
|
+ Integer purchasedCount = this.selectUserPurchasedCount(order.getUserId(), item.getProductAttrValueId());
|
|
|
+ if (purchasedCount == null) {
|
|
|
+ purchasedCount = 0;
|
|
|
+ }
|
|
|
+ // 计算总购买数量(已购买 + 本次订单数量)
|
|
|
+ long totalPurchased = purchasedCount + item.getNum();
|
|
|
+ // 检查是否超过限购数量
|
|
|
+ if (totalPurchased > attrValue.getPurchaseLimit()) {
|
|
|
+ return R.error("商品限购" + attrValue.getPurchaseLimit() + "件,您已购买" + purchasedCount + "件,无法再次购买");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
if(user!=null){
|
|
|
//已改价处理
|