From 9fa875038b12de2aa9d52f9d8c930c1ab28791e6 Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Wed, 25 Jun 2025 11:31:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=BA=97=E9=93=BA=E5=90=8D=E6=98=AF=E5=90=A6=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E4=BD=BF=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/mobile/StoreController.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/mobile/StoreController.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/mobile/StoreController.java index af7747ec..e93ac01c 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/mobile/StoreController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/controller/mobile/StoreController.java @@ -3,6 +3,7 @@ package com.suisung.mall.shop.store.controller.mobile; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.PhoneUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -251,18 +252,60 @@ public class StoreController extends BaseControllerImpl { @ApiOperation(value = "获取附近店铺列表", notes = "获取附近店铺列表") @RequestMapping(value = "/near/list", method = RequestMethod.GET) - public CommonResult nearStoreList(@RequestParam(value = "provinceId",required = false) String provinceId, + public CommonResult nearStoreList(@RequestParam(value = "provinceId", required = false) String provinceId, @RequestParam("cityId") String cityId, @RequestParam("countyId") String countyId, @RequestParam("userLng") String userLng, @RequestParam("userLat") String userLat, @RequestParam(value = "storeCategoryId", required = false) Integer storeCategoryId, - @RequestParam(value = "subSiteId",required = false) Integer subSiteId, - @RequestParam(value = "storeName",required = false) String storeName, + @RequestParam(value = "subSiteId", required = false) Integer subSiteId, + @RequestParam(value = "storeName", required = false) String storeName, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) { IPage storeList = shopStoreBaseService.getNearShop2(provinceId, cityId, countyId, userLng, userLat, storeCategoryId, subSiteId, storeName, pageNum, pageSize); return CommonResult.success(storeList); } + /** + * 检查店铺名称是否已存在。 + *

+ * 支持通过请求体或请求参数传入店铺名称。若两者都未提供,则返回错误信息。 + * 若店铺名存在,返回状态码 1;否则返回状态码 2。 + * + * @param paramsJSON 请求体中的 JSON 参数(可选) + * @param storeName 请求参数中的店铺名称(可选) + * @return CommonResult 返回检查结果 + */ + @ApiOperation("检查店铺名是否已存在?") + @RequestMapping(value = "/check-store-name-exists", method = RequestMethod.POST) + public CommonResult checkStoreNameExists(@RequestBody JSONObject paramsJSON, + @RequestParam(name = "storeName", required = false) String storeName) { + // 优先从请求体中获取店铺名称 + String storeNameFromJson = paramsJSON.getStr("storeName"); + if (StrUtil.isNotBlank(storeNameFromJson)) { + storeName = storeNameFromJson; + } + + // 如果店铺名称为空,直接返回失败结果 + if (StrUtil.isBlank(storeName)) { + return CommonResult.failed("请输入店铺名"); + } + + try { + // 调用服务层检查店铺名称是否存在 + Boolean exists = shopStoreBaseService.isExistsByStoreName(storeName); + + if (Boolean.TRUE.equals(exists)) { + // 店铺名已存在 + return CommonResult.success(new JSONObject().set("flag", 2), "店铺名已被使用!"); + } else { + // 店铺名不存在 + return CommonResult.success(new JSONObject().set("flag", 1), "店铺名可以使用!"); + } + } catch (Exception e) { + // 捕获异常并返回统一的错误信息 + throw new ApiException("检查店铺名称是否存在时发生异常:" + e.getMessage(), e); + } + } + } \ No newline at end of file