| | |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUserApplet; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.system.mapper.TAppUserMapper; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.AppUserListQuery; |
| | | import com.ruoyi.system.query.PromotionPageListQuery; |
| | | import com.ruoyi.system.query.UserPromotionPageListQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.PromotionPageListVo; |
| | | import com.ruoyi.system.vo.UserPromotionPageListVo; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private TIntegralSettlementService tIntegralSettlementService; |
| | | |
| | | @Autowired |
| | | private TCompanyService tCompanyService; |
| | | |
| | | @Override |
| | | public PageInfo<TAppUser> pageList(AppUserListQuery query) { |
| | | PageInfo<TAppUser> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | |
| | | SysUser sysUser = sysUserService.selectUserById(superiorId.longValue()); |
| | | if (Objects.nonNull(sysUser)) { |
| | | appUser.setReferrerSysUserId(superiorId); |
| | | appUser.setReferrerSysUserTime(LocalDateTime.now()); |
| | | } else { |
| | | log.info("推广员不存在,绑定superiorId={}", superiorId); |
| | | } |
| | | } else { |
| | | if (appUser.getReferrerStatus().equals(1)) { |
| | | if (Objects.isNull(appUser.getReferrerStatus()) || appUser.getReferrerStatus().equals(1)) { |
| | | appUser.setReferrerUserId(superiorId); |
| | | appUser.setReferrerTime(LocalDateTime.now()); |
| | | appUser.setReferrerStatus(1); |
| | | } |
| | | } |
| | | this.updateById(appUser); |
| | |
| | | |
| | | @Override |
| | | public List<PromotionPageListVo> promotionPageList(Page<PromotionPageListVo> page, PromotionPageListQuery query) { |
| | | if (Objects.isNull(query.getCompanyId())) { |
| | | throw new ServiceException("公司ID不能为空"); |
| | | } |
| | | List<PromotionPageListVo> list = this.baseMapper.promotionPageList(page,query); |
| | | |
| | | if (!list.isEmpty()) { |
| | |
| | | BigDecimal totalOne = giftPackageOrders.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TBigGiftPackageOrder::getPaymentPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | promotionPageListVo.setTotalConsume(totalOne); |
| | | |
| | | Integer totalIncome = flows.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).mapToInt(TCommissionTransactionFlow::getCommissionAmount).sum(); |
| | | BigDecimal totalIncome = flows.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TCommissionTransactionFlow::getCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | promotionPageListVo.setTotalIncome(totalIncome); |
| | | |
| | | Integer totalSettledIncome = settlements.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).mapToInt(TIntegralSettlement::getTotalSettlementIntegral).sum(); |
| | | promotionPageListVo.setTotalSettledIncome(totalSettledIncome); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | return list; |
| | | } |
| | | @Override |
| | | public List<UserPromotionPageListVo> userPromotionPageList(Page<UserPromotionPageListVo> page, UserPromotionPageListQuery query) { |
| | | List<UserPromotionPageListVo> list = this.baseMapper.userPromotionPageList(page,query); |
| | | |
| | | if (!list.isEmpty()) { |
| | | List<Integer> userIds = list.stream().map(UserPromotionPageListVo::getUserId).collect(Collectors.toList()); |
| | | // List<TPhysicalGoodsOrder> physicalGoodsOrders = tPhysicalGoodsOrderService.list(new LambdaQueryWrapper<TPhysicalGoodsOrder>().in(TPhysicalGoodsOrder::getAppUserId, userIds).notIn(TPhysicalGoodsOrder::getStatus,Arrays.asList(1,4))); |
| | | List<TBigGiftPackageOrder> giftPackageOrders = tBigGiftPackageOrderService.list(new LambdaQueryWrapper<TBigGiftPackageOrder>().in(TBigGiftPackageOrder::getAppUserId, userIds).notIn(TBigGiftPackageOrder::getStatus,Arrays.asList(1,5))); |
| | | |
| | | |
| | | List<TCommissionTransactionFlow> flows = tCommissionTransactionFlowService.list(new LambdaQueryWrapper<TCommissionTransactionFlow>().in(TCommissionTransactionFlow::getAppUserId, userIds)); |
| | | |
| | | List<TIntegralSettlement> settlements = tIntegralSettlementService.list(new LambdaQueryWrapper<TIntegralSettlement>().in(TIntegralSettlement::getAppUserId, userIds)); |
| | | for (UserPromotionPageListVo promotionPageListVo : list) { |
| | | // BigDecimal total = physicalGoodsOrders.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TPhysicalGoodsOrder::getPaymentPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal totalOne = giftPackageOrders.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TBigGiftPackageOrder::getPaymentPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | promotionPageListVo.setTotalConsume(totalOne); |
| | | |
| | | BigDecimal totalIncome = flows.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TCommissionTransactionFlow::getCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | promotionPageListVo.setTotalIncome(totalIncome); |
| | | |
| | | Integer totalSettledIncome = settlements.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).mapToInt(TIntegralSettlement::getTotalSettlementIntegral).sum(); |
| | | promotionPageListVo.setTotalSettledIncome(totalSettledIncome); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<UserPromotionPageListVo> userPromotionPageListExport(UserPromotionPageListQuery query) { |
| | | List<UserPromotionPageListVo> list = this.baseMapper.userPromotionPageListExport(query); |
| | | |
| | | if (!list.isEmpty()) { |
| | | List<Integer> userIds = list.stream().map(UserPromotionPageListVo::getUserId).collect(Collectors.toList()); |
| | | // List<TPhysicalGoodsOrder> physicalGoodsOrders = tPhysicalGoodsOrderService.list(new LambdaQueryWrapper<TPhysicalGoodsOrder>().in(TPhysicalGoodsOrder::getAppUserId, userIds).notIn(TPhysicalGoodsOrder::getStatus,Arrays.asList(1,4))); |
| | | List<TBigGiftPackageOrder> giftPackageOrders = tBigGiftPackageOrderService.list(new LambdaQueryWrapper<TBigGiftPackageOrder>().in(TBigGiftPackageOrder::getAppUserId, userIds).notIn(TBigGiftPackageOrder::getStatus,Arrays.asList(1,5))); |
| | | |
| | | |
| | | List<TCommissionTransactionFlow> flows = tCommissionTransactionFlowService.list(new LambdaQueryWrapper<TCommissionTransactionFlow>().in(TCommissionTransactionFlow::getAppUserId, userIds)); |
| | | |
| | | List<TIntegralSettlement> settlements = tIntegralSettlementService.list(new LambdaQueryWrapper<TIntegralSettlement>().in(TIntegralSettlement::getAppUserId, userIds)); |
| | | for (UserPromotionPageListVo promotionPageListVo : list) { |
| | | // BigDecimal total = physicalGoodsOrders.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TPhysicalGoodsOrder::getPaymentPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal totalOne = giftPackageOrders.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TBigGiftPackageOrder::getPaymentPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | promotionPageListVo.setTotalConsume(totalOne); |
| | | |
| | | BigDecimal totalIncome = flows.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TCommissionTransactionFlow::getCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | promotionPageListVo.setTotalIncome(totalIncome); |
| | | |
| | | Integer totalSettledIncome = settlements.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).mapToInt(TIntegralSettlement::getTotalSettlementIntegral).sum(); |
| | |
| | | BigDecimal totalOne = giftPackageOrders.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TBigGiftPackageOrder::getPaymentPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | promotionPageListVo.setTotalConsume(totalOne); |
| | | |
| | | Integer totalIncome = flows.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).mapToInt(TCommissionTransactionFlow::getCommissionAmount).sum(); |
| | | BigDecimal totalIncome = flows.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TCommissionTransactionFlow::getCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | promotionPageListVo.setTotalIncome(totalIncome); |
| | | |
| | | Integer totalSettledIncome = settlements.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).mapToInt(TIntegralSettlement::getTotalSettlementIntegral).sum(); |
| | |
| | | List<TAppUser> list = this.baseMapper.exportAppUser(query); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public TCompany getUserCompany(Integer appUserId) { |
| | | //默认返回空对象 |
| | | TCompany company = new TCompany(); |
| | | TAppUser appUser = this.getById(appUserId); |
| | | if (Objects.nonNull(appUser)) { |
| | | if (Objects.nonNull(appUser.getCompanyId())) { |
| | | company = tCompanyService.getById(appUser.getCompanyId()); |
| | | } else { |
| | | // 判断是否同时存在两种推荐来源且推荐状态为临时 |
| | | boolean hasBothReferrer = appUser.getReferrerUserId() != null |
| | | && Integer.valueOf(1).equals(appUser.getReferrerStatus()) |
| | | && appUser.getReferrerSysUserId() != null; |
| | | |
| | | if (hasBothReferrer) { |
| | | // 两种推荐来源都存在,比较推荐时间,取后推荐的用户的 companyId |
| | | LocalDateTime referrerTime = appUser.getReferrerTime(); |
| | | LocalDateTime referrerSysUserTime = appUser.getReferrerSysUserTime(); |
| | | |
| | | // 判断哪个推荐时间更晚 |
| | | boolean useSysUserCompany = false; |
| | | if (referrerSysUserTime != null && referrerTime != null) { |
| | | useSysUserCompany = referrerSysUserTime.isAfter(referrerTime); |
| | | } else if (referrerSysUserTime != null) { |
| | | useSysUserCompany = true; |
| | | } |
| | | // 如果 referrerTime != null 且 referrerSysUserTime == null,则 useSysUserCompany 保持 false |
| | | |
| | | if (useSysUserCompany) { |
| | | // 使用股东(SysUser)的 companyId |
| | | SysUser sysUser = sysUserService.selectUserById(Long.valueOf(appUser.getReferrerSysUserId())); |
| | | if (sysUser != null && sysUser.getCompanyId() != null) { |
| | | company = tCompanyService.getById(sysUser.getCompanyId()); |
| | | log.info("用户{}两种推荐来源都存在,股东推荐时间({})晚于普通推荐时间({}),通过股东(SysUser:{})关联公司{}进行加下单", |
| | | appUserId, referrerSysUserTime, referrerTime, appUser.getReferrerSysUserId(), company.getId()); |
| | | } |
| | | } else { |
| | | // 使用推荐人(TAppUser)的 companyId |
| | | TAppUser referrerAppUser = this.getById(appUser.getReferrerUserId()); |
| | | if (referrerAppUser != null && referrerAppUser.getCompanyId() != null) { |
| | | company = tCompanyService.getById(referrerAppUser.getCompanyId()); |
| | | log.info("用户{}两种推荐来源都存在,普通推荐时间({})晚于或等于股东推荐时间({}),通过推荐人(TAppUser:{})关联公司{}进行加下单", |
| | | appUserId, referrerTime, referrerSysUserTime, appUser.getReferrerUserId(), company.getId()); |
| | | } |
| | | } |
| | | } else { |
| | | // 只有一种推荐来源,按原逻辑处理 |
| | | // 优先使用 referrerSysUserId 对应的 SysUser 的 companyId |
| | | if (appUser.getReferrerSysUserId() != null) { |
| | | SysUser sysUser = sysUserService.selectUserById(Long.valueOf(appUser.getReferrerSysUserId())); |
| | | if (sysUser != null && sysUser.getCompanyId() != null) { |
| | | company = tCompanyService.getById(sysUser.getCompanyId()); |
| | | log.info("用户{}通过股东(SysUser:{})关联公司{}进行加下单", appUserId, appUser.getReferrerSysUserId(), company.getId()); |
| | | } |
| | | } |
| | | |
| | | // 如果 referrerSysUserId 为空或对应的 SysUser 没有 companyId,则使用 referrerUserId 对应的 TAppUser 的 companyId |
| | | if (company.getId() == null && appUser.getReferrerUserId() != null) { |
| | | TAppUser referrerAppUser = this.getById(appUser.getReferrerUserId()); |
| | | if (referrerAppUser != null && referrerAppUser.getCompanyId() != null) { |
| | | company = tCompanyService.getById(referrerAppUser.getCompanyId()); |
| | | log.info("用户{}通过推荐人(TAppUser:{})关联公司{}进行加下单", appUserId, appUser.getReferrerUserId(), company.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | return company; |
| | | } |
| | | } |