diff --git a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java index 99c100c4..9d3ca063 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java +++ b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBindConnectController.java @@ -85,5 +85,17 @@ public class AccountUserBindConnectController { return accountUserBindConnectService.getUserBindConnectUserIdByCondition(bind_id, bind_type, user_type); } + /** + * 检查手机注册的商家是否存在(仅供内部调用) + * + * @param mobile + * @return + */ + @ApiOperation(value = "检查手机注册的商家是否存在(仅供内部调用)", notes = "检查手机注册的商家是否存在(仅供内部调用)") + @RequestMapping(value = "/is-merchant-exists", method = RequestMethod.POST) + public Integer isMerchantExists(@RequestParam(name = "mobile") String mobile) { + return accountUserBindConnectService.isMerchantExists(mobile); + } + } diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java index ebc26691..5bca855c 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBindConnectService.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject; import com.suisung.mall.common.modules.account.AccountUserBindConnect; import com.suisung.mall.common.pojo.req.WxUserInfoReq; import com.suisung.mall.core.web.service.IBaseService; + import java.util.List; import java.util.Map; @@ -89,9 +90,17 @@ public interface AccountUserBindConnectService extends IBaseService getAllBindPage(String bindTmpl,Integer pageNum, Integer pageSize); + List getAllBindPage(String bindTmpl, Integer pageNum, Integer pageSize); long getAllBindCount(String bindTmpl); void bindTmplId(JSONObject jsonObject); + + /** + * 检查手机注册的商家是否存在 + * + * @param mobile + * @return 1-存在;2-不存在;3-参数有误 + */ + Integer isMerchantExists(String mobile); } diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindConnectServiceImpl.java b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindConnectServiceImpl.java index 30234da5..8c7a8db8 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindConnectServiceImpl.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindConnectServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.suisung.mall.account.mapper.AccountUserBindConnectMapper; @@ -19,6 +20,7 @@ import com.suisung.mall.common.modules.account.AccountUserBase; import com.suisung.mall.common.modules.account.AccountUserBindConnect; import com.suisung.mall.common.modules.account.AccountUserInfo; import com.suisung.mall.common.pojo.req.WxUserInfoReq; +import com.suisung.mall.common.utils.CheckUtil; import com.suisung.mall.common.utils.I18nUtil; import com.suisung.mall.common.utils.StringUtils; import com.suisung.mall.common.utils.phone.PhoneNumberUtils; @@ -367,6 +369,65 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(AccountUserBindConnect::getBind_id, convertedMobile) + .eq(AccountUserBindConnect::getBind_type, BindCode.MOBILE) // 1-手机号 + .eq(AccountUserBindConnect::getUser_type, CommonConstant.USER_TYPE_MCH) // 2-入驻商家 + .eq(AccountUserBindConnect::getBind_active, CommonConstant.Enable) + .orderByAsc(AccountUserBindConnect::getBind_time) + .select(AccountUserBindConnect::getUser_id); + + log.debug("执行查询,转换后的手机号: {}, 查询条件: {}", convertedMobile, queryWrapper.getSqlSegment()); + + AccountUserBindConnect accountUserBindConnect = getOne(queryWrapper); + if (accountUserBindConnect == null || CheckUtil.isEmpty(accountUserBindConnect.getUser_id())) { + log.info("未找到手机号绑定的商家记录,手机号: {}", convertedMobile); + return 2; + } + + Integer userId = accountUserBindConnect.getUser_id(); + log.debug("找到用户ID: {}", userId); + + AccountUserBase accountUserBase = accountUserBaseService.get(userId); + if (accountUserBase == null) { + log.warn("用户基础信息不存在,用户ID: {}", userId); + return 2; + } + + log.info("商家存在,用户ID: {}", userId); + return 1; + + } catch (Exception e) { + log.error("查询商家绑定信息时发生异常,手机号: {}", mobile, e); + return null; + } + } + + /** * 用户绑定手机号和openid * @@ -505,24 +566,24 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl getAllBindPage(String bindTmpl,Integer pageNum, Integer pageSize) { + public List getAllBindPage(String bindTmpl, Integer pageNum, Integer pageSize) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.select("bind_id,bind_type,user_id,user_type"); - queryWrapper.in("bind_type", Arrays.asList(BindCode.MOBILE,BindCode.WEIXIN_XCX)) + queryWrapper.in("bind_type", Arrays.asList(BindCode.MOBILE, BindCode.WEIXIN_XCX)) .eq("user_type", CommonConstant.USER_TYPE_NORMAL) .eq("bind_active", CommonConstant.Enable) - .eq("bind_tmpl",bindTmpl) + .eq("bind_tmpl", bindTmpl) .orderByAsc("bind_time"); - return this.lists(queryWrapper,pageNum,pageSize).getRecords(); + return this.lists(queryWrapper, pageNum, pageSize).getRecords(); } @Override public long getAllBindCount(String bindTmpl) { QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.in("bind_type", Arrays.asList(BindCode.MOBILE,BindCode.WEIXIN_XCX)) + queryWrapper.in("bind_type", Arrays.asList(BindCode.MOBILE, BindCode.WEIXIN_XCX)) .eq("user_type", CommonConstant.USER_TYPE_NORMAL) .eq("bind_active", CommonConstant.Enable) - .eq("bind_tmpl",bindTmpl) + .eq("bind_tmpl", bindTmpl) .orderByAsc("bind_time"); return this.count(queryWrapper); } @@ -537,42 +598,42 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("bind_openid",openId) + queryWrapper.eq("bind_openid", openId) .eq("user_type", CommonConstant.USER_TYPE_NORMAL) - .in("bind_type",Arrays.asList(1,15)) + .in("bind_type", Arrays.asList(1, 15)) .eq("bind_active", CommonConstant.Enable); - List accountUserBindConnectList= list(queryWrapper); + List accountUserBindConnectList = list(queryWrapper); if (!accountUserBindConnectList.isEmpty()) { - AccountUserBindConnect accountUserBindConnect=accountUserBindConnectList.get(0); - JSONArray jsonArray=null; - JSONObject object= null; + AccountUserBindConnect accountUserBindConnect = accountUserBindConnectList.get(0); + JSONArray jsonArray = null; + JSONObject object = null; try { - jsonArray= jsonObject.getJSONArray("List"); - }catch (RuntimeException runtimeException){ + jsonArray = jsonObject.getJSONArray("List"); + } catch (RuntimeException runtimeException) { log.info("单个模板"); - object=jsonObject.getJSONObject("List"); + object = jsonObject.getJSONObject("List"); } UpdateWrapper updateWrapper = new UpdateWrapper<>(); if (jsonArray != null) { - object= (JSONObject) jsonArray.get(0); - String templateId= object.getStr("TemplateId");//模板id - String SubscribeStatusString= object.getStr("SubscribeStatusString");//订阅结果(accept接收;reject拒收)参考地址https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/subscribe-message.html#%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF%E8%AF%AD%E9%9F%B3%E6%8F%90%E9%86%92 - if(SubscribeStatusString.equals("accept")){ + object = (JSONObject) jsonArray.get(0); + String templateId = object.getStr("TemplateId");//模板id + String SubscribeStatusString = object.getStr("SubscribeStatusString");//订阅结果(accept接收;reject拒收)参考地址https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/subscribe-message.html#%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF%E8%AF%AD%E9%9F%B3%E6%8F%90%E9%86%92 + if (SubscribeStatusString.equals("accept")) { accountUserBindConnect.setBind_tmpl(templateId); getUpdateWrapper(updateWrapper, accountUserBindConnect); } - }else { + } else { assert object != null; - String templateId= object.getStr("TemplateId");//模板id - String SubscribeStatusString= object.getStr("SubscribeStatusString"); - if(StringUtils.isNotEmpty(SubscribeStatusString)&&SubscribeStatusString.equals("accept")){ + String templateId = object.getStr("TemplateId");//模板id + String SubscribeStatusString = object.getStr("SubscribeStatusString"); + if (StringUtils.isNotEmpty(SubscribeStatusString) && SubscribeStatusString.equals("accept")) { accountUserBindConnect.setBind_tmpl(templateId); getUpdateWrapper(updateWrapper, accountUserBindConnect); - }else { - String ErrorStatus=object.getStr("ErrorStatus"); - if(ErrorStatus.equals("success")){ + } else { + String ErrorStatus = object.getStr("ErrorStatus"); + if (ErrorStatus.equals("success")) { log.info("消息推送成功给用户,不需要操作"); return; } @@ -584,16 +645,17 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl updateWrapper, AccountUserBindConnect accountUserBindConnect) { - updateWrapper.set("bind_tmpl",accountUserBindConnect.getBind_tmpl()); - updateWrapper.eq("bind_id",accountUserBindConnect.getBind_id()); - updateWrapper.eq("bind_type",accountUserBindConnect.getBind_type()); - updateWrapper.eq("user_id",accountUserBindConnect.getUser_id()); - updateWrapper.eq("user_type",accountUserBindConnect.getUser_type()); + updateWrapper.set("bind_tmpl", accountUserBindConnect.getBind_tmpl()); + updateWrapper.eq("bind_id", accountUserBindConnect.getBind_id()); + updateWrapper.eq("bind_type", accountUserBindConnect.getBind_type()); + updateWrapper.eq("user_id", accountUserBindConnect.getUser_id()); + updateWrapper.eq("user_type", accountUserBindConnect.getUser_type()); } } diff --git a/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java b/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java index f29a63ba..5e327176 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java +++ b/mall-common/src/main/java/com/suisung/mall/common/feignService/AccountService.java @@ -303,4 +303,14 @@ public interface AccountService { @GetMapping(value = "/admin/account/accountController/getAllBindCount") long getAllBindCount(@RequestParam(name = "bindTmpl") String bindTmpl); + + + /** + * 检查手机注册的商家是否存在(仅供内部调用) + * + * @param mobile + * @return + */ + @RequestMapping(value = "/admin/account/account-user-bind-connect/is-merchant-exists", method = RequestMethod.POST) + Integer isMerchantExists(@RequestParam(name = "mobile") String mobile); } diff --git a/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/MainStoreBranchReqDTO.java b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/MainStoreBranchReqDTO.java new file mode 100644 index 00000000..61e890a2 --- /dev/null +++ b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/MainStoreBranchReqDTO.java @@ -0,0 +1,72 @@ +package com.suisung.mall.common.pojo.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 新增主店的分店的请求DTO实体类 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "新增主店的分店的请求DTO实体类", description = "新增主店的分店的请求DTO实体类") +public class MainStoreBranchReqDTO implements java.io.Serializable { + private static final long serialVersionUID = 1L; + + /** + * 主店店铺 ID + */ + private Integer parent_store_id; + + /** + * 登录手机号 + */ + private String login_mobile; + + /** + * 登录密码 + */ + private String password; + + /** + * 分店名称 + */ + private String store_name; + + /** + * 分店联系人 + */ + private String contact_name; + + /** + * 分店联系人手机号 + */ + private String email; + + /** + * 门头图片 + */ + private String front_facade_image; + + /** + * 环境图片 + */ + private String environment_image; + + /** + * 分店地址 + */ + private String store_address; + + /** + * 分店经度 + */ + private String store_longitude; + + /** + * 分店纬度 + */ + private String store_latitude; + + +} diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/mapper/ShopMchEntryBranchMapper.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/mapper/ShopMchEntryBranchMapper.java new file mode 100644 index 00000000..0c9d0026 --- /dev/null +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/mapper/ShopMchEntryBranchMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.suisung.mall.shop.store.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.suisung.mall.common.modules.store.ShopMchEntryBranch; +import org.springframework.stereotype.Component; + +@Component +public interface ShopMchEntryBranchMapper extends BaseMapper { +} diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopMchEntryBranchService.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopMchEntryBranchService.java new file mode 100644 index 00000000..8bd3b804 --- /dev/null +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopMchEntryBranchService.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. + * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. + * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. + * Vestibulum commodo. Ut rhoncus gravida arcu. + */ + +package com.suisung.mall.shop.store.service; + +import com.suisung.mall.common.modules.store.ShopMchEntryBranch; +import com.suisung.mall.common.pojo.dto.MainStoreBranchReqDTO; +import org.springframework.data.util.Pair; + +public interface ShopMchEntryBranchService { + + /** + * 保存或更新商户终端入驻申请信息 + * + * @param shopMchEntryBranch 商户入驻申请信息 + * @return 保存结果 + */ + Boolean saveShopMchEntryBranch(ShopMchEntryBranch shopMchEntryBranch); + + /** + * 根据商户终端入驻申请ID查询商户终端入驻申请信息 + * + * @param reviewRelatedId 商户终端入驻申请ID + * @return 商户入驻申请信息 + */ + ShopMchEntryBranch getByReviewRelatedId(String reviewRelatedId); + + + /** + * (重要)创建主店铺的分店账号、店铺信息、店铺员工信息、店铺权限信息、入驻信息 + * + * @param mainStoreBranchReq 商户终端入驻申请门店信息 + * @return 创建结果 + */ + Pair createMchEntryBranchStore(MainStoreBranchReqDTO mainStoreBranchReq); +} diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopMchEntryService.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopMchEntryService.java index 40ce92cc..42862d36 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopMchEntryService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopMchEntryService.java @@ -9,6 +9,7 @@ package com.suisung.mall.shop.store.service; import cn.hutool.json.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.modules.store.ShopMchEntry; import org.springframework.data.util.Pair; @@ -375,4 +376,6 @@ public interface ShopMchEntryService { * @return */ ShopMchEntry getLklContractStatusUrl(Integer storeId); + + ShopMchEntry findOneByLambdaQueryWrapper(LambdaQueryWrapper query); } \ No newline at end of file diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryBranchServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryBranchServiceImpl.java new file mode 100644 index 00000000..0fd1a740 --- /dev/null +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryBranchServiceImpl.java @@ -0,0 +1,254 @@ +package com.suisung.mall.shop.store.service.impl; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.suisung.mall.common.constant.CommonConstant; +import com.suisung.mall.common.feignService.AccountService; +import com.suisung.mall.common.modules.store.ShopMchEntry; +import com.suisung.mall.common.modules.store.ShopMchEntryBranch; +import com.suisung.mall.common.modules.store.ShopStoreBase; +import com.suisung.mall.common.pojo.dto.MainStoreBranchReqDTO; +import com.suisung.mall.common.utils.CheckUtil; +import com.suisung.mall.core.web.service.impl.BaseServiceImpl; +import com.suisung.mall.shop.lakala.service.impl.LklTkServiceImpl; +import com.suisung.mall.shop.store.mapper.ShopMchEntryBranchMapper; +import com.suisung.mall.shop.store.mapper.ShopMchEntryMapper; +import com.suisung.mall.shop.store.service.ShopMchEntryBranchService; +import com.suisung.mall.shop.store.service.ShopMchEntryService; +import com.suisung.mall.shop.store.service.ShopStoreBaseService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.util.Pair; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.Objects; + +@Slf4j +@Service +public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl implements ShopMchEntryBranchService { + @Autowired + private ShopStoreBaseService shopStoreBaseService; + + @Autowired + private ShopMchEntryService shopMchEntryService; + + @Autowired + private AccountService accountService; + + + @Autowired + private ShopMchEntryMapper shopMchEntryMapper; + + @Autowired + private LklTkServiceImpl lklTkService; + + + /** + * 保存或更新商户终端入驻申请信息 + *

