| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.model.*; |
| | | import com.ruoyi.account.dto.ApplyForAdmissionDTO; |
| | | import com.ruoyi.account.mapper.AppUserMapper; |
| | | import com.ruoyi.account.service.*; |
| | | import com.ruoyi.account.util.GeodesyUtil; |
| | |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | @Resource |
| | | private OrderClient orderClient; |
| | | |
| | | private static final String DEFAULT_AVATAR_URL = "http://qijishenghuiyuan.obs.cn-southwest-2.myhuaweicloud.com/admin/aedfbbb41280471f8d9fa7905298b65f.png"; |
| | | |
| | | |
| | | /** |
| | | * 小程序一键登录 |
| | |
| | | } |
| | | String openid = map.get("openid").toString(); |
| | | String sessionKey = map.get("sessionKey").toString(); |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | | //查询用户是否注册,没有注册则注册 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getWxOpenid, openid).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | //注册 |
| | | //获取手机号 |
| | | String decrypt = WXCore.decrypt(appletLogin.getEncryptedData_phone(), sessionKey, appletLogin.getIv_phone()); |
| | | if (StringUtils.isEmpty(decrypt)) { |
| | | return R.fail("获取手机信息失败"); |
| | | } |
| | | JSONObject phone = JSON.parseObject(decrypt); |
| | | String purePhoneNumber = phone.getString("purePhoneNumber"); |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(2); |
| | | loginVo.setPhone(purePhoneNumber); |
| | | return R.ok(loginVo); |
| | | String purePhoneNumber = phone.getString("phoneNumber"); |
| | | //新用户默认信息 |
| | | appUser.setName(purePhoneNumber.substring(0, 3) + "****" + purePhoneNumber.substring(7)); |
| | | appUser.setPhone(purePhoneNumber); |
| | | appUser.setAvatar( DEFAULT_AVATAR_URL); |
| | | appUser.setWxOpenid(openid); |
| | | appUser.setStatus(1); |
| | | appUser.setDelFlag(false); |
| | | this.save(appUser); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | if(2 == appUser.getStatus()){ |
| | | return R.fail("账户已被冻结,请联系管理员!"); |
| | | } |
| | | |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | | loginVo.setFirstTime(false); |
| | | loginVo.setPhone(appUser.getPhone()); |
| | | //构建token |
| | | LoginUser loginUser = new LoginUser(); |
| | |
| | | } |
| | | } |
| | | |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | | //查询用户是否注册,没有注册则系统注册 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, mobileLogin.getPhone()) |
| | | .ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null == appUser){ |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(2); |
| | | loginVo.setPhone(mobileLogin.getPhone()); |
| | | return R.ok(loginVo); |
| | | appUser=new AppUser(); |
| | | //注册 |
| | | //使用jscode获取微信openid |
| | | Map<String, Object> map = weChatUtil.code2Session(mobileLogin.getJscode()); |
| | | Integer errcode = Integer.valueOf(map.get("errcode").toString()); |
| | | if(0 != errcode){ |
| | | return R.fail(map.get("msg").toString()); |
| | | } |
| | | String openid = map.get("openid").toString(); |
| | | //设置默认信息 |
| | | appUser.setName(mobileLogin.getPhone().substring(0, 3) + "****" + mobileLogin.getPhone().substring(7)); |
| | | appUser.setPhone(mobileLogin.getPhone()); |
| | | appUser.setAvatar( DEFAULT_AVATAR_URL); |
| | | appUser.setWxOpenid(openid); |
| | | appUser.setStatus(1); |
| | | appUser.setDelFlag(false); |
| | | //调用地图获取省市区数据 |
| | | String citycode = TencentMapUtil.inverseGeographicalAnalysis(mobileLogin.getLongitude(), mobileLogin.getLatitude(), false); |
| | | if(null != citycode){ |
| | | Region region = regionClient.getRegionBiCode(citycode).getData(); |
| | | appUser.setDistrict(region.getName()); |
| | | appUser.setDistrictCode(citycode); |
| | | 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(); |
| | | appUser.setProvince(region.getName()); |
| | | appUser.setProvinceCode(region.getCode()); |
| | | } |
| | | |
| | | this.save(appUser); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | if(2 == appUser.getStatus()){ |
| | |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | | loginVo.setFirstTime(false); |
| | | loginVo.setPhone(appUser.getPhone()); |
| | | //构建token |
| | | LoginUser loginUser = new LoginUser(); |
| | |
| | | |
| | | /** |
| | | * 注册账号 |
| | | * @param registerAccount |
| | | * @return |
| | | */ |
| | | /* |
| | | @Override |
| | | public R<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | //校验验证码 |
| | |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | | */ |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<AppUser> getUserAncestorList(Long id, List<AppUser> list) { |
| | | if (list == null) { |
| | | list = new ArrayList<>(); |
| | | } |
| | | |
| | | Set<Long> visitedIds = new HashSet<>(); |
| | | Long currentId = id; |
| | | |
| | | while (currentId != null && !visitedIds.contains(currentId)) { |
| | | AppUser appUser = getById(currentId); |
| | | if (appUser == null) { |
| | | break; // 如果用户不存在,终止循环 |
| | | } |
| | | |
| | | Long inviteUserId = appUser.getInviteUserId(); |
| | | if (inviteUserId != null) { |
| | | AppUser invitedUser = getById(inviteUserId); |
| | | if (invitedUser != null) { |
| | | list.add(invitedUser); |
| | | visitedIds.add(currentId); |
| | | currentId = inviteUserId; |
| | | } else { |
| | | break; // 如果邀请用户不存在,终止循环 |
| | | } |
| | | } else { |
| | | break; // 如果没有邀请用户,终止循环 |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public AppUser getSuperiorLeader(Long id) { |
| | | AppUser appUser = getById(id); |
| | | Long inviteUserId = appUser.getInviteUserId(); |
| | | AppUser inviteUser = getById(inviteUserId); |
| | | if (inviteUser == null){ |
| | | return null; |
| | | } |
| | | if (inviteUser.getVipId() > 3) { |
| | | return inviteUser; |
| | | }else { |
| | | return getSuperiorLeader(inviteUserId); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 定时解绑推广人 |
| | | */ |
| | | @Override |
| | | public void unbindThePromoter() { |
| | | //注册X天后没有升级成黄金会员则自动解绑推广人 |
| | | //解绑推广人 |
| | | Set<Long> unbind_promoter = redisTemplate.opsForZSet().rangeByScore("unbind_promoter", 0, LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)); |
| | | if(unbind_promoter.size() > 0){ |
| | | List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getVipId, 1).eq(AppUser::getDelFlag, 0).isNotNull(AppUser::getInviteUserId) |
| | | .eq(AppUser::getStatus, 1).in(AppUser::getId, unbind_promoter)); |
| | | for (AppUser appUser : list) { |
| | | UpdateWrapper<AppUser> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.set("invite_user_id", null).set("shop_id", null).eq("id", appUser.getId()); |
| | | this.update(updateWrapper); |
| | | } |
| | | redisTemplate.opsForZSet().remove("unbind_promoter", unbind_promoter.toArray()); |
| | | } |
| | | //可更换推广人 |
| | | Set<Long> replaceable = redisTemplate.opsForZSet().rangeByScore("replaceable", 0, LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)); |
| | | if(replaceable.size() > 0){ |
| | | List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getChangePromoter, 0) |
| | | .eq(AppUser::getStatus, 1).in(AppUser::getId, replaceable)); |
| | | for (AppUser appUser : list) { |
| | | Long data = orderClient.getOrderCountByAppUserId(appUser.getId()).getData(); |
| | | if(data == 0L){ |
| | | appUser.setChangePromoter(1); |
| | | this.updateById(appUser); |
| | | } |
| | | } |
| | | redisTemplate.opsForZSet().remove("replaceable", replaceable.toArray()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 在线记录操作,用于赠送积分 |
| | | */ |
| | | @Override |
| | | public void onlineRecord() { |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | Object cacheObject = redisService.getCacheObject("ONLINE_" + userid); |
| | | if(null == cacheObject){ |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", System.currentTimeMillis()); |
| | | jsonObject.put("online", 0); |
| | | redisService.setCacheObject("ONLINE_" + userid, jsonObject, 1L, TimeUnit.HOURS); |
| | | }else{ |
| | | JSONObject jsonObject = (JSONObject) cacheObject; |
| | | long time = System.currentTimeMillis() - jsonObject.getInteger("time"); |
| | | Integer online = jsonObject.getInteger("online"); |
| | | online++; |
| | | //时间满足1小时,并且次数记录满足6次(10分钟记录一次) |
| | | if(time >= 3600000 && 6 <= online){ |
| | | jsonObject.put("time", System.currentTimeMillis()); |
| | | jsonObject.put("online", 0); |
| | | redisService.setCacheObject("ONLINE_" + userid, jsonObject, 1L, TimeUnit.HOURS); |
| | | AppUser appUser = this.getById(userid); |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); |
| | | if(null != pointSetting){ |
| | | int hourPoint = pointSetting.getHourPoint().intValue(); |
| | | int hourPoint1 = 0; |
| | | if(1 == pointSetting.getWorkPointOpen()){ |
| | | hourPoint1 = new BigDecimal(hourPoint).multiply(pointSetting.getWorkPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | //添加积分变动记录 |
| | | if(hourPoint > 0){ |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + hourPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + hourPoint); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() + hourPoint1); |
| | | appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + hourPoint1); |
| | | if(null != pointSetting && 1 == pointSetting.getWorkPointGift()){ |
| | | appUser.setTransferablePoint(appUser.getTransferablePoint() + hourPoint1); |
| | | } |
| | | appUser.setTotalHourPoint(appUser.getTotalHourPoint() + hourPoint); |
| | | this.updateById(appUser); |
| | | |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(6); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(hourPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPointService.save(userPoint); |
| | | } |
| | | } |
| | | }else{ |
| | | jsonObject.put("online", online); |
| | | redisService.setCacheObject("ONLINE_" + userid, jsonObject, 1L, TimeUnit.HOURS); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public IPage<AppUser> getAppuserPage(Integer pageNum, Integer pageSize, AppUser appUser, Integer shopId, Set<Long> userId) { |
| | |
| | | public List<AppUser> getAppUserByPhoneNoFilter(String phone) { |
| | | return this.baseMapper.getAppUserByPhoneNoFilter(phone); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 小程序-个人中心 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AppUser index() { |
| | | Long userId = tokenService.getLoginUserApplet().getUserid(); |
| | | //当前用户信息 |
| | | AppUser user = this.getById(userId); |
| | | //查询门店,如果门店被冻结 |
| | | List<Shop> shopList = shopClient.getShopByUserId(userId).getData(); |
| | | user.setShopStatus(0);//未拥有门店 |
| | | if (shopList != null && !shopList.isEmpty()) { |
| | | user.setShopStatus(2);//门店都被冻结 |
| | | for (Shop shop : shopList) { |
| | | if (shop.getStatus()==1) { |
| | | user.setShopStatus(1);//门店状态 |
| | | } |
| | | if(null==user.getShopIds()){ |
| | | Set<Integer> integers = new HashSet<>(); |
| | | user.setShopIds(integers); |
| | | } |
| | | user.getShopIds().add(shop.getId()); |
| | | user.setShopIds(user.getShopIds()); |
| | | |
| | | } |
| | | } |
| | | return user; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<UserPointStatisticsVO> getUserPointPageList(String name, Integer pageCurr, Integer pageSize) { |
| | | PageInfo<UserPointStatisticsVO> pageInfo=new PageInfo<>(pageCurr,pageSize); |
| | | List<UserPointStatisticsVO> list=baseMapper.getUserPointPageList(pageInfo, name); |
| | | list.forEach(x->{ |
| | | x.setIdStr(String.valueOf(x.getId())); |
| | | }); |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | } |