puzhibing
2024-02-05 640ff18d2d7f4be02ddb7f8f75e899f05545eb98
cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
@@ -459,18 +459,14 @@
                return ResultUtil.error("请先开启定位", "");
            }
            Map<String, String> geocode = gdMapGeocodingUtil.geocode(addAppUserVo.getLon(), addAppUserVo.getLat());
            Integer num = 0;
            Integer activityId = null;
            if (null != geocode) {
                String province = geocode.get("province");
                String provinceCode = geocode.get("provinceCode");
                String city = geocode.get("city");
                String cityCode = geocode.get("cityCode");
                // 根据所在市code 查询是否有介绍有礼活动
                IntroduceRewards res = introduceRewardsClient.getGiftList(cityCode);
                List<IntroduceRewards> res = introduceRewardsClient.getGiftList(cityCode);
                if (res != null) {
                    num = res.getGiveClass();
                    activityId = res.getId();
                    for (IntroduceRewards re : res) {
                        Integer num = re.getGiveClass();
                        Integer activityId = re.getId();
                    if (ToolUtil.isNotEmpty(addAppUserVo.getInvitePhone())) {
                        List<TAppUser> tAppUsers = this.baseMapper.selectList(new LambdaQueryWrapper<TAppUser>()
                                .eq(TAppUser::getPhone, addAppUserVo.getInvitePhone()));
@@ -496,6 +492,7 @@
                        tAppGift.setActivityId(activityId);
                        tAppGift.setInsertTime(new Date());
                        appGiftService.save(tAppGift);
                        }
                    }
                }
            }
@@ -1175,6 +1172,7 @@
        if (tAppUser.getState() == 2) {
            return ResultUtil.error("您的账号已被冻结");
        }
        boolean newUser = false;
        List<TAppUser> tAppUsers1 = appUserMapper.selectList(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, dto.getPhone()).eq(TAppUser::getState, 1));
        if (tAppUsers1.size() > 0) {
            TAppUser tAppUser1 = tAppUsers1.get(0);
@@ -1192,56 +1190,49 @@
            appUserMapper.updateById(tAppUser);
            token = getToken(tAppUser);
            map.put("token", token);
            newUser = true;
        }
//        tAppUser.setPhone(dto.getPhone());
        if (ToolUtil.isNotEmpty(dto.getInvitePhone())) {
        if (newUser && ToolUtil.isNotEmpty(dto.getInvitePhone())) {
            if (ToolUtil.isEmpty(dto.getLat()) || ToolUtil.isEmpty(dto.getLon())) {
                return ResultUtil.error("请先开启定位");
            }
            TAppUser tAppUser1 = appUserMapper.selectOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, dto.getInvitePhone()).eq(TAppUser::getState, 1));
            if (tAppUser1 != null) {
            TAppUser tAppUser1 = appUserMapper.selectOne(new LambdaQueryWrapper<TAppUser>()
                    .eq(TAppUser::getPhone, dto.getInvitePhone()).eq(TAppUser::getState, 1));
            if(null == tAppUser1){
                return ResultUtil.error("邀请人还未注册账号");
            }
                Map<String, String> geocode = null;
                try {
                    geocode = gdMapGeocodingUtil.geocode(dto.getLon(), dto.getLat());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Integer num = 0;
                if (null != geocode) {
                    String province = geocode.get("province");
                    String provinceCode = geocode.get("provinceCode");
                    String city = geocode.get("city");
                    String cityCode = geocode.get("cityCode");
                    IntroduceRewards giftList = introduceRewardsClient.getGiftList(cityCode);
                    num = giftList.getGiveClass();
                }
                Integer userId = null;
                if (ToolUtil.isNotEmpty(dto.getInvitePhone())) {
                    List<TAppUser> tAppUsers = this.baseMapper.selectList(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, dto.getInvitePhone()));
                    if (tAppUsers.size() > 0) {
                        userId = tAppUsers.get(0).getId();
                    }
                }
                if (userId != null) {
                    TAppGift one = appGiftService.getOne(new LambdaQueryWrapper<TAppGift>().eq(TAppGift::getUserId, userId));
                    if (one != null) {
                        one.setNum(one.getNum() + num);
                        appGiftService.updateById(one);
                    } else {
                // 根据所在市code 查询是否有介绍有礼活动
                List<IntroduceRewards> res = introduceRewardsClient.getGiftList(cityCode);
                if (res != null) {
                    for (IntroduceRewards re : res) {
                        Integer num = re.getGiveClass();
                        Integer activityId = re.getId();
                        if (num != 0) {
                        TAppGift tAppGift = new TAppGift();
                        tAppGift.setUserId(userId);
                            tAppGift.setUserName(tAppUser1.getName());
                            tAppGift.setUserPhone(tAppUser1.getPhone());
                            tAppGift.setUserId(tAppUser1.getId());
                        tAppGift.setNum(num);
                            tAppGift.setShareUserId(tAppUser.getId());
                            tAppGift.setShareUserName(tAppUser.getPhone());
                            tAppGift.setShareUserPhone(tAppUser.getPhone());
                            tAppGift.setActivityId(activityId);
                            tAppGift.setInsertTime(new Date());
                        appGiftService.save(tAppGift);
                    }
                }
            }
        }
//        appUserMapper.updateById(tAppUser);
        }
        return ResultUtil.success(map);
    }