| | |
| | | import com.ruoyi.account.mapper.AppUserMapper; |
| | | import com.ruoyi.account.service.*; |
| | | 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.*; |
| | |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.logging.log4j.core.util.UuidUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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 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> |
| | |
| | | * @author luodangjia |
| | | * @since 2024-11-21 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implements AppUserService { |
| | | |
| | |
| | | |
| | | @Resource |
| | | private UserCouponService userCouponService; |
| | | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | @Resource |
| | | private BalancePaymentService balancePaymentService; |
| | | |
| | | |
| | | /** |
| | |
| | | appUser = appUser1; |
| | | }else if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | appUser.setAvatar(registerAccount.getAvatar()); |
| | | appUser.setName(registerAccount.getName()); |
| | | appUser.setPhone(registerAccount.getPhone()); |
| | | appUser.setWxOpenid(openid); |
| | |
| | | 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(0 == old && regisPoint > 0){ |
| | | //构建积分流水记录 |
| | |
| | | weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + appUser.getId(), EnvVersion.TRIAL, filePath + fileName); |
| | | appUser.setQrCode(accessPath + fileName); |
| | | this.updateById(appUser); |
| | | } |
| | | |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | | loginVo.setFirstTime(null == appUser1); |
| | |
| | | * @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, 4) + "00"; |
| | | List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(cityCode, nearbyReferrer); |
| | | return list; |
| | | 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; |
| | | } |
| | | } |
| | | return pageInfo.setRecords(list); |
| | | } |
| | | 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 ADDDATE(create_time,INTERVAL " + vipCancelDay + " DAY) <= now()")); |
| | | 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); |
| | | |
| | | //解绑推广人 |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | //可更换推广人 |
| | | list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getChangePromoter, 0) |
| | | .eq(AppUser::getStatus, 1).last(" and ADDDATE(ifnull(last_shop_time, create_time),INTERVAL " + vipChangeDay + " DAY) <= now()")); |
| | | 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, unbind_promoter)); |
| | | for (AppUser appUser : list) { |
| | | appUser.setChangePromoter(1); |
| | | this.updateById(appUser); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if(null == cacheObject){ |
| | | redisService.setCacheObject("ONLINE_" + userid, 0, 15L, TimeUnit.MINUTES); |
| | | }else{ |
| | | Long duration = (Long) cacheObject; |
| | | Integer duration = (Integer) cacheObject; |
| | | duration += 10; |
| | | //满足一个小时,开始发放积分,计时归0 |
| | | if(60 >= duration){ |
| | |
| | | } |
| | | |
| | | @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)){ |
| | |
| | | } |
| | | } |
| | | } |
| | | 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) { |
| | | |
| | | return appUserMapper.getAppuserPage1(new Page<>(pageNum, pageSize), appUser,objectId,userIds); |
| | | } |
| | | |
| | |
| | | this.updateBatchById(appUserList); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 定时任务关闭订单 |
| | | */ |
| | | @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()); |
| | | } |
| | | } |
| | | } |
| | | } |