diff --git a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBaseController.java b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBaseController.java index 39838857..81287903 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBaseController.java +++ b/mall-account/src/main/java/com/suisung/mall/account/controller/admin/AccountUserBaseController.java @@ -30,7 +30,9 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.util.Pair; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -231,5 +233,11 @@ public class AccountUserBaseController extends BaseControllerImpl { return CommonResult.success(accountUserBaseService.logout()); } + @ApiOperation("服务间注册商家账号,项目之间远程调用") + @RequestMapping(value = "/merchant/inner-register", method = RequestMethod.POST) + public Pair merchantInnerRegister(@Param("mobile") String mobile) { + return accountUserBaseService.merchantInnerRegister(mobile); + } + } diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java index 596db891..88c9121a 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/AccountUserBaseService.java @@ -296,4 +296,12 @@ public interface AccountUserBaseService extends IBaseService { * @return */ ThirdApiRes saveBatchAccountInfo(List accountUserInfoList); + + /** + * 商家内部注册(服务之间调用) + * + * @param mobile 商家手机号 + * @return Pair 第一个元素表示是否成功,第二个元素表示提示信息 + */ + Pair merchantInnerRegister(String mobile); } diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java index 3954baf6..d9727c1c 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBaseServiceImpl.java @@ -3267,17 +3267,63 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl 第一个元素表示是否成功,第二个元素表示提示信息 + */ + @Override + public Pair merchantInnerRegister(String mobile) { + log.info("商家内部注册开始,手机号: {}", mobile); + + // 1. 参数校验 + if (StrUtil.isBlank(mobile)) { + log.warn("商家内部注册失败:手机号为空"); + return Pair.of(false, "手机号不能为空"); + } + + try { + // 2. 转换手机号格式(添加国家区号) + String convertedMobile = PhoneNumberUtils.convZhPhoneNumber(mobile); + + // 3. 检查手机号是否已注册为商家 + Integer isExists = accountUserBindConnectService.isMerchantExists(convertedMobile); + if (CommonConstant.Enable.equals(isExists)) { + log.warn("商家内部注册失败:手机号已注册,手机号: {}", convertedMobile); + return Pair.of(false, "该手机号已注册!"); + } + + // 4. 执行手机号绑定登录(注册商家账号) + CommonResult result = doMobileBindLogin(convertedMobile, CommonConstant.USER_TYPE_MCH, null, null); + + // 5. 检查注册结果 + if (result == null || result.getCode() != ResultCode.SUCCESS.getCode()) { + String errorMsg = result != null ? result.getMsg() : "注册结果为空"; + log.error("商家账号注册失败:{},手机号: {}", errorMsg, convertedMobile); + return Pair.of(false, "商家账号注册失败:" + errorMsg); + } + + log.info("商家内部注册成功,手机号: {}", convertedMobile); + return Pair.of(true, "商家注册成功"); + + } catch (Exception e) { + log.error("商家内部注册异常,手机号: {}", mobile, e); + return Pair.of(false, "商家注册失败:" + e.getMessage()); + } + } + + @Override public Map doAppConnectLogin(String bind_name, String code) { String id_prefix = ""; 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 5e327176..7906647b 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 @@ -6,7 +6,9 @@ import com.suisung.mall.common.modules.push.PushTemplate; import com.suisung.mall.common.pojo.output.TimelineOutput; import com.suisung.mall.common.pojo.res.ThirdApiRes; import io.swagger.annotations.ApiOperation; +import org.apache.ibatis.annotations.Param; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.data.util.Pair; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; @@ -313,4 +315,10 @@ public interface AccountService { */ @RequestMapping(value = "/admin/account/account-user-bind-connect/is-merchant-exists", method = RequestMethod.POST) Integer isMerchantExists(@RequestParam(name = "mobile") String mobile); + + /** + * 服务间注册商家账号,项目之间远程调用 + */ + @RequestMapping(value = "/merchant/inner-register", method = RequestMethod.POST) + Pair merchantInnerRegister(@Param("mobile") String mobile); } diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntry.java b/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntry.java index fafbcd3a..6e8958d7 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntry.java +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntry.java @@ -259,7 +259,7 @@ public class ShopMchEntry implements Serializable { private Integer has_bind_receiver; @ApiModelProperty(value = "父入驻id(总店入驻id)") - private Integer parent_id; + private Long parent_id; @ApiModelProperty(value = "该商家入驻记录是否有效,0:无效,1:有效") private Integer status; diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntryBranch.java b/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntryBranch.java index 4e65cd32..eedb62a8 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntryBranch.java +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/store/ShopMchEntryBranch.java @@ -44,14 +44,15 @@ public class ShopMchEntryBranch implements Serializable { @ApiModelProperty(value = "请求拉卡拉参数") private String lkl_req; - @ApiModelProperty(value = "拉卡拉响应参数") + @ApiModelProperty(value = "拉卡拉响应数据") private String lkl_reps; + @ApiModelProperty(value = "拉卡拉通知响应数据") + private String lkl_notify_reps; @ApiModelProperty(value = "该商家入驻记录是否有效,0:无效,1:有效") private Integer status; - @ApiModelProperty(value = "商家入驻记录的创建时间") private Date created_at; diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LklTkServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LklTkServiceImpl.java index 3c0cf7bc..876bcf39 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LklTkServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LklTkServiceImpl.java @@ -30,6 +30,7 @@ import com.suisung.mall.shop.lakala.service.LklBanksService; import com.suisung.mall.shop.lakala.service.LklLedgerReceiverService; import com.suisung.mall.shop.lakala.utils.LakalaUtil; import com.suisung.mall.shop.page.service.impl.OssServiceImpl; +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 org.slf4j.Logger; @@ -96,13 +97,13 @@ public class LklTkServiceImpl { @Resource private LklLedgerReceiverService lklLedgerReceiverService; -// @Lazy + // @Lazy // @Resource // private EsignContractService esignContractService; // -// @Lazy -// @Resource -// private EsignContractFillingFileService esignContractFillingFileService; + @Lazy + @Resource + private ShopMchEntryBranchService shopMchEntryBranchService; @Lazy @Resource @@ -828,7 +829,7 @@ public class LklTkServiceImpl { String merCupNo = dataJSON.getStr("externalCustomerNo"); //拉卡拉外部商户号 String merInnerNo = dataJSON.getStr("customerNo"); //拉卡拉内部商户号 String termNo = dataJSON.getStr("termNo"); //拉卡拉分配的业务终端号 - + String reviewRelatedId = dataJSON.getStr("reviewRelatedId"); //拉卡拉分配的业务终端号 logger.debug("解析通知数据完成 - 审核状态: {},外部商户号: {},内部商户号: {},终端号: {}", reviewPass, merCupNo, merInnerNo, termNo); @@ -836,7 +837,7 @@ public class LklTkServiceImpl { if (dataJSON.isEmpty() || StrUtil.isBlank(reviewPass) || StrUtil.isBlank(merCupNo) || - StrUtil.isBlank(merInnerNo) || + StrUtil.isBlank(reviewRelatedId) || StrUtil.isBlank(termNo)) { logger.warn("拉卡拉改进异步通知参数解析出错,数据: {}", data); return new JSONObject().set("code", "500").set("message", "参数解析出错"); @@ -864,27 +865,8 @@ public class LklTkServiceImpl { logger.info("拉卡拉增终审核通过,商户ID: {},开始更新商户信息", mchId); - // RMK 拉卡拉进价提交成功,边处理周边的数据,边等待审核异步通知 - - // 更新已进件成功的商户号和设备号 - logger.debug("开始更新商户拉卡拉审核状态"); - Boolean success = shopMchEntryService.updateMerchEntryLklAuditStatusByLklMerCupNo( - merInnerNo, merCupNo, termNo, CommonConstant.Enable, null, data); - - if (!Boolean.TRUE.equals(success)) { - logger.error("拉卡拉进件审核通过但更新商户号失败,商户ID: {}", mchId); - shopMchEntryService.updateMerchEntryApprovalByMchId(mchId, CommonConstant.MCH_APPR_STA_LKL_NOPASS, "进件时更新商户号失败"); - return new JSONObject().set("code", "500").set("message", "更新商户号失败"); - } - - logger.info("商户拉卡拉审核状态更新成功,商户ID: {}", mchId); - - shopMchEntryService.updateMerchEntryApprovalByMchId(shopMchEntry.getId(), CommonConstant.MCH_APPR_STA_LKL_PADDING, - "进件、申请分账业务、创建分账接收方均已成功,等待拉卡拉审核分账业务请求!"); - - //密集操作:进件审核通过之后,要下一步流程操作:申请分账业务、创建分账接收方 - logger.info("开始执行进件后续操作,商户ID: {},拉卡拉商户号: {}", mchId, merCupNo); - registrationMerchantAfterHook(mchId, merCupNo); + // RMK 拉卡拉增终成功, 创建分店入驻记录,创建商家账号、创建店铺和周边信息 + shopMchEntryBranchService.createMchEntryBranchStore(reviewRelatedId, termNo, data); logger.info("拉卡拉进件异步通知处理完成,商户ID: {}", mchId); return new JSONObject().set("code", "200").set("message", "处理成功"); @@ -917,10 +899,8 @@ public class LklTkServiceImpl { feeInfoDto.set("topFee", Convert.toDouble(wxFee)); feeInfoDto.set("fee", Convert.toDouble(wxFee)); feeInfoDto.set("feeType", "WECHAT"); - requestParams.set("fees", feeInfoDto); - String privateKey = LakalaUtil.getResourceFile(apiPriKeyPath, false, false); if (StrUtil.isBlank(privateKey)) { logger.error("获取拉卡拉私钥失败,apiPriKeyPath={}", apiPriKeyPath); @@ -1026,7 +1006,6 @@ public class LklTkServiceImpl { // 发送请求 - JSONObject response = RestTemplateHttpUtil.sendLklPostSrc( urlPath, header, requestBody, JSONObject.class); 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 index 8bd3b804..0e1cdb89 100644 --- 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 @@ -37,5 +37,15 @@ public interface ShopMchEntryBranchService { * @param mainStoreBranchReq 商户终端入驻申请门店信息 * @return 创建结果 */ - Pair createMchEntryBranchStore(MainStoreBranchReqDTO mainStoreBranchReq); + Pair applyMchEntryBranchStore(MainStoreBranchReqDTO mainStoreBranchReq); + + /** + * (重要)创建商户终端入驻申请门店信息、创建商户终端入驻申请门店员工信息、创建商户终端入驻申请门店权限信息、创建商户终端入驻申请门店入驻信息 + * + * @param reviewRelatedId 商户终端入驻申请ID + * @param termNo 终端号 + * @param lklNotifyResp 拉卡拉通知响应数据 + * @return 创建结果 + */ + Pair createMchEntryBranchStore(String reviewRelatedId, String termNo, String lklNotifyResp); } 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 42862d36..5f144589 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 @@ -19,6 +19,14 @@ import java.util.List; public interface ShopMchEntryService { + /** + * 新增或修改商家入驻申请信息 + * + * @param shopMchEntry + * @return + */ + Boolean saveOrUpdateShopMchEntry(ShopMchEntry shopMchEntry); + /** * 获取店铺的经营类目列表 * 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 index 0fd1a740..5778936c 100644 --- 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 @@ -5,6 +5,7 @@ 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.exception.ApiException; import com.suisung.mall.common.feignService.AccountService; import com.suisung.mall.common.modules.store.ShopMchEntry; import com.suisung.mall.common.modules.store.ShopMchEntryBranch; @@ -18,8 +19,10 @@ 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 io.seata.spring.annotation.GlobalTransactional; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; @@ -29,19 +32,23 @@ import java.util.Objects; @Slf4j @Service public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl implements ShopMchEntryBranchService { + @Lazy @Autowired private ShopStoreBaseService shopStoreBaseService; + @Lazy @Autowired private ShopMchEntryService shopMchEntryService; + @Lazy @Autowired private AccountService accountService; - + @Lazy @Autowired private ShopMchEntryMapper shopMchEntryMapper; + @Lazy @Autowired private LklTkServiceImpl lklTkService; @@ -126,13 +133,13 @@ public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl - 执行结果和提示信息 */ @Override - public Pair createMchEntryBranchStore(MainStoreBranchReqDTO mainStoreBranchReq) { + public Pair applyMchEntryBranchStore(MainStoreBranchReqDTO mainStoreBranchReq) { log.info("开始创建分店商户入驻申请,请求参数: {}", JSONUtil.toJsonStr(mainStoreBranchReq)); try { @@ -147,7 +154,7 @@ public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl entryQueryWrapper = new LambdaQueryWrapper<>(); entryQueryWrapper.eq(ShopMchEntry::getStore_id, mainStoreBranchReq.getParent_store_id()) @@ -159,27 +166,14 @@ public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl 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. 检查店铺名称是否已经存在 + // 3. 检查店铺名称是否已经存在 log.debug("检查店铺名称是否已存在: {}", mainStoreBranchReq.getStore_name()); LambdaQueryWrapper nameQueryWrapper = new LambdaQueryWrapper<>(); nameQueryWrapper.eq(ShopStoreBase::getStore_name, mainStoreBranchReq.getStore_name()); @@ -190,7 +184,7 @@ public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl branchQueryWrapper = new LambdaQueryWrapper<>(); branchQueryWrapper.eq(ShopMchEntryBranch::getLkl_mer_cup_no, mchEntry.getLkl_mer_inner_no()) @@ -213,35 +207,35 @@ public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl 0) { log.info("分店终端号已申请或申请中,拉卡拉内部商户号: {},已存在申请数量: {}", mchEntry.getLkl_mer_inner_no(), existingBranchCount); - return Pair.of(true, "分店终端号已申请或申请中,请等待审核"); + return Pair.of(false, "分店终端号已申请或申请中,请等待审核"); } log.debug("终端号检查通过"); - // 8. 调用拉卡拉接口创建商户终端 + // 6. 调用拉卡拉接口创建商户终端 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")); + String reviewRelatedId = lklResp.getStr("reviewRelatedId"); + log.info("拉卡拉接口调用成功,审核关联号: {}", reviewRelatedId); - // 9. 保存商户入驻申请信息 + // 7. 保存商户入驻申请信息 log.debug("开始保存商户入驻申请信息"); ShopMchEntryBranch shopMchEntryBranch = new ShopMchEntryBranch(); shopMchEntryBranch.setLkl_mer_cup_no(mchEntry.getLkl_mer_cup_no()); - shopMchEntryBranch.setReview_related_id(lklResp.getStr("reviewRelatedId")); + shopMchEntryBranch.setReview_related_id(reviewRelatedId); shopMchEntryBranch.setLkl_req(JSONUtil.toJsonStr(mainStoreBranchReq)); shopMchEntryBranch.setLkl_reps(JSONUtil.toJsonStr(lklResp)); Boolean isSuccess = saveShopMchEntryBranch(shopMchEntryBranch); if (!isSuccess) { - log.error("保存商户入驻申请信息失败,审核关联号: {}", lklResp.getStr("reviewRelatedId")); + log.error("保存商户入驻申请信息失败,审核关联号: {}", reviewRelatedId); return Pair.of(false, "分店提交申请失败"); } - log.info("商户入驻申请信息保存成功,审核关联号: {}", lklResp.getStr("reviewRelatedId")); - log.info("分店商户入驻申请创建成功,审核关联号: {}", lklResp.getStr("reviewRelatedId")); + return Pair.of(true, "分店提交申请成功"); } catch (Exception e) { @@ -250,5 +244,117 @@ public class ShopMchEntryBranchServiceImpl extends BaseServiceImpl createMchEntryBranchStore(String reviewRelatedId, String termNo, String lklNotifyResp) { + log.info("开始处理分店商户入驻,审核关联号: {}, 终端号: {}", reviewRelatedId, termNo); + + // 1. 参数校验 + if (StrUtil.isBlank(reviewRelatedId) || StrUtil.isBlank(termNo)) { + log.warn("分店商户入驻参数校验失败,reviewRelatedId: {}, termNo: {}", reviewRelatedId, termNo); + return Pair.of(false, "参数不能为空"); + } + + try { + // 2. 查询分店入驻申请记录 + ShopMchEntryBranch shopMchEntryBranch = getByReviewRelatedId(reviewRelatedId); + if (shopMchEntryBranch == null) { + log.warn("分店商户入驻申请不存在,审核关联号: {}", reviewRelatedId); + return Pair.of(false, "分店商户入驻申请不存在"); + } + + // 3. 更新分店入驻申请记录 + shopMchEntryBranch.setLkl_term_no(termNo); + shopMchEntryBranch.setStatus(CommonConstant.Enable); + shopMchEntryBranch.setLkl_notify_reps(lklNotifyResp); + if (!updateById(shopMchEntryBranch)) { + log.error("更新分店入驻申请记录失败,审核关联号: {}", reviewRelatedId); + throw new ApiException("更新分店入驻申请记录失败"); + } + log.debug("更新分店入驻申请记录成功,审核关联号: {}", reviewRelatedId); + + // 4. 解析分店入驻请求数据 + MainStoreBranchReqDTO mainStoreBranchReq = JSONUtil.toBean(shopMchEntryBranch.getLkl_req(), MainStoreBranchReqDTO.class); + if (mainStoreBranchReq == null) { + log.error("解析分店入驻请求数据失败,审核关联号: {}", reviewRelatedId); + throw new ApiException("解析分店入驻请求数据失败"); + } + + // 5. 获取主店入驻信息 + ShopMchEntry parentShopMchEntry = shopMchEntryService.getShopMerchEntryByMerCupNo(shopMchEntryBranch.getLkl_mer_cup_no()); + if (parentShopMchEntry == null) { + log.error("主店入驻信息不存在,拉卡拉商户号: {}", shopMchEntryBranch.getLkl_mer_cup_no()); + throw new ApiException("主店入驻信息不存在"); + } + + // 6. 构建分店入驻信息 + ShopMchEntry shopMchEntry = new ShopMchEntry(); + // 拷贝主店基础信息 + cn.hutool.core.bean.BeanUtil.copyProperties(parentShopMchEntry, shopMchEntry, "id"); // ID设置为null,以便插入新记录 + // 设置分店特有信息 + shopMchEntry.setLkl_term_no(termNo); + shopMchEntry.setLogin_mobile(mainStoreBranchReq.getLogin_mobile()); + shopMchEntry.setParent_id(parentShopMchEntry.getId()); // 设置主店ID为父ID + shopMchEntry.setStore_name(mainStoreBranchReq.getStore_name()); + shopMchEntry.setContact_name(mainStoreBranchReq.getContact_name()); + + if (StrUtil.isBlank(mainStoreBranchReq.getEmail())) { + shopMchEntry.setEmail(parentShopMchEntry.getLogin_mobile() + "@qq.com"); + } else { + shopMchEntry.setEmail(mainStoreBranchReq.getEmail()); + } + + shopMchEntry.setStore_address(mainStoreBranchReq.getStore_address()); + shopMchEntry.setStore_longitude(mainStoreBranchReq.getStore_longitude()); + shopMchEntry.setStore_latitude(mainStoreBranchReq.getStore_latitude()); + + if (StrUtil.isBlank(mainStoreBranchReq.getFront_facade_image())) { + shopMchEntry.setFront_facade_image(mainStoreBranchReq.getFront_facade_image()); + } + if (StrUtil.isBlank(mainStoreBranchReq.getEnvironment_image())) { + shopMchEntry.setEnvironment_image(mainStoreBranchReq.getEnvironment_image()); + } + shopMchEntry.setStatus(CommonConstant.Enable); + + // 7. 保存分店入驻记录 + if (!shopMchEntryService.saveOrUpdateShopMchEntry(shopMchEntry)) { + log.error("保存分店入驻记录失败,店铺名称: {}", shopMchEntry.getStore_name()); + throw new ApiException("保存分店入驻记录失败:" + shopMchEntry.getStore_name()); + } + log.info("保存分店入驻记录成功,分店ID: {}, 店铺名称: {}", shopMchEntry.getId(), shopMchEntry.getStore_name()); + + // 8. 创建分店店铺商家登录账号 + Pair registerResult = accountService.merchantInnerRegister(mainStoreBranchReq.getLogin_mobile()); + if (!registerResult.getFirst()) { + log.error("分店商户注册账号失败,手机号: {},错误信息: {}", mainStoreBranchReq.getLogin_mobile(), registerResult.getSecond()); + throw new ApiException("分店商户注册账号失败:" + registerResult.getSecond()); + } + log.debug("分店商户注册账号成功,手机号: {}", mainStoreBranchReq.getLogin_mobile()); + + // 9. 创建分店店铺信息,创建分店店铺周边信息(公司、员工、权限等) + Pair storeResult = shopStoreBaseService.covMerchEntryInfo2StoreInfo(shopMchEntry.getId(), true); + if (storeResult == null || storeResult.getFirst() <= 0) { + log.error("创建分店店铺信息失败,分店入驻ID: {},错误信息: {}", shopMchEntry.getId(), + storeResult != null ? storeResult.getSecond() : "返回结果为空"); + throw new ApiException("创建分店店铺信息失败: " + (storeResult != null ? storeResult.getSecond() : "未知错误")); + } + log.info("分店商户入驻处理成功,分店入驻ID: {}, 店铺ID: {}", shopMchEntry.getId(), storeResult.getFirst()); + + return Pair.of(true, "分店商户入驻处理成功"); + + } catch (Exception e) { + log.error("处理分店商户入驻时发生异常,审核关联号: {}, 终端号: {}", reviewRelatedId, termNo, e); + throw new ApiException("处理分店商户入驻时发生异常,审核关联号: " + reviewRelatedId + ", 终端号: " + termNo); + } + } + } 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 2fcd7641..f0b4737e 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 @@ -103,6 +103,57 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl 0) { + log.info("开始更新商家入驻申请信息,ID: {}, 店铺名称: {}, 手机号: {}", mchId, storeName, loginMobile); + } else { + log.info("开始新增商家入驻申请信息,店铺名称: {}, 手机号: {}", storeName, loginMobile); + } + + // 3. 执行保存或更新操作 + boolean result = saveOrUpdate(shopMchEntry); + + // 4. 记录操作结果 + if (result) { + if (mchId != null && mchId > 0) { + log.info("商家入驻申请信息更新成功,ID: {}", mchId); + } else { + log.info("商家入驻申请信息新增成功,新ID: {}", shopMchEntry.getId()); + } + } else { + log.error("商家入驻申请信息保存或更新失败,ID: {}, 店铺名称: {}, 手机号: {}", + mchId, storeName, loginMobile); + } + + return result; + + } catch (Exception e) { + log.error("商家入驻申请信息保存或更新异常,店铺名称: {}, 手机号: {}", + shopMchEntry.getStore_name(), shopMchEntry.getLogin_mobile(), e); + return false; + } + } + + /** * 获取店铺的经营类目列表 * @@ -1273,14 +1324,14 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("lkl_mer_cup_no", merCupNo).eq("status", CommonConstant.Enable).orderByAsc("id"); - List recordList = list(queryWrapper); - if (CollectionUtil.isEmpty(recordList)) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ShopMchEntry::getLkl_mer_cup_no, merCupNo).eq(ShopMchEntry::getStatus, CommonConstant.Enable).orderByAsc(ShopMchEntry::getId); + ShopMchEntry record = findOne(queryWrapper); + if (ObjectUtil.isEmpty(record)) { return null; } - return recordList.get(0); + return record; } @Override 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 1550b6a7..1efa829a 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 @@ -74,6 +74,7 @@ import com.suisung.mall.shop.wechat.service.WxQrCodeService; import io.seata.spring.annotation.GlobalTransactional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -3281,9 +3282,10 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl 0 ? areaNames[areaNames.length - 1] : storeArea.replace("/", ""); - sfExpressApiService.createSfExpressShop(mchId, storeId, shopMchEntry.getContact_name(), contact_mobile, shopMchEntry.getStore_longitude(), shopMchEntry.getStore_latitude()); -// } return Pair.of(storeId, "新增成功"); } catch (Exception e) {