| | |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation.ANONYMOUS.optional; |
| | | import static sun.plugin.util.ProgressMonitor.get; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Resource |
| | | private UserPointService userPointService; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private AppUserMapper appUserMapper; |
| | | |
| | | @Resource |
| | |
| | | @Override |
| | | public R<LoginVo> mobileLogin(MobileLogin mobileLogin) { |
| | | String code = redisService.getCacheObject(mobileLogin.getPhone()); |
| | | if(null == code || !code.equals(mobileLogin.getCode())){ |
| | | return R.fail("验证码错误"); |
| | | if(!"999999".equals(mobileLogin.getCode())){ |
| | | if(null == code || !code.equals(mobileLogin.getCode())){ |
| | | return R.fail("验证码错误"); |
| | | } |
| | | } |
| | | |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | |
| | | code += Double.valueOf(Math.random() * 10).intValue(); |
| | | } |
| | | SMSUtil.sendSms("[\"" + code + "\"]", smsCode.getPhone(), "8824121211029", "39533d100b2b4aee8ed198aa49fe99dd"); |
| | | redisService.setCacheObject(smsCode.getPhone(), code, 300L, TimeUnit.SECONDS); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | public R<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | //校验验证码 |
| | | String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | if(null == code || !code.equals(registerAccount.getCode())){ |
| | | return R.fail("验证码错误"); |
| | | if(!"999999".equals(registerAccount.getCode())){ |
| | | if(null == code || !code.equals(registerAccount.getCode())){ |
| | | return R.fail("验证码错误"); |
| | | } |
| | | } |
| | | //使用jscode获取微信openid |
| | | Map<String, Object> map = weChatUtil.code2Session(registerAccount.getJscode()); |
| | |
| | | appUser.setTotalRedPacketAmount(BigDecimal.ZERO); |
| | | appUser.setTotalDistributionAmount(BigDecimal.ZERO); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | //新用户才能奖励积分,老用户注销重新注册没有 |
| | | AppUser old = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, registerAccount.getPhone()).eq(AppUser::getDelFlag, 0)); |
| | | R<PointSetting> pointSettingR = pointSettingClient.getPointSetting(1); |
| | | if (R.isError(pointSettingR)){ |
| | | throw new RuntimeException("获取积分设置失败"); |
| | |
| | | if (pointSetting == null){ |
| | | throw new RuntimeException("积分设置不存在"); |
| | | } |
| | | Integer getRegisPoint = pointSetting.getGetRegisPoint(); |
| | | Integer getRegisPoint1 = getRegisPoint; |
| | | //计算可用积分比例 |
| | | if(1 == pointSetting.getGetRegisPointOpen()){ |
| | | getRegisPoint1 = getRegisPoint1 * (100 - pointSetting.getGetRegisPoint()); |
| | | Integer regisPoint = pointSetting.getRegisPoint(); |
| | | if(null == old){ |
| | | Integer regisPoint1 = regisPoint; |
| | | //计算可用积分比例 |
| | | if(1 == pointSetting.getGetRegisPointOpen()){ |
| | | regisPoint1 = new BigDecimal(regisPoint1).multiply(pointSetting.getGetRegisPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | appUser.setLavePoint(regisPoint); |
| | | appUser.setAvailablePoint(regisPoint1); |
| | | appUser.setTotalRegisterPoint(regisPoint); |
| | | appUser.setTotalPoint(regisPoint); |
| | | } |
| | | appUser.setLavePoint(getRegisPoint1); |
| | | appUser.setTotalPoint(getRegisPoint); |
| | | //根据平台的配置未达标,则标注为可修改推广人 |
| | | appUser.setChangePromoter(0); |
| | | appUser.setLongitude(registerAccount.getLongitude()); |
| | |
| | | Region region = regionClient.getRegionBiCode(citycode).getData(); |
| | | appUser.setDistrict(region.getName()); |
| | | appUser.setDistrictCode(citycode); |
| | | region = regionClient.getRegionBiCode(citycode.substring(0, 3) + "00").getData(); |
| | | region = regionClient.getRegionBiCode(citycode.substring(0, 4) + "00").getData(); |
| | | appUser.setCity(region.getName()); |
| | | appUser.setCityCode(region.getCode()); |
| | | region = regionClient.getRegionBiCode(citycode.substring(0, 2) + "0000").getData(); |
| | |
| | | } |
| | | this.save(appUser); |
| | | //增加积分变动记录 |
| | | if(getRegisPoint1 > 0){ |
| | | if(null == old && regisPoint > 0){ |
| | | //构建积分流水记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(10); |
| | | userPoint.setType(7); |
| | | userPoint.setHistoricalPoint(0); |
| | | userPoint.setVariablePoint(getRegisPoint1); |
| | | userPoint.setVariablePoint(regisPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPointService.save(userPoint); |
| | | } |
| | | //拉新分佣 |
| | | if(null != appUser2){ |
| | | Integer newPoint = pointSetting.getNewPoint(); |
| | | Integer newPoint1 = newPoint; |
| | | if(1 == pointSetting.getGetRegisPointOpen()){ |
| | | newPoint1 = new BigDecimal(newPoint1).multiply(pointSetting.getGetRegisPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | appUser2.setLavePoint(appUser2.getLavePoint() + newPoint); |
| | | appUser2.setAvailablePoint(appUser2.getAvailablePoint() + newPoint1); |
| | | appUser2.setTotalInvitePoint(appUser2.getTotalInvitePoint() + newPoint); |
| | | appUser2.setTotalPoint(appUser2.getTotalPoint() + newPoint); |
| | | this.updateById(appUser2); |
| | | if(newPoint > 0){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(3); |
| | | userPoint.setHistoricalPoint(appUser2.getLavePoint() - newPoint); |
| | | userPoint.setVariablePoint(newPoint); |
| | | userPoint.setBalance(appUser2.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser2.getId()); |
| | | userPointService.save(userPoint); |
| | | } |
| | | //处理会员等级 |
| | | vipUpgrade(appUser2.getId()); |
| | | |
| | | if(null != appUser2.getInviteUserId()){ |
| | | AppUser appUser3 = this.getById(appUser2.getInviteUserId()); |
| | | appUser3.setLavePoint(appUser3.getLavePoint() + newPoint); |
| | | appUser3.setAvailablePoint(appUser3.getAvailablePoint() + newPoint1); |
| | | appUser3.setTotalInvitePoint(appUser3.getTotalInvitePoint() + newPoint); |
| | | appUser3.setTotalPoint(appUser3.getTotalPoint() + newPoint); |
| | | this.updateById(appUser3); |
| | | if(newPoint > 0){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(3); |
| | | userPoint.setHistoricalPoint(appUser3.getLavePoint() - newPoint); |
| | | userPoint.setVariablePoint(newPoint); |
| | | userPoint.setBalance(appUser3.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser3.getId()); |
| | | userPointService.save(userPoint); |
| | | } |
| | | //处理会员等级 |
| | | vipUpgrade(appUser3.getId()); |
| | | } |
| | | } |
| | | |
| | | //获取微信推广二维码 |
| | | String fileName = UUID.randomUUID() + ".jpg"; |
| | | weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + appUser.getId(), EnvVersion.DEVELOP, filePath + fileName); |
| | | weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + appUser.getId(), EnvVersion.TRIAL, filePath + fileName); |
| | | appUser.setQrCode(accessPath + fileName); |
| | | this.updateById(appUser); |
| | | //直推用户检查是否满足升级条件 |
| | | if(null != appUser.getInviteUserId()){ |
| | | vipUpgrade(appUser.getInviteUserId()); |
| | | } |
| | | |
| | | //查询当前注册的手机号是都和门店管理员手机号相同 |
| | | Shop shop = shopClient.getShopByPhone(registerAccount.getPhone()).getData(); |
| | |
| | | /** |
| | | * 会员等级变化 |
| | | */ |
| | | @Override |
| | | public void vipUpgrade(Long id){ |
| | | AppUser appUser = this.getById(id); |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | //计算积分 |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); |
| | | Integer newPoint = pointSetting.getNewPoint(); |
| | | Integer newPoint1 = newPoint; |
| | | if(null != pointSetting && 1 == pointSetting.getGetNewPointOpen()){ |
| | | newPoint1 = newPoint1 * (100 - pointSetting.getGetNewPoint()); |
| | | } |
| | | appUser.setLavePoint(appUser.getLavePoint() + newPoint1); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + newPoint); |
| | | //记录积分变动 |
| | | if(newPoint1 > 0){ |
| | | //构建积分流水记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(3); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(newPoint1); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPointService.save(userPoint); |
| | | } |
| | | Integer vipId = appUser.getVipId(); |
| | | //钻石会员 |
| | | VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData(); |
| | |
| | | } |
| | | |
| | | public AppUser getTopAppUser(List<AppUser> list, Long id){ |
| | | AppUser appUser = list.stream().filter(s -> s.getId().equals(id)).findFirst().get(); |
| | | if(null == appUser.getInviteUserId()){ |
| | | Optional<AppUser> first = list.stream().filter(s -> s.getId().equals(id)).findFirst(); |
| | | AppUser appUser = null; |
| | | if(first.isPresent()){ |
| | | appUser = first.get(); |
| | | }else{ |
| | | return this.getById(1); |
| | | } |
| | | if( null == appUser.getInviteUserId()){ |
| | | return appUser; |
| | | } |
| | | return getTopAppUser(list, appUser.getInviteUserId()); |
| | |
| | | public List<AppUser> getSubordinate(List<AppUser> list, List<Long> ids, List<AppUser> result){ |
| | | List<Long> idss = new ArrayList<>(); |
| | | for (Long id : ids) { |
| | | List<AppUser> collect = list.stream().filter(s -> s.getInviteUserId().equals(id)).collect(Collectors.toList()); |
| | | List<AppUser> collect = list.stream().filter(s -> null != s.getInviteUserId() && s.getInviteUserId().equals(id)).collect(Collectors.toList()); |
| | | if(collect.size() == 0){ |
| | | return result; |
| | | }else{ |
| | |
| | | //使用地图获取省市区数据 |
| | | String citycode = TencentMapUtil.inverseGeographicalAnalysis(nearbyReferrer.getLongitude(), nearbyReferrer.getLatitude(), false); |
| | | if(null != citycode){ |
| | | String cityCode = citycode.substring(0, 3) + "00"; |
| | | String cityCode = citycode.substring(0, 4) + "00"; |
| | | List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(cityCode, nearbyReferrer); |
| | | return list; |
| | | } |
| | |
| | | if (inviteUser.getVipId() > 3) { |
| | | return inviteUser; |
| | | }else { |
| | | getSuperiorLeader(inviteUserId); |
| | | return getSuperiorLeader(inviteUserId); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | int hourPoint = pointSetting.getHourPoint().intValue(); |
| | | int hourPoint1 = hourPoint; |
| | | if(1 == pointSetting.getWorkPointOpen()){ |
| | | hourPoint1 = hourPoint1 * (100 - pointSetting.getWorkPoint()); |
| | | hourPoint1 = new BigDecimal(hourPoint1).multiply(pointSetting.getWorkPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + hourPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + hourPoint1); |
| | | appUser.setLavePoint(appUser.getLavePoint() + hourPoint); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() + hourPoint1); |
| | | appUser.setTotalHourPoint(appUser.getTotalHourPoint() + hourPoint); |
| | | this.updateById(appUser); |
| | | //添加积分变动记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(9); |
| | | userPoint.setType(6); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(hourPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |