“mitao”
2025-12-24 b82e78ceb8f52b05203f05eb4b14151b1ab408a2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TAppUserServiceImpl.java
@@ -6,12 +6,15 @@
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;
@@ -52,6 +55,9 @@
    @Autowired
    private TIntegralSettlementService tIntegralSettlementService;
    @Autowired
    private TCompanyService tCompanyService;
    @Override
    public PageInfo<TAppUser> pageList(AppUserListQuery query) {
        PageInfo<TAppUser> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
@@ -81,9 +87,10 @@
                    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);
@@ -92,6 +99,9 @@
    @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()) {
@@ -108,7 +118,68 @@
                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();
@@ -139,10 +210,10 @@
                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);
                BigDecimal totalSettledIncome = settlements.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).map(TIntegralSettlement::getTotalSettlementIntegral).reduce(BigDecimal.ZERO, BigDecimal::add);
                Integer totalSettledIncome = settlements.stream().filter(e -> e.getAppUserId().equals(promotionPageListVo.getUserId())).mapToInt(TIntegralSettlement::getTotalSettlementIntegral).sum();
                promotionPageListVo.setTotalSettledIncome(totalSettledIncome);
            }
@@ -157,4 +228,15 @@
        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) && Objects.nonNull(appUser.getCompanyId())) {
            company = tCompanyService.getById(appUser.getCompanyId());
        }
        return company;
    }
}