|
|
@@ -62,7 +62,7 @@ public class ProductScrmController extends AppBaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private IFsStoreProductPurchaseLimitScrmService purchaseLimitService;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private IFsStoreOrderItemScrmService orderItemService;
|
|
|
/**
|
|
|
@@ -71,12 +71,13 @@ public class ProductScrmController extends AppBaseController {
|
|
|
* @return */
|
|
|
@ApiOperation("获取分类")
|
|
|
@GetMapping("/getProductCate")
|
|
|
- public R getProductCate(@RequestParam(name = "storeId",required = false) Long storeId){
|
|
|
+ public R getProductCate(@RequestParam(name = "storeId",required = false) Long storeId,@RequestParam(name = "appId",required = false) String appId){
|
|
|
try {
|
|
|
FsStoreProductCategoryScrm param=new FsStoreProductCategoryScrm();
|
|
|
param.setIsShow(1);
|
|
|
param.setIsDel(0);
|
|
|
param.setStoreId(storeId);
|
|
|
+ param.setAppId(appId);
|
|
|
List<FsStoreProductCategoryScrm> list=categoryService.selectFsStoreProductCategoryListQuery(param);
|
|
|
return R.ok().put("data",list);
|
|
|
} catch (Exception e){
|
|
|
@@ -250,7 +251,7 @@ public class ProductScrmController extends AppBaseController {
|
|
|
@Login
|
|
|
@ApiOperation("检查商品限购")
|
|
|
@GetMapping("/checkPurchaseLimit")
|
|
|
- public R checkPurchaseLimit(@RequestParam(value="productId") Long productId,
|
|
|
+ public R checkPurchaseLimit(@RequestParam(value="productId") Long productId,
|
|
|
@RequestParam(value="num", required = false, defaultValue = "1") Integer num){
|
|
|
try {
|
|
|
// 查询商品信息
|
|
|
@@ -258,13 +259,13 @@ public class ProductScrmController extends AppBaseController {
|
|
|
if(product == null){
|
|
|
return R.error("商品不存在");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查是否限购
|
|
|
if(product.getPurchaseLimit() == null || product.getPurchaseLimit() <= 0){
|
|
|
// 商品不限购,直接返回成功
|
|
|
return R.ok();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 商品有限购,查询用户已购买数量
|
|
|
String userId = getUserId();
|
|
|
if(userId == null){
|
|
|
@@ -276,14 +277,14 @@ public class ProductScrmController extends AppBaseController {
|
|
|
if (purchaseLimit != null) {
|
|
|
purchasedNum = purchaseLimit.getNum();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 计算剩余可购买数量
|
|
|
int remainingPurchaseLimit = product.getPurchaseLimit() - purchasedNum;
|
|
|
if (remainingPurchaseLimit < num) {
|
|
|
// 剩余可购买数量不足
|
|
|
return R.error("该商品限购" + product.getPurchaseLimit() + "件,您已购买" + purchasedNum + "件,本次购买" + num + "件,超出限购数量");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 剩余可购买数量充足
|
|
|
return R.ok();
|
|
|
} catch (Exception e){
|
|
|
@@ -376,29 +377,29 @@ public class ProductScrmController extends AppBaseController {
|
|
|
if (userId == null) {
|
|
|
return R.error("用户未登录");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (param.getProducts() == null || param.getProducts().isEmpty()) {
|
|
|
return R.error("商品列表不能为空");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Long userIdLong = Long.parseLong(userId);
|
|
|
List<String> errorMessages = new ArrayList<>();
|
|
|
-
|
|
|
+
|
|
|
// 按productId分组,累加同一商品不同规格的数量
|
|
|
Map<Long, Integer> productNumMap = new HashMap<>();
|
|
|
Map<Long, String> productNameMap = new HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
for (CartPurchaseLimitCheckParam.ProductItem item : param.getProducts()) {
|
|
|
Long productId = item.getProductId();
|
|
|
Integer num = item.getNum();
|
|
|
-
|
|
|
+
|
|
|
if (productId == null || num == null || num <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 累加同一商品的数量(不同规格算在一起)
|
|
|
productNumMap.put(productId, productNumMap.getOrDefault(productId, 0) + num);
|
|
|
-
|
|
|
+
|
|
|
// 保存商品名称(用于错误提示)
|
|
|
if (!productNameMap.containsKey(productId)) {
|
|
|
FsStoreProductScrm product = productService.selectFsStoreProductById(productId);
|
|
|
@@ -407,24 +408,24 @@ public class ProductScrmController extends AppBaseController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 遍历分组后的商品,检查限购
|
|
|
for (Map.Entry<Long, Integer> entry : productNumMap.entrySet()) {
|
|
|
Long productId = entry.getKey();
|
|
|
Integer totalNum = entry.getValue(); // 同一商品所有规格的总数量
|
|
|
-
|
|
|
+
|
|
|
// 查询商品信息
|
|
|
FsStoreProductScrm product = productService.selectFsStoreProductById(productId);
|
|
|
if (product == null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查是否限购
|
|
|
if (product.getPurchaseLimit() == null || product.getPurchaseLimit() <= 0) {
|
|
|
// 商品不限购,跳过
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 商品有限购,查询用户已购买数量
|
|
|
FsStoreProductPurchaseLimitScrm purchaseLimit = purchaseLimitService.selectByProductIdAndUserId(
|
|
|
productId, userIdLong);
|
|
|
@@ -432,12 +433,12 @@ public class ProductScrmController extends AppBaseController {
|
|
|
if (purchaseLimit != null) {
|
|
|
purchasedNum = purchaseLimit.getNum();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 计算剩余可购买数量
|
|
|
int remainingPurchaseLimit = product.getPurchaseLimit() - purchasedNum;
|
|
|
if (remainingPurchaseLimit < totalNum) {
|
|
|
// 超过限购,添加错误信息
|
|
|
- String productName = productNameMap.getOrDefault(productId,
|
|
|
+ String productName = productNameMap.getOrDefault(productId,
|
|
|
product.getProductName() != null ? product.getProductName() : "商品ID:" + productId);
|
|
|
String errorMsg = String.format("商品【%s】限购%d件,您已购买%d件,本次购买%d件,超出限购数量",
|
|
|
productName,
|
|
|
@@ -447,13 +448,13 @@ public class ProductScrmController extends AppBaseController {
|
|
|
errorMessages.add(errorMsg);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 如果有错误信息,拼接并返回
|
|
|
if (!errorMessages.isEmpty()) {
|
|
|
String errorMsg = String.join(";", errorMessages);
|
|
|
return R.error(errorMsg);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 所有商品都通过限购检查
|
|
|
return R.ok();
|
|
|
} catch (Exception e) {
|
|
|
@@ -470,39 +471,39 @@ public class ProductScrmController extends AppBaseController {
|
|
|
if (userId == null) {
|
|
|
return R.error("用户未登录");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (orderCode == null || orderCode.trim().isEmpty()) {
|
|
|
return R.error("订单号不能为空");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Long userIdLong = Long.parseLong(userId);
|
|
|
-
|
|
|
+
|
|
|
// 根据orderCode查询订单商品
|
|
|
FsStoreOrderItemScrm queryParam = new FsStoreOrderItemScrm();
|
|
|
queryParam.setOrderCode(orderCode);
|
|
|
List<FsStoreOrderItemScrm> orderItems = orderItemService.selectFsStoreOrderItemList(queryParam);
|
|
|
-
|
|
|
+
|
|
|
if (orderItems == null || orderItems.isEmpty()) {
|
|
|
return R.error("订单不存在或订单中没有商品");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
List<String> errorMessages = new ArrayList<>();
|
|
|
-
|
|
|
+
|
|
|
// 按productId分组,累加同一商品不同规格的数量
|
|
|
Map<Long, Integer> productNumMap = new HashMap<>();
|
|
|
Map<Long, String> productNameMap = new HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
for (FsStoreOrderItemScrm orderItem : orderItems) {
|
|
|
Long productId = orderItem.getProductId();
|
|
|
Integer num = orderItem.getNum();
|
|
|
-
|
|
|
+
|
|
|
if (productId == null || num == null || num <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 累加同一商品的数量(不同规格算在一起)
|
|
|
productNumMap.put(productId, productNumMap.getOrDefault(productId, 0) + num);
|
|
|
-
|
|
|
+
|
|
|
// 保存商品名称(用于错误提示)
|
|
|
if (!productNameMap.containsKey(productId)) {
|
|
|
FsStoreProductScrm product = productService.selectFsStoreProductById(productId);
|
|
|
@@ -511,24 +512,24 @@ public class ProductScrmController extends AppBaseController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 遍历分组后的商品,检查限购
|
|
|
for (Map.Entry<Long, Integer> entry : productNumMap.entrySet()) {
|
|
|
Long productId = entry.getKey();
|
|
|
Integer totalNum = entry.getValue(); // 同一商品所有规格的总数量
|
|
|
-
|
|
|
+
|
|
|
// 查询商品信息
|
|
|
FsStoreProductScrm product = productService.selectFsStoreProductById(productId);
|
|
|
if (product == null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查是否限购
|
|
|
if (product.getPurchaseLimit() == null || product.getPurchaseLimit() <= 0) {
|
|
|
// 商品不限购,跳过
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 商品有限购,查询用户已购买数量
|
|
|
FsStoreProductPurchaseLimitScrm purchaseLimit = purchaseLimitService.selectByProductIdAndUserId(
|
|
|
productId, userIdLong);
|
|
|
@@ -536,12 +537,12 @@ public class ProductScrmController extends AppBaseController {
|
|
|
if (purchaseLimit != null) {
|
|
|
purchasedNum = purchaseLimit.getNum();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 计算剩余可购买数量(订单中的数量也要计算在内)
|
|
|
int remainingPurchaseLimit = product.getPurchaseLimit() - purchasedNum;
|
|
|
if (remainingPurchaseLimit < totalNum) {
|
|
|
// 超过限购,添加错误信息
|
|
|
- String productName = productNameMap.getOrDefault(productId,
|
|
|
+ String productName = productNameMap.getOrDefault(productId,
|
|
|
product.getProductName() != null ? product.getProductName() : "商品ID:" + productId);
|
|
|
String errorMsg = String.format("商品【%s】限购%d件,您已购买%d件,订单中购买%d件,超出限购数量",
|
|
|
productName,
|
|
|
@@ -551,13 +552,13 @@ public class ProductScrmController extends AppBaseController {
|
|
|
errorMessages.add(errorMsg);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 如果有错误信息,拼接并返回
|
|
|
if (!errorMessages.isEmpty()) {
|
|
|
String errorMsg = String.join(";", errorMessages);
|
|
|
return R.error(errorMsg);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 所有商品都通过限购检查
|
|
|
return R.ok();
|
|
|
} catch (Exception e) {
|