diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 2961e4b..cbdcdb2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -208,6 +208,7 @@ public class LoginContoller { return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); } } catch (Exception e){ +// e.printStackTrace(); log.info("登录传参 获取手机号失败 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,data); } return Result.fail("获取手机号失败,请重试!"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index f4e4ab3..dee9506 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.redis.RedisCst; @@ -416,23 +417,33 @@ public class LoginService { @Transactional public Result upPhone(String openId, String phone, String shopId) { TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId); + boolean isup = false; + if(StringUtils.isNotBlank(userInfo.getTelephone())){ + List 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.setUpdatedAt(System.currentTimeMillis()); 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 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); }