授权手机号 修改手机号部分

This commit is contained in:
wangw 2024-07-17 14:58:47 +08:00
parent d784ba8c27
commit faf33855d6
2 changed files with 26 additions and 14 deletions

View File

@ -208,6 +208,7 @@ public class LoginContoller {
return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString());
} }
} catch (Exception e){ } catch (Exception e){
// e.printStackTrace();
log.info("登录传参 获取手机号失败 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,data); log.info("登录传参 获取手机号失败 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,data);
} }
return Result.fail("获取手机号失败,请重试!"); return Result.fail("获取手机号失败,请重试!");

View File

@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisCst;
@ -416,23 +417,33 @@ public class LoginService {
@Transactional @Transactional
public Result upPhone(String openId, String phone, String shopId) { public Result upPhone(String openId, String phone, String shopId) {
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId); TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
boolean isup = false;
if(StringUtils.isNotBlank(userInfo.getTelephone())){
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(userInfo.getTelephone());
for (TbShopUser tbShopUser : tbShopUsers) {
if (tbShopUser.getShopId().equals(shopId)) {
isup = true;
}
tbShopUser.setTelephone(phone);
tbShopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKey(tbShopUser);
}
if(!isup){
registerShopUser(userInfo,shopId);
}
}else {
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), shopId);
if (shopUser != null) {
shopUser.setTelephone(phone);
shopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKey(shopUser);
}else {
registerShopUser(userInfo,shopId);
}
}
userInfo.setTelephone(phone); userInfo.setTelephone(phone);
userInfo.setUpdatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis());
tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); tbUserInfoMapper.updateByPrimaryKeySelective(userInfo);
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), shopId);
if (shopUser != null) if (!shopUser.getIsVip().equals(1) && shopUser.getAmount().equals(BigDecimal.ZERO)) {
tbShopUserMapper.deleteByPrimaryKey(shopUser.getId());
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(phone);
if (!CollectionUtils.isEmpty(tbShopUsers)) {
for (TbShopUser tbShopUser : tbShopUsers) {
tbShopUser.setUserId(userInfo.getId() + "");
tbShopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKey(tbShopUser);
}
return Result.success(CodeEnum.SUCCESS);
}
}
registerShopUser(userInfo,shopId);
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }