加入会员合并同账号数据
This commit is contained in:
parent
51e1644624
commit
2a0fb6966d
|
|
@ -263,48 +263,43 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
||||||
// 当前用户信息
|
// 当前用户信息
|
||||||
UserInfo userInfo = userInfoService.getById(userId);
|
UserInfo userInfo = userInfoService.getById(userId);
|
||||||
|
|
||||||
// 查询系统添加的会员
|
|
||||||
UserInfo oriInfo = userInfoService.getOne(new QueryWrapper().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()));
|
|
||||||
if (oriInfo != null) {
|
|
||||||
BeanUtil.copyProperties(shopUserAddDTO, oriInfo);
|
|
||||||
if (StrUtil.isNotBlank(userInfo.getAlipayOpenId())) {
|
|
||||||
oriInfo.setAlipayOpenId(userInfo.getAlipayOpenId());
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotBlank(userInfo.getWechatOpenId())) {
|
|
||||||
oriInfo.setAlipayOpenId(userInfo.getWechatOpenId());
|
|
||||||
}
|
|
||||||
// 迁移订单
|
|
||||||
|
|
||||||
OrderInfo orderInfo = new OrderInfo();
|
|
||||||
orderInfo.setUserId(oriInfo.getId());
|
|
||||||
orderInfoService.update(orderInfo, new QueryWrapper().eq(OrderInfo::getUserId, userInfo.getId()));
|
|
||||||
|
|
||||||
// 删除多余用户信息
|
|
||||||
userInfoService.removeById(userId);
|
|
||||||
userInfo = oriInfo;
|
|
||||||
}else {
|
|
||||||
BeanUtil.copyProperties(shopUserAddDTO, userInfo);
|
|
||||||
}
|
|
||||||
userInfoService.updateById(userInfo);
|
|
||||||
|
|
||||||
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfo.getId()));
|
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfo.getId()));
|
||||||
if (shopUser == null) {
|
if (shopUser == null) {
|
||||||
shopUser = new ShopUser();
|
shopUser = new ShopUser();
|
||||||
|
shopUser.setUserId(userId);
|
||||||
shopUser.setShopId(shopId);
|
shopUser.setShopId(shopId);
|
||||||
shopUser.setUserId(userInfo.getId());
|
|
||||||
save(shopUser);
|
|
||||||
} else if (shopUser.getIsVip() == 1) {
|
|
||||||
throw new ApiNotPrintException("您已加入店铺会员");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询系统添加的会员
|
||||||
|
UserInfo oriInfo = userInfoService.getOne(new QueryWrapper().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()));
|
||||||
|
if (oriInfo != null) {
|
||||||
|
// 迁移订单
|
||||||
|
OrderInfo orderInfo = new OrderInfo();
|
||||||
|
orderInfo.setUserId(userId);
|
||||||
|
orderInfoService.update(orderInfo, new QueryWrapper().eq(OrderInfo::getUserId, oriInfo.getId()));
|
||||||
|
// 删除多余用户信息
|
||||||
|
userInfoService.removeById(oriInfo.getId());
|
||||||
|
BeanUtil.copyProperties(oriInfo, userInfo, "id", "alipayOpenId", "wechatOpenId");
|
||||||
|
|
||||||
|
ShopUser oldUserInfo = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, oriInfo.getId()));
|
||||||
|
removeById(oldUserInfo.getId());
|
||||||
|
BeanUtil.copyProperties(oldUserInfo, shopUser, "id", "userId");
|
||||||
|
}
|
||||||
|
|
||||||
BeanUtil.copyProperties(shopUserAddDTO, shopUser);
|
BeanUtil.copyProperties(shopUserAddDTO, shopUser);
|
||||||
shopUser.setIsVip(1);
|
BeanUtil.copyProperties(shopUserAddDTO, userInfo);
|
||||||
shopUser.setCode(generateCode(shopId));
|
userInfoService.updateById(userInfo);
|
||||||
shopUser.setJoinTime(DateUtil.date().toLocalDateTime());
|
|
||||||
shopUser.setUserId(null);
|
if (shopUser.getIsVip() != 1 && shopUser.getId() != null) {
|
||||||
shopUser.setShopId(null);
|
shopUser.setIsVip(1);
|
||||||
// 切换id
|
if (StrUtil.isBlank(shopUser.getCode())) {
|
||||||
StpKit.USER.reLogin(shopUser.getId());
|
shopUser.setCode(generateCode(shopId));
|
||||||
return true;
|
}
|
||||||
|
shopUser.setJoinTime(DateUtil.date().toLocalDateTime());
|
||||||
|
shopUser.setUserId(null);
|
||||||
|
shopUser.setShopId(null);
|
||||||
|
}
|
||||||
|
return saveOrUpdate(shopUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue