| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.model.AppUserShop; |
| | | import com.ruoyi.account.mapper.AppUserMapper; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.service.AppUserService; |
| | | import com.ruoyi.account.service.AppUserShopService; |
| | | import com.ruoyi.account.util.weChat.WeChatUtil; |
| | | import com.ruoyi.account.vo.*; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.other.api.domain.Shop; |
| | | import com.ruoyi.other.api.feignClient.ShopClient; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private ShopClient shopClient; |
| | | |
| | | @Resource |
| | | private AppUserShopService appUserShopService; |
| | | |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 小程序一键登录 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult appletLogin(AppletLogin appletLogin) { |
| | | public R appletLogin(AppletLogin appletLogin) { |
| | | //使用jscode获取微信openid |
| | | Map<String, Object> map = weChatUtil.code2Session(appletLogin.getJscode()); |
| | | Integer errcode = Integer.valueOf(map.get("errcode").toString()); |
| | | if(0 != errcode){ |
| | | return AjaxResult.error(map.get("msg").toString()); |
| | | return R.fail(map.get("msg").toString()); |
| | | } |
| | | String openid = map.get("openid").toString(); |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | |
| | | if(null == appUser){ |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(2); |
| | | return AjaxResult.success(loginVo); |
| | | return R.ok(loginVo); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | if(2 == appUser.getStatus()){ |
| | | return AjaxResult.error("账户已被冻结,请联系管理员!"); |
| | | return R.fail("账户已被冻结,请联系管理员!"); |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | return AjaxResult.success(loginVo); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult<LoginVo> mobileLogin(MobileLogin mobileLogin) { |
| | | //校验验证码 |
| | | String code = redisService.getCacheObject(mobileLogin.getPhone()); |
| | | if(null == code || !code.equals(mobileLogin.getCode())){ |
| | | return AjaxResult.error("验证码错误"); |
| | | } |
| | | public R<LoginVo> mobileLogin(MobileLogin mobileLogin) { |
| | | //校验验证码 TODO 待完善 |
| | | // String code = redisService.getCacheObject(mobileLogin.getPhone()); |
| | | // if(null == code || !code.equals(mobileLogin.getCode())){ |
| | | // return R.fail("验证码错误"); |
| | | // } |
| | | |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | | 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); |
| | | return AjaxResult.success(loginVo); |
| | | return R.ok(loginVo); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | if(2 == appUser.getStatus()){ |
| | | return AjaxResult.error("账户已被冻结,请联系管理员!"); |
| | | return R.fail("账户已被冻结,请联系管理员!"); |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | return AjaxResult.success(loginVo); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult getSMSCode(SMSCode smsCode) { |
| | | public R getSMSCode(SMSCode smsCode) { |
| | | //校验验证码获取评率(1分钟5次) |
| | | String key = smsCode.getType() + "&" + smsCode.getPhone(); |
| | | Map<String, Object> cacheMap = redisService.getCacheMap(key); |
| | |
| | | Integer number = Integer.valueOf(cacheMap.get("number").toString()) + 1; |
| | | Long startTime = Long.valueOf(cacheMap.get("startTime").toString()); |
| | | if(number > 5 && (System.currentTimeMillis() - startTime) < 60000){ |
| | | return AjaxResult.error("获取验证码太频繁,请稍后重试!"); |
| | | return R.fail("获取验证码太频繁,请稍后重试!"); |
| | | } |
| | | if(number <= 5){ |
| | | cacheMap.put("number", number); |
| | |
| | | code += Double.valueOf(Math.random() * 10).intValue(); |
| | | } |
| | | //发送短信 todo 待对接短信 |
| | | return AjaxResult.success(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | public R<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | // TODO 待完善 |
| | | //校验验证码 |
| | | String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | if(null == code || !code.equals(registerAccount.getCode())){ |
| | | return AjaxResult.error("验证码错误"); |
| | | } |
| | | // String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | // if(null == code || !code.equals(registerAccount.getCode())){ |
| | | // return R.fail("验证码错误"); |
| | | // } |
| | | //使用jscode获取微信openid |
| | | Map<String, Object> map = weChatUtil.code2Session(registerAccount.getJscode()); |
| | | Integer errcode = Integer.valueOf(map.get("errcode").toString()); |
| | | if(0 != errcode){ |
| | | return AjaxResult.error(map.get("msg").toString()); |
| | | } |
| | | String openid = map.get("openid").toString(); |
| | | //查询用户是否注册 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getWxOpenid, openid).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null != appUser){ |
| | | return AjaxResult.error("此微信号已注册,请直接登录!"); |
| | | } |
| | | // Map<String, Object> map = weChatUtil.code2Session(registerAccount.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 appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getWxOpenid, openid).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | // if(null != appUser){ |
| | | // return R.fail("此微信号已注册,请直接登录!"); |
| | | // } |
| | | AppUser appUser = null; |
| | | AppUser appUser1 = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, registerAccount.getPhone()).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null != appUser1){ |
| | | return AjaxResult.error("手机号已注册,请直接登录!"); |
| | | return R.fail("手机号已注册,请直接登录!"); |
| | | } |
| | | if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | appUser.setName(registerAccount.getName()); |
| | | appUser.setPhone(registerAccount.getPhone()); |
| | | appUser.setWxOpenid(openid); |
| | | // appUser.setWxOpenid(openid); |
| | | //注册默认为普通会员 |
| | | appUser.setVipId(1); |
| | | appUser.setStatus(1); |
| | |
| | | AppUser appUser2 = this.getById(registerAccount.getPromoter()); |
| | | appUser.setInviteUserId(registerAccount.getPromoter()); |
| | | appUser.setShopId(appUser2.getShopId()); |
| | | appUser.setPartPoint(BigDecimal.ZERO); |
| | | appUser.setPartGrowPoint(BigDecimal.ZERO); |
| | | appUser.setShopPoint(BigDecimal.ZERO); |
| | | appUser.setSharePoint(BigDecimal.ZERO); |
| | | appUser.setPartPoint(0); |
| | | appUser.setPartGrowPoint(0); |
| | | appUser.setShopPoint(0); |
| | | appUser.setSharePoint(0); |
| | | appUser.setShopAmount(BigDecimal.ZERO); |
| | | appUser.setWithdrawableAmount(BigDecimal.ZERO); |
| | | appUser.setWithdrawnAmount(BigDecimal.ZERO); |
| | | appUser.setTotalRechargeAmount(BigDecimal.ZERO); |
| | | appUser.setTotalRedPacketAmount(BigDecimal.ZERO); |
| | | appUser.setTotalDistributionAmount(BigDecimal.ZERO); |
| | | appUser.setLavePoint(BigDecimal.ZERO); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setLavePoint(0); |
| | | //根据平台的配置未达标,则标注为可修改推广人 |
| | | appUser.setChangePromoter(0); |
| | | appUser.setLongitude(registerAccount.getLongitude()); |
| | | appUser.setLatitude(registerAccount.getLatitude()); |
| | | //调用地图获取省市区数据 |
| | | //调用地图获取省市区数据 TODO 待完善 |
| | | // appUser.setProvince(); |
| | | // appUser.setProvinceCode(); |
| | | // appUser.setCity(); |
| | |
| | | // appUser.setDistrict(); |
| | | // appUser.setDistrictCode(); |
| | | this.save(appUser); |
| | | |
| | | //查询当前注册的手机号是都和门店管理员手机号相同 |
| | | Shop shop = shopClient.getShopByPhone(registerAccount.getPhone()).getData(); |
| | | if(null != shop){ |
| | | //添加门店用户关系数据 |
| | | AppUserShop appUserShop = appUserShopService.getOne(new LambdaQueryWrapper<AppUserShop>().eq(AppUserShop::getAppUserId, appUser.getId()).eq(AppUserShop::getShopId, shop.getId())); |
| | | if(null == appUserShop){ |
| | | appUserShop = new AppUserShop(); |
| | | appUserShop.setShopId(shop.getId()); |
| | | appUserShop.setAppUserId(appUser.getId()); |
| | | appUserShopService.save(appUserShop); |
| | | //添加管理后台账号 |
| | | SysUser user = new SysUser(); |
| | | user.setDeptId(1L); |
| | | user.setUserName(appUser.getName()); |
| | | user.setNickName(appUser.getName()); |
| | | user.setPhonenumber(appUser.getPhone()); |
| | | user.setAvatar(appUser.getAvatar()); |
| | | user.setStatus("0"); |
| | | user.setDelFlag("0"); |
| | | user.setRoleType(2); |
| | | user.setObjectId(shop.getId()); |
| | | user.setAppUserId(appUser.getId()); |
| | | sysUserClient.saveShopUser(user); |
| | | } |
| | | } |
| | | |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | return AjaxResult.success(loginVo); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | public AppUser getTopAppUser(List<AppUser> list, Long id){ |
| | | AppUser appUser = list.stream().filter(s -> s.getInviteUserId().equals(id)).findFirst().get(); |
| | | AppUser appUser = list.stream().filter(s -> s.getId().equals(id)).findFirst().get(); |
| | | if(null == appUser.getInviteUserId()){ |
| | | return appUser; |
| | | } |
| | | return getTopAppUser(list, appUser.getId()); |
| | | return getTopAppUser(list, appUser.getInviteUserId()); |
| | | } |
| | | |
| | | |
| | |
| | | //使用地图获取省市区数据 |
| | | String longitude = nearbyReferrer.getLongitude(); |
| | | String latitude = nearbyReferrer.getLatitude(); |
| | | String cityCode = ""; |
| | | String cityCode = ""; // TODO 待完善 |
| | | List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(cityCode, nearbyReferrer); |
| | | return list; |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | |
| | | } |