| | |
| | | import com.ruoyi.account.util.weChat.WeChatUtil; |
| | | import com.ruoyi.account.vo.*; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.BaseTable; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | 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; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public AjaxResult<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | return null; |
| | | //校验验证码 |
| | | String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | if(null == code || !code.equals(registerAccount.getCode())){ |
| | | return AjaxResult.error("验证码错误"); |
| | | } |
| | | //使用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("此微信号已注册,请直接登录!"); |
| | | } |
| | | 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("手机号已注册,请直接登录!"); |
| | | } |
| | | if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | appUser.setName(registerAccount.getName()); |
| | | appUser.setPhone(registerAccount.getPhone()); |
| | | appUser.setWxOpenid(openid); |
| | | //注册默认为普通会员 |
| | | appUser.setVipId(1); |
| | | appUser.setStatus(1); |
| | | appUser.setCreateTime(LocalDateTime.now()); |
| | | appUser.setDelFlag(false); |
| | | appUser.setFirstAdd(1); |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | //顶级推广人 |
| | | AppUser topAppUser = getTopAppUser(registerAccount.getPromoter()); |
| | | appUser.setTopInviteId(topAppUser.getId()); |
| | | //绑定门店为推荐人绑定的门店 |
| | | 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.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.setChangePromoter(0); |
| | | appUser.setLongitude(registerAccount.getLongitude()); |
| | | appUser.setLatitude(registerAccount.getLatitude()); |
| | | //调用地图获取省市区数据 |
| | | appUser.setProvince(); |
| | | appUser.setProvinceCode(); |
| | | appUser.setCity(); |
| | | appUser.setCityCode(); |
| | | appUser.setDistrict(); |
| | | appUser.setDistrictCode(); |
| | | this.save(appUser); |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | | loginVo.setFirstTime(false); |
| | | loginVo.setPhone(appUser.getPhone()); |
| | | //构建token |
| | | LoginUser loginUser = new LoginUser(); |
| | | loginUser.setUserid(appUser.getId()); |
| | | loginUser.setUsername(appUser.getName()); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 递归查询顶级推广人 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public AppUser getTopAppUser(Long id){ |
| | | List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0)); |
| | | return getTopAppUser(list, id); |
| | | } |
| | | |
| | | public AppUser getTopAppUser(List<AppUser> list, Long id){ |
| | | AppUser appUser = list.stream().filter(s -> s.getInviteUserId().equals(id)).findFirst().get(); |
| | | if(null == appUser.getInviteUserId()){ |
| | | return appUser; |
| | | } |
| | | return getTopAppUser(list, appUser.getId()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取附近推广人 |
| | | * @param nearbyReferrer |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BaseTable<NearbyReferrerVo> getNearbyReferrer(NearbyReferrer nearbyReferrer) { |
| | | //使用地图获取省市区数据 |
| | | String longitude = nearbyReferrer.getLongitude(); |
| | | String latitude = nearbyReferrer.getLatitude(); |
| | | String cityCode = ""; |
| | | List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(cityCode, nearbyReferrer); |
| | | BaseTable baseTable = new BaseTable(); |
| | | baseTable.setRows(list); |
| | | baseTable.setTotal(list.size()); |
| | | return baseTable; |
| | | } |
| | | } |