| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.model.AppUserShop; |
| | | import com.ruoyi.account.api.model.UserChangeLog; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | | import com.ruoyi.account.api.model.*; |
| | | 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.service.UserChangeLogService; |
| | | import com.ruoyi.account.service.UserPointService; |
| | | import com.ruoyi.account.service.*; |
| | | import com.ruoyi.account.util.ALiSendSms; |
| | | import com.ruoyi.account.util.GeodesyUtil; |
| | | import com.ruoyi.account.util.SMSUtil; |
| | | import com.ruoyi.account.util.payment.PaymentUtil; |
| | | import com.ruoyi.account.util.payment.model.CloseOrderResult; |
| | | import com.ruoyi.account.util.tencentMap.TencentMapUtil; |
| | | import com.ruoyi.account.util.weChat.EnvVersion; |
| | | import com.ruoyi.account.util.weChat.WXCore; |
| | |
| | | import com.ruoyi.account.vo.*; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.other.api.domain.PointSetting; |
| | | import com.ruoyi.other.api.domain.Region; |
| | | import com.ruoyi.other.api.domain.Shop; |
| | | import com.ruoyi.other.api.domain.VipSetting; |
| | | import com.ruoyi.other.api.feignClient.PointSettingClient; |
| | | import com.ruoyi.other.api.feignClient.RegionClient; |
| | | import com.ruoyi.other.api.feignClient.ShopClient; |
| | | import com.ruoyi.other.api.feignClient.VipSettingClient; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.order.feignClient.OrderClient; |
| | | import com.ruoyi.other.api.domain.*; |
| | | import com.ruoyi.other.api.feignClient.*; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import org.apache.logging.log4j.core.util.UuidUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.redisson.RedissonLock; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation.ANONYMOUS.optional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author luodangjia |
| | | * @since 2024-11-21 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implements AppUserService { |
| | | |
| | |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private ALiSendSms aLiSendSms; |
| | | |
| | | @Resource |
| | | private ShopClient shopClient; |
| | |
| | | |
| | | @Resource |
| | | private UserPointService userPointService; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private AppUserMapper appUserMapper; |
| | | |
| | | @Resource |
| | | private RegionClient regionClient; |
| | | |
| | | @Resource |
| | | private CouponInfoClient couponInfoClient; |
| | | |
| | | @Resource |
| | | private UserCouponService userCouponService; |
| | | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | @Resource |
| | | private BalancePaymentService balancePaymentService; |
| | | |
| | | @Resource |
| | | private OrderClient orderClient; |
| | | |
| | | @Resource |
| | | private IAppUserGiveawayTemporaryService appUserGiveawayTemporaryService; |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | 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){ |
| | | 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); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | 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(); |
| | | 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())); |
| | | |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | this.updateById(appUser); |
| | | return R.ok(loginVo); |
| | | String key = "login:" + openid; |
| | | Boolean hasKey = redisService.lock(key); |
| | | if(hasKey){ |
| | | try { |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getWxOpenid, openid).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null == 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.setSkipPage(2); |
| | | loginVo.setPhone(purePhoneNumber); |
| | | return R.ok(loginVo); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | if(2 == appUser.getStatus()){ |
| | | return R.fail("账户已被冻结,请联系管理员!"); |
| | | } |
| | | 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())); |
| | | |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | this.updateById(appUser); |
| | | return R.ok(loginVo); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisService.unlock(key); |
| | | } |
| | | }else{ |
| | | return R.fail("请稍后重试"); |
| | | } |
| | | return R.fail("登录失败"); |
| | | } |
| | | |
| | | |
| | |
| | | @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("验证码错误"); |
| | | } |
| | | } |
| | | |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, mobileLogin.getPhone()).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | 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); |
| | |
| | | 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())); |
| | | |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | this.updateById(appUser); |
| | | return R.ok(loginVo); |
| | |
| | | for (int i = 0; i < 6; i++) { |
| | | code += Double.valueOf(Math.random() * 10).intValue(); |
| | | } |
| | | SMSUtil.sendSms("[\"" + code + "\"]", smsCode.getPhone(), "8824121211029", "39533d100b2b4aee8ed198aa49fe99dd"); |
| | | // SMSUtil.sendSms("[\"" + code + "\"]", smsCode.getPhone(), "8824121211029", "39533d100b2b4aee8ed198aa49fe99dd"); |
| | | aLiSendSms.sendSms(smsCode.getPhone(), "SMS_484035336", "{\"code\":\"" + code + "\"}"); |
| | | redisService.setCacheObject(smsCode.getPhone(), code, 300L, TimeUnit.SECONDS); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 注册账号 |
| | | * @param registerAccount |
| | |
| | | @Override |
| | | public R<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | //校验验证码 |
| | | String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | if(null == code || !code.equals(registerAccount.getCode())){ |
| | | return R.fail("验证码错误"); |
| | | } |
| | | // String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | // 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()); |
| | | Integer errcode = Integer.valueOf(map.get("errcode").toString()); |
| | |
| | | if(null != appUser1 && appUser1.getStatus() == 2){ |
| | | return R.fail("手机号已注册,请直接登录!"); |
| | | } |
| | | |
| | | String avatar = registerAccount.getAvatar(); |
| | | if (StringUtils.isEmpty(avatar)){ |
| | | avatar = "http://qijishenghuiyuan.obs.cn-southwest-2.myhuaweicloud.com/admin/aedfbbb41280471f8d9fa7905298b65f.png"; |
| | | } |
| | | |
| | | //如果手机号已注册,但是没有微信号,则将微信号添加到已有账户上 |
| | | if(null != appUser1 && StringUtils.isEmpty(appUser1.getWxOpenid())){ |
| | | appUser1.setWxOpenid(openid); |
| | |
| | | appUser = appUser1; |
| | | }else if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | appUser.setAvatar(avatar); |
| | | appUser.setName(registerAccount.getName()); |
| | | appUser.setPhone(registerAccount.getPhone()); |
| | | appUser.setWxOpenid(openid); |
| | |
| | | appUser.setTotalRedPacketAmount(BigDecimal.ZERO); |
| | | appUser.setTotalDistributionAmount(BigDecimal.ZERO); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | //新用户才能奖励积分,老用户注销重新注册没有 |
| | | long old = this.count(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(0 == old){ |
| | | Integer regisPoint1 = 0; |
| | | //计算可用积分比例 |
| | | if(1 == pointSetting.getGetRegisPointOpen()){ |
| | | regisPoint1 = new BigDecimal(regisPoint).multiply(pointSetting.getGetRegisPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | appUser.setLavePoint(regisPoint); |
| | | appUser.setAvailablePoint(regisPoint1); |
| | | appUser.setTotalAvailablePoint(regisPoint1); |
| | | if(null != pointSetting && 1 == pointSetting.getGetRegisPointGift()){ |
| | | appUser.setTransferablePoint(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(); |
| | |
| | | appUser.setProvinceCode(region.getCode()); |
| | | } |
| | | this.save(appUser); |
| | | //添加定时任务队列 |
| | | VipSetting vipSetting = vipSettingClient.getVipSetting(1).getData(); |
| | | Integer vipCancelDay = vipSetting.getVipCancelDay(); |
| | | Integer vipChangeDay = vipSetting.getVipChangeDay(); |
| | | //解绑推广人 |
| | | redisTemplate.opsForZSet().add("unbind_promoter", appUser.getId().toString(), LocalDateTime.now().plusDays(vipCancelDay).toEpochSecond(ZoneOffset.UTC)); |
| | | //可更换推广人 |
| | | redisTemplate.opsForZSet().add("replaceable", appUser.getId().toString(), LocalDateTime.now().plusDays(vipChangeDay).toEpochSecond(ZoneOffset.UTC)); |
| | | |
| | | //增加积分变动记录 |
| | | if(getRegisPoint1 > 0){ |
| | | if(0 == old && regisPoint > 0){ |
| | | //构建积分流水记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(10); |
| | | userPoint.setHistoricalPoint(0); |
| | | userPoint.setVariablePoint(getRegisPoint1); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setType(7); |
| | | userPoint.setVariablePoint(regisPoint); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPoint.setChangeDirection(1); |
| | | userPointService.save(userPoint); |
| | | } |
| | | //获取微信推广二维码 |
| | | String fileName = UUID.randomUUID() + ".jpg"; |
| | | weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + appUser.getId(), EnvVersion.DEVELOP, filePath + fileName); |
| | | appUser.setQrCode(accessPath + fileName); |
| | | this.updateById(appUser); |
| | | //直推用户检查是否满足升级条件 |
| | | if(null != appUser.getInviteUserId()){ |
| | | vipUpgrade(appUser.getInviteUserId()); |
| | | } |
| | | |
| | | //查询当前注册的手机号是都和门店管理员手机号相同 |
| | | 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); |
| | | //获取优惠券 |
| | | if(0 == old){ |
| | | List<CouponInfo> list = couponInfoClient.getCouponInfoByPersonType(4).getData(); |
| | | for (CouponInfo couponInfo : list) { |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setDelFlag(0); |
| | | userCoupon.setCreateTime(LocalDateTime.now()); |
| | | userCoupon.setAppUserId(appUser.getId()); |
| | | userCoupon.setCouponId(couponInfo.getId()); |
| | | LocalDateTime start = couponInfo.getPeriodStartTime().atTime(0, 0, 0); |
| | | LocalDateTime end = couponInfo.getPeriodEndTime().atTime(23, 59, 59); |
| | | if(couponInfo.getPeriodType() == 2){ |
| | | start = LocalDateTime.now(); |
| | | end = start.plusDays(couponInfo.getPeriodDays()); |
| | | } |
| | | userCoupon.setStartTime(start); |
| | | userCoupon.setEndTime(end); |
| | | userCoupon.setCouponInfo(JSON.toJSONString(couponInfo)); |
| | | userCouponService.save(userCoupon); |
| | | } |
| | | } |
| | | } |
| | | //变更等级 |
| | | vipUpgrade(appUser.getId()); |
| | | |
| | | //拉新分佣 |
| | | if(0 == old && null != appUser2){ |
| | | pointSetting = pointSettingClient.getPointSetting(appUser2.getVipId()).getData(); |
| | | Integer newPoint = pointSetting.getNewPoint(); |
| | | Integer newPoint1 = 0; |
| | | if(1 == pointSetting.getGetNewPointOpen()){ |
| | | newPoint1 = new BigDecimal(newPoint).multiply(pointSetting.getGetNewPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | appUser2.setLavePoint(appUser2.getLavePoint() + newPoint); |
| | | appUser2.setAvailablePoint(appUser2.getAvailablePoint() + newPoint1); |
| | | appUser2.setTotalAvailablePoint(appUser2.getTotalAvailablePoint() + newPoint1); |
| | | if(null != pointSetting && 1 == pointSetting.getGetNewPointGift()){ |
| | | appUser2.setTransferablePoint(appUser2.getTransferablePoint() + 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.setVariablePoint(newPoint); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser2.getId()); |
| | | userPoint.setChangeDirection(1); |
| | | 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.setTotalAvailablePoint(appUser3.getTotalAvailablePoint() + newPoint1); |
| | | if(null != pointSetting && 1 == pointSetting.getGetRegisPointGift()){ |
| | | appUser3.setTransferablePoint(appUser3.getTransferablePoint() + 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.setVariablePoint(newPoint); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser3.getId()); |
| | | userPoint.setChangeDirection(1); |
| | | userPointService.save(userPoint); |
| | | } |
| | | //变更等级 |
| | | vipUpgrade(appUser3.getId()); |
| | | } |
| | | } |
| | | |
| | | //获取微信推广二维码 |
| | | String fileName = UUID.randomUUID() + ".jpg"; |
| | | String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/start/start", "id=" + appUser.getId(), EnvVersion.RELEASE, filePath + fileName); |
| | | appUser.setQrCode(getwxacodeunlimit); |
| | | this.updateById(appUser); |
| | | |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | | loginVo.setFirstTime(null == appUser1); |
| | |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 会员等级变化 |
| | | */ |
| | | @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(); |
| | | //消费积分满足升级 |
| | | if(1 == vipSetting3.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting3.getVipLevelUpShop()) >= 0 && appUser.getVipId() < 3){ |
| | | appUser.setVipId(3); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //返佣积分满足升级 |
| | | List<AppUserGiveawayTemporary> list = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>().eq(AppUserGiveawayTemporary::getAppUserId, appUser.getId())); |
| | | int sum = list.stream().mapToInt(AppUserGiveawayTemporary::getSharePoint).sum(); |
| | | int sharePoin = appUser.getSharePoint() + sum; |
| | | if(1 == vipSetting3.getVipLevelUpShareRole() && sharePoin >= vipSetting3.getVipLevelUpShare() && appUser.getVipId() < 3){ |
| | | appUser.setVipId(3); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //下级人数满足升级 |
| | | Integer vipLevelUpNumRole = vipSetting3.getVipLevelUpNumRole(); |
| | | Integer vipDirectNum = vipSetting3.getVipDirectNum(); |
| | | Integer vipTeamNum = vipSetting3.getVipTeamNum(); |
| | |
| | | return; |
| | | } |
| | | } |
| | | |
| | | //黄金会员 |
| | | VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData(); |
| | | //消费积分满足升级 |
| | | if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting2.getVipLevelUpShop()) >= 0 && appUser.getVipId() < 2){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //返佣积分满足升级 |
| | | if(1 == vipSetting2.getVipLevelUpShareRole() && appUser.getSharePoint().compareTo(vipSetting2.getVipLevelUpShare()) >= 0 && appUser.getVipId() < 2){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //下级人数满足升级 |
| | | vipLevelUpNumRole = vipSetting2.getVipLevelUpNumRole(); |
| | | vipDirectNum = vipSetting2.getVipDirectNum(); |
| | | vipTeamNum = vipSetting2.getVipTeamNum(); |
| | | if(1 == vipLevelUpNumRole && appUser.getVipId() < 2){ |
| | | //查询直推用户达到X人或者团队人数达到X人后,可升级 |
| | | //直推用户数 |
| | | long count = this.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1).eq(AppUser::getInviteUserId, id)); |
| | | //团队用户数 |
| | | List<AppUser> subordinate = getSubordinate(id); |
| | | if(vipDirectNum <= count || vipTeamNum <= subordinate.size()){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void vipConsumption(Long id){ |
| | | |
| | | System.out.println("1111111111111111111111"); |
| | | |
| | | AppUser appUser = this.getById(id); |
| | | System.out.println("消费积分:"+ appUser.getShopPoint()); |
| | | System.out.println("返佣积分:"+ appUser.getSharePoint() ); |
| | | Integer vipId = appUser.getVipId(); |
| | | //钻石会员 |
| | | VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData(); |
| | | //消费积分满足升级 |
| | | if(1 == vipSetting3.getVipLevelUpShopRole() && appUser.getShopPoint() >= vipSetting3.getVipLevelUpShop() && appUser.getVipId() < 3){ |
| | | appUser.setVipId(3); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //返佣积分满足升级 |
| | | if(1 == vipSetting3.getVipLevelUpShareRole() && appUser.getSharePoint() >= vipSetting3.getVipLevelUpShare() && appUser.getVipId() < 3){ |
| | | appUser.setVipId(3); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //下级人数满足升级 |
| | | Integer vipLevelUpNumRole = vipSetting3.getVipLevelUpNumRole(); |
| | | Integer vipDirectNum = vipSetting3.getVipDirectNum(); |
| | | Integer vipTeamNum = vipSetting3.getVipTeamNum(); |
| | | if(1 == vipLevelUpNumRole && appUser.getVipId() < 3){ |
| | | //查询直推用户达到X人或者团队人数达到X人后,可升级 |
| | | //直推用户数 |
| | | long count = this.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1).eq(AppUser::getInviteUserId, id)); |
| | | //团队用户数 |
| | | List<AppUser> subordinate = getSubordinate(id); |
| | | if(vipDirectNum <= count || vipTeamNum <= subordinate.size()){ |
| | | appUser.setVipId(3); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | //黄金会员 |
| | | VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData(); |
| | | //消费积分满足升级 |
| | | if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint() >= vipSetting2.getVipLevelUpShop() && appUser.getVipId() < 2){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //返佣积分满足升级 |
| | | if(1 == vipSetting2.getVipLevelUpShareRole() && appUser.getSharePoint() >= vipSetting2.getVipLevelUpShare() && appUser.getVipId() < 2){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //下级人数满足升级 |
| | | vipLevelUpNumRole = vipSetting2.getVipLevelUpNumRole(); |
| | | vipDirectNum = vipSetting2.getVipDirectNum(); |
| | | vipTeamNum = vipSetting2.getVipTeamNum(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 处理会员降级 |
| | | * @param appUserId |
| | | */ |
| | | @Override |
| | | public void vipDemotion(Long appUserId) { |
| | | AppUser appUser = this.getById(appUserId); |
| | | Integer vipId = appUser.getVipId(); |
| | | //钻石会员 |
| | | VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData(); |
| | | if(1 == vipSetting3.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting3.getVipLevelUpShop()) >= 0 && appUser.getVipId() == 3){ |
| | | return; |
| | | } |
| | | //返佣积分满足升级 |
| | | List<AppUserGiveawayTemporary> list = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>().eq(AppUserGiveawayTemporary::getAppUserId, appUser.getId())); |
| | | int sum = list.stream().mapToInt(AppUserGiveawayTemporary::getSharePoint).sum(); |
| | | int sharePoin = appUser.getSharePoint() + sum; |
| | | if(1 == vipSetting3.getVipLevelUpShareRole() && sharePoin >= vipSetting3.getVipLevelUpShare() && appUser.getVipId() == 3){ |
| | | return; |
| | | } |
| | | //下级人数满足升级 |
| | | Integer vipLevelUpNumRole = vipSetting3.getVipLevelUpNumRole(); |
| | | Integer vipDirectNum = vipSetting3.getVipDirectNum(); |
| | | Integer vipTeamNum = vipSetting3.getVipTeamNum(); |
| | | if(1 == vipLevelUpNumRole && appUser.getVipId() == 3){ |
| | | //查询直推用户达到X人或者团队人数达到X人后,可升级 |
| | | //直推用户数 |
| | | long count = this.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1).eq(AppUser::getInviteUserId, appUserId)); |
| | | //团队用户数 |
| | | List<AppUser> subordinate = getSubordinate(appUserId); |
| | | if(vipDirectNum <= count || vipTeamNum <= subordinate.size()){ |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | //黄金会员 |
| | | VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData(); |
| | | //消费积分满足升级 |
| | | if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting2.getVipLevelUpShop()) >= 0 && appUser.getVipId() >= 2){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(0); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //返佣积分满足升级 |
| | | if(1 == vipSetting2.getVipLevelUpShareRole() && sharePoin >= vipSetting2.getVipLevelUpShare() && appUser.getVipId() >= 2){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(0); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | //下级人数满足升级 |
| | | vipLevelUpNumRole = vipSetting2.getVipLevelUpNumRole(); |
| | | vipDirectNum = vipSetting2.getVipDirectNum(); |
| | | vipTeamNum = vipSetting2.getVipTeamNum(); |
| | | if(1 == vipLevelUpNumRole && appUser.getVipId() >= 2){ |
| | | //查询直推用户达到X人或者团队人数达到X人后,可升级 |
| | | //直推用户数 |
| | | long count = this.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1).eq(AppUser::getInviteUserId, appUserId)); |
| | | //团队用户数 |
| | | List<AppUser> subordinate = getSubordinate(appUserId); |
| | | if(vipDirectNum <= count || vipTeamNum <= subordinate.size()){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(0); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | } |
| | | appUser.setVipId(1); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(0); |
| | | userChangeLogService.save(userChangeLog); |
| | | } |
| | | |
| | | /** |
| | | * 递归查询顶级推广人 |
| | |
| | | } |
| | | |
| | | 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{ |
| | | result.addAll(collect); |
| | | List<Long> collect1 = collect.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | List<Long> collect2 = result.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | List<AppUser> list1 = new ArrayList<>(); |
| | | for (AppUser appUser : collect) { |
| | | if(!collect2.contains(appUser.getId())){ |
| | | list1.add(appUser); |
| | | } |
| | | } |
| | | if(list1.size() == 0){ |
| | | return result; |
| | | } |
| | | result.addAll(list1); |
| | | List<Long> collect1 = list1.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | idss.addAll(collect1); |
| | | } |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<NearbyReferrerVo> getNearbyReferrer(NearbyReferrer nearbyReferrer) { |
| | | public PageInfo<NearbyReferrerVo> getNearbyReferrer(NearbyReferrer nearbyReferrer) { |
| | | //使用地图获取省市区数据 |
| | | String citycode = TencentMapUtil.inverseGeographicalAnalysis(nearbyReferrer.getLongitude(), nearbyReferrer.getLatitude(), false); |
| | | if(StringUtils.isEmpty(citycode)){ |
| | | citycode = "510100"; |
| | | } |
| | | if(null != citycode){ |
| | | String cityCode = citycode.substring(0, 3) + "00"; |
| | | List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(cityCode, nearbyReferrer); |
| | | return list; |
| | | String cityCode = citycode.substring(0, 4) + "00"; |
| | | PageInfo<NearbyReferrerVo> pageInfo = new PageInfo(nearbyReferrer.getPageCurr(), nearbyReferrer.getPageSize()); |
| | | List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(pageInfo, cityCode, nearbyReferrer); |
| | | for (NearbyReferrerVo nearbyReferrerVo : list) { |
| | | switch (nearbyReferrerVo.getVip()){ |
| | | case "1": |
| | | nearbyReferrerVo.setVip("普通会员"); |
| | | break; |
| | | case "2": |
| | | nearbyReferrerVo.setVip("黄金会员"); |
| | | break; |
| | | case "3": |
| | | nearbyReferrerVo.setVip("钻石会员"); |
| | | break; |
| | | case "4": |
| | | nearbyReferrerVo.setVip("准代理"); |
| | | break; |
| | | case "5": |
| | | nearbyReferrerVo.setVip("代理"); |
| | | break; |
| | | case "6": |
| | | nearbyReferrerVo.setVip("总代"); |
| | | break; |
| | | case "7": |
| | | nearbyReferrerVo.setVip("合伙人"); |
| | | break; |
| | | } |
| | | |
| | | String latitude = nearbyReferrerVo.getLatitude(); |
| | | String longitude = nearbyReferrerVo.getLongitude(); |
| | | Double wgs84 = GeodesyUtil.getDistance(longitude + "," + latitude, nearbyReferrer.getLongitude() + "," + nearbyReferrer.getLatitude()).get("WGS84"); |
| | | nearbyReferrerVo.setDistance(wgs84); |
| | | } |
| | | list.sort(new Comparator<NearbyReferrerVo>() { |
| | | @Override |
| | | public int compare(NearbyReferrerVo o1, NearbyReferrerVo o2) { |
| | | return o1.getDistance().compareTo(o2.getDistance()); |
| | | } |
| | | }); |
| | | return pageInfo.setRecords(list); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | if (inviteUser.getVipId() > 3) { |
| | | return inviteUser; |
| | | }else { |
| | | getSuperiorLeader(inviteUserId); |
| | | return getSuperiorLeader(inviteUserId); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | @Override |
| | | public void unbindThePromoter() { |
| | | //注册X天后没有升级成黄金会员则自动解绑推广人 |
| | | VipSetting vipSetting = vipSettingClient.getVipSetting(1).getData(); |
| | | Integer vipCancelDay = vipSetting.getVipCancelDay(); |
| | | Integer vipChangeDay = vipSetting.getVipChangeDay(); |
| | | List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getVipId, 1).eq(AppUser::getDelFlag, 0).isNotNull(AppUser::getInviteUserId) |
| | | .eq(AppUser::getStatus, 1).last(" and (UNIX_TIMESTAMP(create_time) + " + vipCancelDay + ") <= UNIX_TIMESTAMP()")); |
| | | for (AppUser appUser : list) { |
| | | appUser.setInviteUserId(null); |
| | | appUser.setShopId(null); |
| | | this.updateById(appUser); |
| | | //解绑推广人 |
| | | 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()); |
| | | } |
| | | |
| | | //可更换推广人 |
| | | list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getVipId, 1).eq(AppUser::getDelFlag, 0).eq(AppUser::getChangePromoter, 0) |
| | | .isNull(AppUser::getLastShopTime).eq(AppUser::getStatus, 1).last(" and (UNIX_TIMESTAMP(create_time) + " + vipCancelDay + ") <= UNIX_TIMESTAMP()")); |
| | | for (AppUser appUser : list) { |
| | | appUser.setChangePromoter(1); |
| | | this.updateById(appUser); |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | Object cacheObject = redisService.getCacheObject("ONLINE_" + userid); |
| | | if(null == cacheObject){ |
| | | redisService.setCacheObject("ONLINE_" + userid, 0, 15L, TimeUnit.MINUTES); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("time", System.currentTimeMillis()); |
| | | jsonObject.put("online", 0); |
| | | redisService.setCacheObject("ONLINE_" + userid, jsonObject, 1L, TimeUnit.HOURS); |
| | | }else{ |
| | | Long duration = (Long) cacheObject; |
| | | duration += 10; |
| | | //满足一个小时,开始发放积分,计时归0 |
| | | if(60 >= duration){ |
| | | redisService.setCacheObject("ONLINE_" + userid, 0, 15L, TimeUnit.MINUTES); |
| | | 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 = hourPoint; |
| | | int hourPoint1 = 0; |
| | | if(1 == pointSetting.getWorkPointOpen()){ |
| | | hourPoint1 = hourPoint1 * (100 - pointSetting.getWorkPoint()); |
| | | hourPoint1 = new BigDecimal(hourPoint).multiply(pointSetting.getWorkPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + hourPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + hourPoint1); |
| | | this.updateById(appUser); |
| | | //添加积分变动记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(9); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(hourPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPointService.save(userPoint); |
| | | 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.setVariablePoint(hourPoint); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPoint.setChangeDirection(1); |
| | | userPointService.save(userPoint); |
| | | //变更等级 |
| | | vipUpgrade(appUser.getId()); |
| | | } |
| | | } |
| | | }else{ |
| | | redisService.setCacheObject("ONLINE_" + userid, duration, 15L, TimeUnit.MINUTES); |
| | | jsonObject.put("online", online); |
| | | redisService.setCacheObject("ONLINE_" + userid, jsonObject, 1L, TimeUnit.HOURS); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public IPage<AppUser> getAppuserPage(Integer pageNum, Integer pageSize, AppUser appUser) { |
| | | public IPage<AppUser> getAppuserPage(Integer pageNum, Integer pageSize, AppUser appUser, Integer shopId, Set<Long> userId) { |
| | | if (StringUtils.isNotEmpty(appUser.getShopName())){ |
| | | R<Set<Integer>> shopR = shopClient.getShopIdByName(appUser.getShopName()); |
| | | if (R.isSuccess(shopR)){ |
| | | Set<Integer> shopIds = shopR.getData(); |
| | | if (!CollectionUtils.isEmpty(shopIds)){ |
| | | appUser.setShopIds(shopIds); |
| | | }else { |
| | | return new Page<>(); |
| | | } |
| | | } |
| | | } |
| | | return appUserMapper.getAppuserPage(new Page<>(pageNum, pageSize), appUser); |
| | | return appUserMapper.getAppuserPage(new Page<>(pageNum, pageSize), appUser, shopId, userId); |
| | | } |
| | | @Override |
| | | public IPage<AppUser> getAppuserPage1(Integer pageNum, Integer pageSize, AppUser appUser,Integer objectId,List<Long> userIds) { |
| | | public IPage<AppUser> getAppuserPage1(Integer pageNum, Integer pageSize, AppUser appUser,List<Long> userIds) { |
| | | return appUserMapper.getAppuserPage1(new Page<>(pageNum, pageSize), appUser,userIds); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 降级检测 |
| | | */ |
| | | @Override |
| | | public void demotionDetection() { |
| | | //代理 |
| | | List<AppUser> appUserList = new ArrayList<>(); |
| | | for (int i = 5; i < 8; i++) { |
| | | VipSetting vipSetting = vipSettingClient.getVipSetting(i).getData(); |
| | | List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getVipId, i).eq(AppUser::getStatus, 1).eq(AppUser::getDelFlag, 0).eq(AppUser::getIsDanger, 0)); |
| | | for (AppUser appUser : list) { |
| | | //消费积分 |
| | | List<UserPoint> list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 1).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepBuyDay() + " DAY) <= create_time")); |
| | | int sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum(); |
| | | if(sum < vipSetting.getKeepBuyPoint()){ |
| | | appUser.setIsDanger(1); |
| | | appUserList.add(appUser); |
| | | continue; |
| | | } |
| | | //返佣积分 |
| | | list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 2).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShareDay() + " DAY) <= create_time")); |
| | | sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum(); |
| | | if(sum < vipSetting.getKeepSharePoint()){ |
| | | appUser.setIsDanger(1); |
| | | appUserList.add(appUser); |
| | | continue; |
| | | } |
| | | //门店业绩 |
| | | list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 8).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShopDay() + " DAY) <= create_time")); |
| | | sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum(); |
| | | if(sum < vipSetting.getKeepShopPoint()){ |
| | | appUser.setIsDanger(1); |
| | | appUserList.add(appUser); |
| | | } |
| | | } |
| | | } |
| | | if(appUserList.size() > 0){ |
| | | this.updateBatchById(appUserList); |
| | | } |
| | | } |
| | | |
| | | return appUserMapper.getAppuserPage1(new Page<>(pageNum, pageSize), appUser,objectId,userIds); |
| | | |
| | | |
| | | /** |
| | | * 定时任务关闭订单 |
| | | */ |
| | | @Override |
| | | public void closeOrder() { |
| | | //订单支付数据 |
| | | long second = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); |
| | | Set<String> orderPayment = redisTemplate.opsForZSet().rangeByScore("BalanceRecharge", 0, second); |
| | | if(orderPayment.size() > 0){ |
| | | List<BalancePayment> list = balancePaymentService.list(new LambdaQueryWrapper<BalancePayment>().in(BalancePayment::getId, orderPayment)); |
| | | for (BalancePayment order : list) { |
| | | if(null == order || order.getStatus() != 1){ |
| | | redisTemplate.opsForZSet().remove("BalanceRecharge", order.getId()); |
| | | continue; |
| | | } |
| | | //开始执行关闭订单操作 |
| | | CloseOrderResult closeOrderResult = PaymentUtil.closeOrder(order.getId().toString()); |
| | | if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) && |
| | | Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){ |
| | | redisTemplate.opsForZSet().add("BalanceRecharge", order.getId(), 0); |
| | | log.error("关闭订单失败:{}---->{}", order.getId(), com.alibaba.fastjson2.JSON.toJSONString(closeOrderResult)); |
| | | } |
| | | redisTemplate.opsForZSet().remove("BalanceRecharge", order.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<AppUser> getAppUserByPhoneNoFilter(String phone) { |
| | | return this.baseMapper.getAppUserByPhoneNoFilter(phone); |
| | | } |
| | | } |