+ * 根据 reviewRelatedId 确定新增或更改记录 + * + * @param shopMchEntryBranch 商户入驻申请信息 + * @return 保存结果 + */ + @Override + public Boolean saveShopMchEntryBranch(ShopMchEntryBranch shopMchEntryBranch) { + try { + if (shopMchEntryBranch == null) { + log.error("商户终端入驻申请信息不能为空"); + return false; + } + + // 验证必要字段 + if (StrUtil.isBlank(shopMchEntryBranch.getReview_related_id())) { + log.error("审核关联号不能为空"); + return false; + } + + String reviewRelatedId = shopMchEntryBranch.getReview_related_id(); + + // 查询是否已存在记录 + ShopMchEntryBranch existingRecord = getByReviewRelatedId(reviewRelatedId); + + boolean result; + if (existingRecord != null) { + // 更新现有记录 + shopMchEntryBranch.setId(existingRecord.getId()); + result = updateById(shopMchEntryBranch); + log.info("更新商户终端入驻申请信息成功,审核关联号: {}", reviewRelatedId); + } else { + // 新增记录 + result = save(shopMchEntryBranch); + log.info("新增商户终端入驻申请信息成功,审核关联号: {}", reviewRelatedId); + } + + return result; + } catch (Exception e) { + log.error("保存或更新商户终端入驻申请信息失败,审核关联号: {}", + shopMchEntryBranch != null ? shopMchEntryBranch.getReview_related_id() : "null", e); + return false; + } + } + + /** + * 根据商户终端入驻申请ID查询商户终端入驻申请信息 + * + * @param reviewRelatedId 商户终端入驻申请ID + * @return 商户入驻申请信息 + */ + @Override + public ShopMchEntryBranch getByReviewRelatedId(String reviewRelatedId) { + try { + if (StrUtil.isBlank(reviewRelatedId)) { + log.warn("审核关联号为空,无法查询商户终端入驻申请信息"); + return null; + } + + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ShopMchEntryBranch::getReview_related_id, reviewRelatedId); + + ShopMchEntryBranch result = findOne(queryWrapper); + + if (result != null) { + log.debug("查询商户终端入驻申请信息成功,审核关联号: {}", reviewRelatedId); + } else { + log.info("未找到对应的商户终端入驻申请信息,审核关联号: {}", reviewRelatedId); + } + + return result; + } catch (Exception e) { + log.error("查询商户终端入驻申请信息失败,审核关联号: {}", reviewRelatedId, e); + return null; + } + } + + /** + * 创建分店商户入驻申请 + * + * @param mainStoreBranchReq 分店入驻请求DTO + * @return Pair - 执行结果和提示信息 + */ + @Override + public Pair createMchEntryBranchStore(MainStoreBranchReqDTO mainStoreBranchReq) { + log.info("开始创建分店商户入驻申请,请求参数: {}", JSONUtil.toJsonStr(mainStoreBranchReq)); + + try { + // 1. 参数校验 + if (mainStoreBranchReq == null) { + log.warn("分店入驻信息不能为空"); + return Pair.of(false, "分店入驻信息不能为空"); + } + + if (mainStoreBranchReq.getParent_store_id() == null) { + log.warn("主店ID不能为空"); + return Pair.of(false, "主店ID不能为空"); + } + + // 2. 检查主店信息是否存在 + log.debug("检查主店信息是否存在,主店ID: {}", mainStoreBranchReq.getParent_store_id()); + LambdaQueryWrapper entryQueryWrapper = new LambdaQueryWrapper<>(); + entryQueryWrapper.eq(ShopMchEntry::getStore_id, mainStoreBranchReq.getParent_store_id()) + .eq(ShopMchEntry::getApproval_status, CommonConstant.Enable) + .eq(ShopMchEntry::getParent_id, 0L); + ShopMchEntry mchEntry = shopMchEntryService.findOneByLambdaQueryWrapper(entryQueryWrapper); + + if (mchEntry == null) { + log.warn("主店商户入驻信息不存在,主店ID: {}", mainStoreBranchReq.getParent_store_id()); + return Pair.of(false, "主店商户入驻信息不存在"); + } + log.debug("找到主店信息,商户ID: {}, 拉卡拉商户号: {}", mchEntry.getId(), mchEntry.getLkl_mer_cup_no()); + + // 3. 检查主店入驻状态是否已经完成 + log.debug("检查主店入驻状态,当前状态: {}", mchEntry.getLkl_tk_audit_status()); + if (!Objects.equals(mchEntry.getLkl_tk_audit_status(), CommonConstant.Enable)) { + log.warn("主店入驻状态未完成,当前状态: {},无法创建分店", mchEntry.getLkl_tk_audit_status()); + return Pair.of(false, "主店入驻状态未完成,无法创建分店"); + } + + // 4. 检查主店信息是否存在(根据parent_store_id获取shop_store_base表记录) + log.debug("检查主店基础信息是否存在"); + LambdaQueryWrapper baseQueryWrapper = new LambdaQueryWrapper<>(); + baseQueryWrapper.eq(ShopStoreBase::getStore_id, mainStoreBranchReq.getParent_store_id()); + ShopStoreBase parentStore = shopStoreBaseService.getOne(baseQueryWrapper); + if (parentStore == null) { + log.warn("主店信息不存在,主店ID: {}", mainStoreBranchReq.getParent_store_id()); + return Pair.of(false, "主店信息不存在"); + } + log.debug("主店基础信息存在,店铺名称: {}", parentStore.getStore_name()); + + // 5. 检查店铺名称是否已经存在 + log.debug("检查店铺名称是否已存在: {}", mainStoreBranchReq.getStore_name()); + LambdaQueryWrapper nameQueryWrapper = new LambdaQueryWrapper<>(); + nameQueryWrapper.eq(ShopStoreBase::getStore_name, mainStoreBranchReq.getStore_name()); + ShopStoreBase existingStore = shopStoreBaseService.getOne(nameQueryWrapper); + if (existingStore != null) { + log.warn("店铺名称已存在: {}", mainStoreBranchReq.getStore_name()); + return Pair.of(false, "店铺名称已存在"); + } + log.debug("店铺名称检查通过"); + + // 6. 检查分店登录手机号是否已经注册过商户 + log.debug("检查手机号是否已注册商户: {}", mainStoreBranchReq.getLogin_mobile()); + Integer status = accountService.isMerchantExists(mainStoreBranchReq.getLogin_mobile()); + if (CheckUtil.isEmpty(status)) { + log.error("调用账户服务检查商户信息失败,手机号: {}", mainStoreBranchReq.getLogin_mobile()); + return Pair.of(false, "检查商户信息失败!"); + } + + if (status == CommonConstant.Enable) { + log.warn("手机号商户已被注册: {}", mainStoreBranchReq.getLogin_mobile()); + return Pair.of(false, "手机号商户已被注册"); + } + log.debug("手机号检查通过"); + + // 7. 检查分店终端号是否已经申请或申请中 + log.debug("检查分店终端号是否已申请或申请中,拉卡拉内部商户号: {}", mchEntry.getLkl_mer_inner_no()); + LambdaQueryWrapper branchQueryWrapper = new LambdaQueryWrapper<>(); + branchQueryWrapper.eq(ShopMchEntryBranch::getLkl_mer_cup_no, mchEntry.getLkl_mer_inner_no()) + .in(ShopMchEntryBranch::getStatus, Arrays.asList(1, 3)); // 1-申请中,3-可能的其他状态 + long existingBranchCount = count(branchQueryWrapper); + if (existingBranchCount > 0) { + log.info("分店终端号已申请或申请中,拉卡拉内部商户号: {},已存在申请数量: {}", + mchEntry.getLkl_mer_inner_no(), existingBranchCount); + return Pair.of(true, "分店终端号已申请或申请中,请等待审核"); + } + log.debug("终端号检查通过"); + + // 8. 调用拉卡拉接口创建商户终端 + log.info("调用拉卡拉接口创建商户终端,主店拉卡拉商户号: {}", mchEntry.getLkl_mer_cup_no()); + JSONObject lklResp = lklTkService.openMerchantAddTerm(mchEntry.getLkl_mer_cup_no()); + if (lklResp == null || StrUtil.isBlank(lklResp.getStr("reviewRelatedId"))) { + log.error("调用拉卡拉接口创建商户终端失败,主店拉卡拉商户号: {}", mchEntry.getLkl_mer_cup_no()); + return Pair.of(false, "分店提交申请失败"); + } + log.info("拉卡拉接口调用成功,审核关联号: {}", lklResp.getStr("reviewRelatedId")); + + // 9. 保存商户入驻申请信息 + log.debug("开始保存商户入驻申请信息"); + ShopMchEntryBranch shopMchEntryBranch = new ShopMchEntryBranch(); + shopMchEntryBranch.setLkl_mer_cup_no(mchEntry.getLkl_mer_cup_no()); + shopMchEntryBranch.setReview_related_id(lklResp.getStr("reviewRelatedId")); + shopMchEntryBranch.setLkl_req(JSONUtil.toJsonStr(mainStoreBranchReq)); + shopMchEntryBranch.setLkl_reps(JSONUtil.toJsonStr(lklResp)); + + Boolean isSuccess = saveShopMchEntryBranch(shopMchEntryBranch); + if (!isSuccess) { + log.error("保存商户入驻申请信息失败,审核关联号: {}", lklResp.getStr("reviewRelatedId")); + return Pair.of(false, "分店提交申请失败"); + } + log.info("商户入驻申请信息保存成功,审核关联号: {}", lklResp.getStr("reviewRelatedId")); + + log.info("分店商户入驻申请创建成功,审核关联号: {}", lklResp.getStr("reviewRelatedId")); + return Pair.of(true, "分店提交申请成功"); + + } catch (Exception e) { + log.error("创建分店商户入驻申请时发生异常,请求参数: {}", JSONUtil.toJsonStr(mainStoreBranchReq), e); + return Pair.of(false, "分店提交申请失败:" + e.getMessage()); + } + } + + +} diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java index 5f1a6c9d..2fcd7641 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java @@ -2579,6 +2579,29 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl query) { + // 参数校验 + if (query == null) { + log.warn("查询条件为空,无法执行查询"); + return null; + } + + try { + // 执行查询 + return findOne(query); + } catch (Exception e) { + log.error("执行商户入驻查询时发生异常", e); + return null; + } + } + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java index f7837a02..1550b6a7 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java @@ -2473,12 +2473,8 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl 0) { + BigDecimal packingFee = Convert.toBigDecimal(getParameter("packing_fee"), BigDecimal.ZERO); + if (packingFee.compareTo(new BigDecimal("10")) >= 0) { logger.warn("打包费超出范围: {}", packingFee); return CommonResult.failed("打包费请控制在0到10元范围"); } @@ -2668,12 +2664,8 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl 0) { + BigDecimal packingFee = Convert.toBigDecimal(getParameter("packing_fee"), BigDecimal.ZERO); + if (packingFee.compareTo(new BigDecimal("10")) >= 0) { logger.warn("打包费超出范围: {}", packingFee); return CommonResult.failed("打包费请控制在0到10元范围"); } @@ -3327,6 +3319,7 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl