|
|
@@ -463,7 +463,9 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
if (subAccount == null) continue;
|
|
|
if (StringUtils.isNotEmpty(id) && (subAccount.getId() == null || !String.valueOf(subAccount.getId()).contains(id))) continue;
|
|
|
if (StringUtils.isNotEmpty(phone) && (subAccount.getPhone() == null || !subAccount.getPhone().contains(phone))) continue;
|
|
|
- if (status != null && !status.equals(subAccount.getStatus())) continue;
|
|
|
+ // 子账号行展示状态以 role.status 为准,筛选时与之一致
|
|
|
+ int rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
+ if (status != null && !status.equals(rowStatus)) continue;
|
|
|
filteredRoles.add(role);
|
|
|
}
|
|
|
filteredRoles.sort(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())));
|
|
|
@@ -496,7 +498,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
if (subAccount == null) continue;
|
|
|
StoreUserVo storeUserVo = new StoreUserVo();
|
|
|
BeanUtils.copyProperties(subAccount, storeUserVo);
|
|
|
- storeUserVo.setSwitchStatus(subAccount.getStatus() != null && subAccount.getStatus() == 0);
|
|
|
+ // 子账号端:以 store_platform_user_role.status 为准(0 启用 1 禁用)。既是主账号也是子账号时禁用只改 role,子账号行展示禁用;纯子账号被禁用/启用后此处同步展示
|
|
|
+ int rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
+ storeUserVo.setStatus(rowStatus);
|
|
|
+ storeUserVo.setSwitchStatus(rowStatus == 0);
|
|
|
storeUserVo.setPhone(subAccount.getPhone());
|
|
|
StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
if (mainAccount != null) {
|
|
|
@@ -530,7 +535,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
BeanUtils.copyProperties(storeUser, vo);
|
|
|
vo.setPassword(null);
|
|
|
vo.setPayPassword(null);
|
|
|
- vo.setSwitchStatus(storeUser.getStatus() != null && storeUser.getStatus() == 0);
|
|
|
+ // 主账号端:以 store_user.status 为准(0 启用 1 禁用)。既是主账号也是子账号时禁用只改 role,主账号仍启用;无子账号的主账号被禁用后此处展示禁用
|
|
|
+ int mainStatus = storeUser.getStatus() != null ? storeUser.getStatus() : 0;
|
|
|
+ vo.setStatus(mainStatus);
|
|
|
+ vo.setSwitchStatus(mainStatus == 0);
|
|
|
int childCount = countSubAccountUserIdsByStoreId(storeUser.getStoreId(), storeUser.getId());
|
|
|
vo.setChildAccountCount(childCount);
|
|
|
List<Integer> childUserIds = getSubAccountUserIdsByStoreId(storeUser.getStoreId(), storeUser.getId());
|
|
|
@@ -580,9 +588,8 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * web端切换商家端用户状态(主账号底下有子账号时禁止禁用;子账号无限制)
|
|
|
- * @param storeUserParam
|
|
|
- * @return
|
|
|
+ * web端切换商家端用户状态(主账号底下有子账号时禁止禁用;子账号无限制)。
|
|
|
+ * 若同一账号既是主账号又是子账号:禁用时只禁用子账号角色,主账号保持启用。
|
|
|
*/
|
|
|
@Override
|
|
|
public R<StoreUserVo> switchingStates(StoreUser storeUserParam) {
|
|
|
@@ -598,42 +605,34 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
throw new RuntimeException("请先删除主账号下的子账号后再禁用");
|
|
|
}
|
|
|
}
|
|
|
- // 禁用时删除 token
|
|
|
- baseRedisService.delete("store_" + storeUser.getPhone());
|
|
|
}
|
|
|
- // 根据当前状态切另一个状态(0 启用,1 禁用)
|
|
|
int newStatus = storeUser.getStatus() == 0 ? 1 : 0;
|
|
|
- if(storeUser.getAccountType() != null && storeUser.getAccountType() == 1){
|
|
|
- LambdaUpdateWrapper<StoreUser> queryWrapper = new LambdaUpdateWrapper<>();
|
|
|
- queryWrapper.eq(StoreUser::getId, storeUser.getId())
|
|
|
- .set(StoreUser::getStatus, newStatus);
|
|
|
- int updateCount = storeUserMapper.update(null, queryWrapper);
|
|
|
- if (updateCount <= 0) {
|
|
|
- throw new RuntimeException("更新失败");
|
|
|
- }
|
|
|
+ // 是否既是主账号又在 store_platform_user_role 中有记录(即也是子账号)
|
|
|
+ long roleCount = storePlatformUserRoleMapper.selectCount(new LambdaQueryWrapper<StorePlatformUserRole>().eq(StorePlatformUserRole::getUserId, storeUser.getId()));
|
|
|
+ boolean isBothMainAndSub = (storeUser.getAccountType() != null && storeUser.getAccountType() == 1) && roleCount > 0;
|
|
|
+ if (isBothMainAndSub && newStatus == 1) {
|
|
|
+ // 既是主账号也是子账号且本次为禁用:只禁用子账号角色,不更新 store_user,主账号保持启用
|
|
|
+ LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId()).set(StorePlatformUserRole::getStatus, 1);
|
|
|
+ storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
StoreUserVo vo = new StoreUserVo();
|
|
|
vo.setId(storeUser.getId());
|
|
|
- vo.setStatus(newStatus);
|
|
|
- vo.setSwitchStatus(newStatus == 0);
|
|
|
+ vo.setStatus(1);
|
|
|
+ vo.setSwitchStatus(false);
|
|
|
return R.data(vo);
|
|
|
}
|
|
|
+ if (newStatus == 1) {
|
|
|
+ baseRedisService.delete("store_" + storeUser.getPhone());
|
|
|
+ }
|
|
|
LambdaUpdateWrapper<StoreUser> queryWrapper = new LambdaUpdateWrapper<>();
|
|
|
- queryWrapper.eq(StoreUser::getId, storeUser.getId())
|
|
|
- .set(StoreUser::getStatus, newStatus);
|
|
|
+ queryWrapper.eq(StoreUser::getId, storeUser.getId()).set(StoreUser::getStatus, newStatus);
|
|
|
int updateCount = storeUserMapper.update(null, queryWrapper);
|
|
|
if (updateCount <= 0) {
|
|
|
throw new RuntimeException("更新失败");
|
|
|
}
|
|
|
-// StoreUserVo vo = new StoreUserVo();
|
|
|
-// vo.setId(storeUser.getId());
|
|
|
-// vo.setStatus(newStatus);
|
|
|
-// vo.setSwitchStatus(newStatus == 0);
|
|
|
- // 子账号启用/禁用时同步更新 store_platform_user_role 的 status(0 启用,1 禁用)
|
|
|
LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
- .set(StorePlatformUserRole::getStatus, newStatus);
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId()).set(StorePlatformUserRole::getStatus, newStatus);
|
|
|
storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
- // 返回更新后的状态,供前端及时展示
|
|
|
StoreUserVo vo = new StoreUserVo();
|
|
|
vo.setId(storeUser.getId());
|
|
|
vo.setStatus(newStatus);
|