|
@@ -537,7 +537,7 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
StoreUserVo storeUserVo = new StoreUserVo();
|
|
StoreUserVo storeUserVo = new StoreUserVo();
|
|
|
BeanUtils.copyProperties(subAccount, storeUserVo);
|
|
BeanUtils.copyProperties(subAccount, storeUserVo);
|
|
|
- // 分页:返回主账号id(id/parentAccountId)及主账号对应的子账号联系方式id(subAccountId),禁用/删除时用 subAccountId
|
|
|
|
|
|
|
+ // 分页:返回主账号id(id/parentAccountId)及子账号id(subAccountId),禁用/删除时用 subAccountId;状态以 store_platform_user_role.status 为准,启用/禁用后分页再查即展示最新状态
|
|
|
Integer mainId = mainAccount != null ? mainAccount.getId() : subAccount.getSubAccountId();
|
|
Integer mainId = mainAccount != null ? mainAccount.getId() : subAccount.getSubAccountId();
|
|
|
storeUserVo.setId(mainId != null ? mainId : subAccount.getId());
|
|
storeUserVo.setId(mainId != null ? mainId : subAccount.getId());
|
|
|
storeUserVo.setSubAccountId(subAccount.getId());
|
|
storeUserVo.setSubAccountId(subAccount.getId());
|
|
@@ -631,73 +631,114 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * web端切换商家端用户状态(禁用/启用)。
|
|
|
|
|
- * 禁用逻辑:1)主账号:有关联子账号则禁止禁用,无关联子账号可禁用;2)子账号:可禁用;
|
|
|
|
|
- * 若既是主账号也是子账号且本次为禁用:只禁用子账号角色(store_platform_user_role),不更新 store_user,主账号保持启用;子账号在列表按 status 展示为禁用。
|
|
|
|
|
|
|
+ * 启用/禁用(参考 deleteStoreAccountInfo 数据格式)。
|
|
|
|
|
+ * 要求1:子账号禁用时,若该账号既是主账号也是子账号,只禁用子账号角色,不禁用主账号;分页查询时页面展示最新状态(以 store_platform_user_role.status 为准)。
|
|
|
|
|
+ * 要求2:子账号可以禁用。
|
|
|
|
|
+ * 要求3:主账号底下有关联子账号时不能禁用。
|
|
|
|
|
+ * 状态:0 启用/正常,1 禁用;接口返回 newStatus 便于前端及分页展示最新状态。
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public R<StoreUserVo> switchingStates(StoreUserVo storeUserParam) {
|
|
public R<StoreUserVo> switchingStates(StoreUserVo storeUserParam) {
|
|
|
- // 默认传 0 表示执行禁用(状态改为 1),分页列表展示为禁用;传 1 表示执行启用(状态改为 0),分页列表展示为启用
|
|
|
|
|
|
|
+ if (storeUserParam == null) {
|
|
|
|
|
+ throw new RuntimeException("参数不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 当前状态 0=启用 1=禁用;点击禁用则 newStatus=1,点击启用则 newStatus=0
|
|
|
int currentStatus = storeUserParam.getStatus() != null ? storeUserParam.getStatus() : 0;
|
|
int currentStatus = storeUserParam.getStatus() != null ? storeUserParam.getStatus() : 0;
|
|
|
int newStatus = (currentStatus == 0) ? 1 : 0;
|
|
int newStatus = (currentStatus == 0) ? 1 : 0;
|
|
|
boolean isMainAccount = storeUserParam.getAccountType() != null && storeUserParam.getAccountType() == 1;
|
|
boolean isMainAccount = storeUserParam.getAccountType() != null && storeUserParam.getAccountType() == 1;
|
|
|
|
|
|
|
|
- if(storeUserParam.getAccountType()==2){
|
|
|
|
|
- StoreUser storeUser = storeUserMapper.selectById(storeUserParam.getSubAccountId());
|
|
|
|
|
|
|
+ // ---------- 子账号:要求2 子账号可以禁用 ----------
|
|
|
|
|
+ if (storeUserParam.getAccountType() != null && storeUserParam.getAccountType() == 2) {
|
|
|
|
|
+ Integer subAccountId = storeUserParam.getSubAccountId();
|
|
|
|
|
+ if (subAccountId == null) {
|
|
|
|
|
+ throw new RuntimeException("子账号 id 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ StoreUser storeUser = storeUserMapper.selectById(subAccountId);
|
|
|
if (storeUser == null) {
|
|
if (storeUser == null) {
|
|
|
throw new RuntimeException("用户不存在");
|
|
throw new RuntimeException("用户不存在");
|
|
|
}
|
|
}
|
|
|
- // 统计该用户在 platform 中未删除的角色数,用于判断是否「既是主账号也是子账号」
|
|
|
|
|
- long roleCount = storePlatformUserRoleMapper.selectCount(
|
|
|
|
|
- new LambdaQueryWrapper<StorePlatformUserRole>()
|
|
|
|
|
- .eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
|
|
- .eq(StorePlatformUserRole::getDeleteFlag, 0));
|
|
|
|
|
- log.info("员工状态的status roleCount={}",roleCount);
|
|
|
|
|
- boolean isBothMainAndSub = isMainAccount && roleCount > 0;
|
|
|
|
|
- // 1 既是主账号也是子账号且本次为禁用:只禁用子账号角色,不更新 store_user,主账号保持启用;子账号在列表上按 role.status 展示为禁用
|
|
|
|
|
- if (isBothMainAndSub) {
|
|
|
|
|
- LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
- roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
|
|
- .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
- .set(StorePlatformUserRole::getStatus, currentStatus);
|
|
|
|
|
- storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
- StoreUserVo vo = new StoreUserVo();
|
|
|
|
|
- vo.setId(storeUser.getId());
|
|
|
|
|
- vo.setStatus(currentStatus);
|
|
|
|
|
- vo.setSwitchStatus(newStatus == 0);
|
|
|
|
|
- return R.data(vo);
|
|
|
|
|
|
|
+ Integer mainAccountId = storeUserParam.getParentAccountId() != null ? storeUserParam.getParentAccountId() : storeUser.getSubAccountId();
|
|
|
|
|
+ Integer storeId = null;
|
|
|
|
|
+ if (mainAccountId != null) {
|
|
|
|
|
+ StoreUser mainAccount = storeUserMapper.selectById(mainAccountId);
|
|
|
|
|
+ if (mainAccount != null) storeId = mainAccount.getStoreId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 要求1:若该账号既是主账号也是子账号,只禁用子账号角色,不禁用主账号(同一手机号存在主账号则只更新 role)
|
|
|
|
|
+ boolean isBothMainAndSub = false;
|
|
|
|
|
+ if (storeUser.getPhone() != null && !storeUser.getPhone().isEmpty()) {
|
|
|
|
|
+ long mainSamePhone = storeUserMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<StoreUser>()
|
|
|
|
|
+ .eq(StoreUser::getPhone, storeUser.getPhone())
|
|
|
|
|
+ .eq(StoreUser::getAccountType, 1)
|
|
|
|
|
+ .eq(StoreUser::getDeleteFlag, 0));
|
|
|
|
|
+ isBothMainAndSub = mainSamePhone > 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ if (storeId != null) {
|
|
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getStoreId, storeId);
|
|
|
|
|
+ }
|
|
|
roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
.eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
.eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
- .set(StorePlatformUserRole::getStatus, currentStatus);
|
|
|
|
|
|
|
+ .set(StorePlatformUserRole::getStatus, newStatus);
|
|
|
storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if (isBothMainAndSub) {
|
|
|
|
|
+ // 既是主账号也是子账号:只改了 role,不更新 store_user,主账号保持启用;分页列表以 role.status 展示为最新状态
|
|
|
|
|
+ StoreUserVo vo = new StoreUserVo();
|
|
|
|
|
+ vo.setId(mainAccountId != null ? mainAccountId : storeUser.getId());
|
|
|
|
|
+ vo.setSubAccountId(storeUser.getId());
|
|
|
|
|
+ vo.setParentAccountId(mainAccountId);
|
|
|
|
|
+ vo.setStatus(newStatus);
|
|
|
|
|
+ vo.setSwitchStatus(newStatus == 0);
|
|
|
|
|
+ return R.data(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
baseRedisService.delete("store_" + storeUser.getPhone());
|
|
baseRedisService.delete("store_" + storeUser.getPhone());
|
|
|
LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
userUpdateWrapper.eq(StoreUser::getId, storeUser.getId()).set(StoreUser::getStatus, newStatus);
|
|
userUpdateWrapper.eq(StoreUser::getId, storeUser.getId()).set(StoreUser::getStatus, newStatus);
|
|
|
storeUserMapper.update(null, userUpdateWrapper);
|
|
storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
+ long enabledRoleCount = storePlatformUserRoleMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<StorePlatformUserRole>()
|
|
|
|
|
+ .eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
+ .eq(StorePlatformUserRole::getStatus, 0));
|
|
|
|
|
+ if (enabledRoleCount == 0) {
|
|
|
|
|
+ baseRedisService.delete("store_" + storeUser.getPhone());
|
|
|
|
|
+ userUpdateWrapper.eq(StoreUser::getId, storeUser.getId()).set(StoreUser::getStatus, newStatus);
|
|
|
|
|
+ storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
+ }
|
|
|
StoreUserVo vo = new StoreUserVo();
|
|
StoreUserVo vo = new StoreUserVo();
|
|
|
- vo.setId(storeUser.getId());
|
|
|
|
|
|
|
+ vo.setId(mainAccountId != null ? mainAccountId : storeUser.getId());
|
|
|
|
|
+ vo.setSubAccountId(storeUser.getId());
|
|
|
|
|
+ vo.setParentAccountId(mainAccountId);
|
|
|
vo.setStatus(newStatus);
|
|
vo.setStatus(newStatus);
|
|
|
vo.setSwitchStatus(newStatus == 0);
|
|
vo.setSwitchStatus(newStatus == 0);
|
|
|
return R.data(vo);
|
|
return R.data(vo);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 本次为禁用(newStatus==1):主账号有关联子账号则禁止禁用,无关联子账号可禁用
|
|
|
|
|
|
|
+ // ---------- 主账号:要求3 底下有关联子账号不能禁用 ----------
|
|
|
if (newStatus == 1 && isMainAccount) {
|
|
if (newStatus == 1 && isMainAccount) {
|
|
|
- List<StoreUser> subAccounts = getSubAccountsByMainAccountId(storeUserParam.getId());
|
|
|
|
|
- if (subAccounts != null && !subAccounts.isEmpty()) {
|
|
|
|
|
|
|
+ List<Integer> subAccountIds = storeUserMapper.selectSubAccountUserIdsByMainAccountIdWithRole(storeUserParam.getId());
|
|
|
|
|
+ if (subAccountIds != null && !subAccountIds.isEmpty()) {
|
|
|
throw new RuntimeException("请先删除主账号下的子账号后再禁用");
|
|
throw new RuntimeException("请先删除主账号下的子账号后再禁用");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // 启用/禁用:更新 store_user 的 status(禁用 0→1,启用 1→0),列表即时展示用返回的 vo
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 主账号启用/禁用:更新 store_user.status,禁用时删 token;返回 newStatus 便于分页展示最新状态
|
|
|
LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- userUpdateWrapper.eq(StoreUser::getId, storeUserParam.getId()).set(StoreUser::getStatus, currentStatus);
|
|
|
|
|
|
|
+ userUpdateWrapper.eq(StoreUser::getId, storeUserParam.getId()).set(StoreUser::getStatus, newStatus);
|
|
|
storeUserMapper.update(null, userUpdateWrapper);
|
|
storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
+ if (newStatus == 1) {
|
|
|
|
|
+ StoreUser u = storeUserMapper.selectById(storeUserParam.getId());
|
|
|
|
|
+ if (u != null && u.getPhone() != null) {
|
|
|
|
|
+ baseRedisService.delete("store_" + u.getPhone());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
StoreUserVo vo = new StoreUserVo();
|
|
StoreUserVo vo = new StoreUserVo();
|
|
|
vo.setId(storeUserParam.getId());
|
|
vo.setId(storeUserParam.getId());
|
|
|
- vo.setStatus(currentStatus);
|
|
|
|
|
|
|
+ vo.setStatus(newStatus);
|
|
|
vo.setSwitchStatus(newStatus == 0);
|
|
vo.setSwitchStatus(newStatus == 0);
|
|
|
return R.data(vo);
|
|
return R.data(vo);
|
|
|
}
|
|
}
|
|
@@ -1072,86 +1113,125 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 删除商家账号:主账号下有店铺或有关联子账号禁止删除;子账号则逻辑删除 store_platform_user_role,
|
|
|
|
|
- * 若主账号下仅关联一个子账号则同时逻辑删除 store_platform_user_role 和 store_user,若多个子账号则仅逻辑删除 store_platform_user_role。
|
|
|
|
|
|
|
+ * 删除商家账号。
|
|
|
|
|
+ * 主账号:有关联店铺禁止删除,有关联子账号禁止删除。
|
|
|
|
|
+ * 子账号:参照 removeRole 逻辑,按 userId/storeId 逻辑删除 store_platform_user_role;若该主账号下仅 1 个子账号且非主账号则同时逻辑删除 store_user 并清 token。
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public String deleteStoreAccountInfo(StoreUserVo storeUserVo) {
|
|
public String deleteStoreAccountInfo(StoreUserVo storeUserVo) {
|
|
|
- // 解析用户:优先用子账号联系方式 phone 查;未传 phone 时用 id/subAccountId 查 store_user,后端从库中拿到子账号联系方式(phone)
|
|
|
|
|
|
|
+ if (storeUserVo == null) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 参数不能为空");
|
|
|
|
|
+ return "删除失败";
|
|
|
|
|
+ }
|
|
|
|
|
+ // 1. 解析用户:子账号 id(userId) 优先用 subAccountId,其次 id;或通过 phone 查
|
|
|
|
|
+ Integer userId = null;
|
|
|
StoreUser storeUser = null;
|
|
StoreUser storeUser = null;
|
|
|
- if ((storeUserVo.getId() != null || storeUserVo.getSubAccountId() != null)) {
|
|
|
|
|
|
|
+ if (storeUserVo.getSubAccountId() != null || storeUserVo.getId() != null) {
|
|
|
Integer idParam = storeUserVo.getSubAccountId() != null ? storeUserVo.getSubAccountId() : storeUserVo.getId();
|
|
Integer idParam = storeUserVo.getSubAccountId() != null ? storeUserVo.getSubAccountId() : storeUserVo.getId();
|
|
|
storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
|
|
storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
|
|
|
.eq(StoreUser::getId, idParam).eq(StoreUser::getDeleteFlag, 0));
|
|
.eq(StoreUser::getId, idParam).eq(StoreUser::getDeleteFlag, 0));
|
|
|
if (storeUser != null) {
|
|
if (storeUser != null) {
|
|
|
- log.info("deleteStoreAccountInfo 通过 id 查到用户,后端拿到子账号联系方式: userId={}, phone={}", storeUser.getId(), storeUser.getPhone());
|
|
|
|
|
|
|
+ userId = storeUser.getId();
|
|
|
|
|
+ log.info("deleteStoreAccountInfo 通过子账号 id 查到用户: userId={}, phone={}", userId, storeUser.getPhone());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (storeUserVo == null) {
|
|
|
|
|
- log.warn("deleteStoreAccountInfo 用户不存在或已删除,请传子账号联系电话(phone)或用户id");
|
|
|
|
|
- return "删除失败";
|
|
|
|
|
- }
|
|
|
|
|
- // 通过 phone 再尝试解析用户(前端可能只传 phone)
|
|
|
|
|
if (storeUser == null && storeUserVo.getPhone() != null) {
|
|
if (storeUser == null && storeUserVo.getPhone() != null) {
|
|
|
storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
|
|
storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
|
|
|
.eq(StoreUser::getPhone, storeUserVo.getPhone()).eq(StoreUser::getDeleteFlag, 0));
|
|
.eq(StoreUser::getPhone, storeUserVo.getPhone()).eq(StoreUser::getDeleteFlag, 0));
|
|
|
|
|
+ if (storeUser != null) userId = storeUser.getId();
|
|
|
}
|
|
}
|
|
|
- if (storeUser == null) {
|
|
|
|
|
- log.warn("deleteStoreAccountInfo 用户不存在或已删除,请传子账号联系电话(phone)或用户id");
|
|
|
|
|
|
|
+ if (userId == null || storeUser == null) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 用户不存在或已删除,请传 userId(subAccountId/id)或 phone");
|
|
|
return "删除失败";
|
|
return "删除失败";
|
|
|
}
|
|
}
|
|
|
- Integer userId = storeUser.getId();
|
|
|
|
|
|
|
|
|
|
- // 删除主账号校验:该主账号下有店铺禁止删除、该主账号下有子账号禁止删除(主账号列表返回的 id 即主账号 id)
|
|
|
|
|
|
|
+ // 2. 主账号删除校验:有关联店铺禁止删除,有关联子账号禁止删除
|
|
|
if (storeUserVo.getAccountType() != null && storeUserVo.getAccountType() == 1) {
|
|
if (storeUserVo.getAccountType() != null && storeUserVo.getAccountType() == 1) {
|
|
|
- if (storeUser.getStoreId() != null) {
|
|
|
|
|
- log.error("该主账号下存在店铺,禁止删除");
|
|
|
|
|
|
|
+ Integer mainIdForCheck = storeUserVo.getId();
|
|
|
|
|
+ if (mainIdForCheck == null) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 删除主账号时 id 不能为空");
|
|
|
|
|
+ return "删除失败";
|
|
|
|
|
+ }
|
|
|
|
|
+ StoreUser mainUser = storeUserMapper.selectById(mainIdForCheck);
|
|
|
|
|
+ if (mainUser != null && mainUser.getStoreId() != null && mainUser.getStoreId() > 0) {
|
|
|
|
|
+ log.error("该主账号下存在关联店铺,禁止删除");
|
|
|
return "当前账号下存在店铺 禁止删除";
|
|
return "当前账号下存在店铺 禁止删除";
|
|
|
}
|
|
}
|
|
|
- Integer mainIdForCheck = storeUserVo.getId();
|
|
|
|
|
- if (mainIdForCheck != null) {
|
|
|
|
|
- List<StoreUser> subAccounts = getSubAccountsByMainAccountId(mainIdForCheck);
|
|
|
|
|
- if (subAccounts != null && !subAccounts.isEmpty()) {
|
|
|
|
|
- log.error("该主账号下存在关联子账号,禁止删除");
|
|
|
|
|
- return "当前账号下存在子账号禁止删除";
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<Integer> subAccountIds = storeUserMapper.selectSubAccountUserIdsByMainAccountIdWithRole(mainIdForCheck);
|
|
|
|
|
+ if (subAccountIds != null && !subAccountIds.isEmpty()) {
|
|
|
|
|
+ log.error("该主账号下存在关联子账号,禁止删除");
|
|
|
|
|
+ return "当前账号下存在子账号禁止删除";
|
|
|
}
|
|
}
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 主账号 id:优先用子账号 store_user.sub_account_id;无则用前端列表返回的 parentAccountId(与分页接口 records 字段一致)
|
|
|
|
|
|
|
+ // 3. 子账号删除:入参等价于 userId、主账号 id(mainAccountId)、主账号店铺 storeId;先查子账号 id 列表再判断
|
|
|
Integer mainAccountId = storeUser.getSubAccountId() != null ? storeUser.getSubAccountId() : storeUserVo.getParentAccountId();
|
|
Integer mainAccountId = storeUser.getSubAccountId() != null ? storeUser.getSubAccountId() : storeUserVo.getParentAccountId();
|
|
|
if (mainAccountId == null) {
|
|
if (mainAccountId == null) {
|
|
|
- log.warn("deleteStoreAccountInfo 无法确定主账号,请传 parentAccountId 或保证子账号 store_user.sub_account_id 有值");
|
|
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 无法确定主账号,请传 parentAccountId 或保证子账号 sub_account_id 有值");
|
|
|
return "删除失败";
|
|
return "删除失败";
|
|
|
}
|
|
}
|
|
|
- // 查询主账号下的子账号数量(按 store_user 统计:account_type=2 且 sub_account_id=主账号id)
|
|
|
|
|
- List<StoreUser> subAccountsUnderMain = getSubAccountsByMainAccountId(mainAccountId);
|
|
|
|
|
- int subAccountCount = subAccountsUnderMain != null ? subAccountsUnderMain.size() : 0;
|
|
|
|
|
- log.info("主账号下子账号数量: mainAccountId={}, subAccountCount={}", mainAccountId, subAccountCount);
|
|
|
|
|
-
|
|
|
|
|
- // 仅删除该主账号对应店铺下的角色:取主账号的 store_id,按 userId + storeId 逻辑删除 store_platform_user_role
|
|
|
|
|
- StoreUser mainAccount = storeUserMapper.selectById(mainAccountId);
|
|
|
|
|
- Integer storeId = mainAccount != null ? mainAccount.getStoreId() : null;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 3.1 查询主账号下的子账号 id 列表,根据子账号 id 判断数量及是否包含当前 userId
|
|
|
|
|
+ List<Integer> subAccountIds = storeUserMapper.selectSubAccountUserIdsByMainAccountIdWithRole(mainAccountId);
|
|
|
|
|
+ if (subAccountIds == null) subAccountIds = Collections.emptyList();
|
|
|
|
|
+ int subAccountCount = subAccountIds.size();
|
|
|
|
|
+ log.info("deleteStoreAccountInfo 主账号下子账号数量: userId={}, mainAccountId={}, storeId={}, subAccountCount={}", userId, mainAccountId, subAccountCount);
|
|
|
|
|
+ if (!subAccountIds.contains(userId)) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 当前用户不在主账号子账号列表中: userId={}, mainAccountId={}", userId, mainAccountId);
|
|
|
|
|
+ return "删除失败";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3.2 逻辑删除 store_platform_user_role(按 userId + storeId,delete_flag=1)
|
|
|
LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, userId).eq(StorePlatformUserRole::getDeleteFlag, 0);
|
|
|
|
|
- if (storeId != null) {
|
|
|
|
|
- roleUpdateWrapper.eq(StorePlatformUserRole::getStoreId, storeId);
|
|
|
|
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
+ .set(StorePlatformUserRole::getDeleteFlag, 1);
|
|
|
|
|
+ int roleUpdateResult = storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
+ if (roleUpdateResult <= 0) {
|
|
|
|
|
+ log.error("deleteStoreAccountInfo 逻辑删除 store_platform_user_role 失败: userId={}", userId);
|
|
|
|
|
+ return "删除失败";
|
|
|
}
|
|
}
|
|
|
- roleUpdateWrapper.set(StorePlatformUserRole::getDeleteFlag, 1);
|
|
|
|
|
- storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
|
|
|
|
|
- // 主账号下子账号唯一:逻辑删除 store_platform_user_role 和 store_user;不唯一:只逻辑删除 store_platform_user_role
|
|
|
|
|
|
|
+ // 3.3 根据子账号 id 查询用户信息及联系方式,删除 Redis token(key: store_手机号),参照 removeRole
|
|
|
|
|
+ StoreUser subUser = storeUserMapper.selectById(userId);
|
|
|
|
|
+ if (subUser != null && subUser.getPhone() != null) {
|
|
|
|
|
+ String tokenKey = "store_" + subUser.getPhone();
|
|
|
|
|
+ try {
|
|
|
|
|
+ String existingToken = baseRedisService.getString(tokenKey);
|
|
|
|
|
+ if (existingToken != null) {
|
|
|
|
|
+ baseRedisService.delete(tokenKey);
|
|
|
|
|
+ log.info("deleteStoreAccountInfo 清除用户 token 成功: userId={}, phone={}, tokenKey={}", userId, subUser.getPhone(), tokenKey);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 用户 token 不存在或已过期: userId={}, phone={}", userId, subUser.getPhone());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 清除 token 异常: userId={}, tokenKey={}", userId, tokenKey, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3.4 若该主账号下仅 1 个子账号,则进一步判断是否为主账号,再决定是否同时逻辑删除 store_user(参照 removeRole)
|
|
|
if (subAccountCount == 1) {
|
|
if (subAccountCount == 1) {
|
|
|
- LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
- userUpdateWrapper.eq(StoreUser::getId, userId)
|
|
|
|
|
- .eq(StoreUser::getDeleteFlag, 0)
|
|
|
|
|
- .set(StoreUser::getDeleteFlag, 1);
|
|
|
|
|
- storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
- log.info("主账号下子账号唯一,已逻辑删除 store_platform_user_role 和 store_user: userId={}", userId);
|
|
|
|
|
- String tokenKey = "store_" + storeUser.getPhone();
|
|
|
|
|
- baseRedisService.delete(tokenKey);
|
|
|
|
|
|
|
+ if (subUser != null) {
|
|
|
|
|
+ if (subUser.getStoreId() != null && subUser.getStoreId() > 0) {
|
|
|
|
|
+ log.info("deleteStoreAccountInfo 用户是主账号,不删除 store_user 记录: userId={}, storeId={}", userId, subUser.getStoreId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ userUpdateWrapper.eq(StoreUser::getId, userId)
|
|
|
|
|
+ .eq(StoreUser::getDeleteFlag, 0)
|
|
|
|
|
+ .set(StoreUser::getDeleteFlag, 1);
|
|
|
|
|
+ int userUpdateResult = storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
+ if (userUpdateResult > 0) {
|
|
|
|
|
+ log.info("deleteStoreAccountInfo 用户只有一个子账号且不是主账号,已同时逻辑删除 store_user 记录: userId={}", userId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 逻辑删除 store_user 记录失败或记录不存在: userId={}", userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 未找到用户信息: userId={}", userId);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- log.info("主账号下子账号数不为1,仅逻辑删除 store_platform_user_role,不删 store_user: mainAccountId={}, subAccountCount={}", mainAccountId, subAccountCount);
|
|
|
|
|
|
|
+ log.info("deleteStoreAccountInfo 用户有多个子账号(count={}),仅删除 store_platform_user_role 记录,不删除 store_user 记录: userId={}", subAccountCount, userId);
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|