mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	@@ -20,13 +20,13 @@ import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSumma
 | 
			
		||||
import io.swagger.v3.oas.annotations.Operation;
 | 
			
		||||
import io.swagger.v3.oas.annotations.Parameter;
 | 
			
		||||
import io.swagger.v3.oas.annotations.tags.Tag;
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import jakarta.validation.Valid;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.format.annotation.DateTimeFormat;
 | 
			
		||||
import org.springframework.validation.annotation.Validated;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import jakarta.validation.Valid;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
@@ -50,7 +50,6 @@ public class AppBrokerageUserController {
 | 
			
		||||
    private BrokerageRecordService brokerageRecordService;
 | 
			
		||||
    @Resource
 | 
			
		||||
    private BrokerageWithdrawService brokerageWithdrawService;
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    private MemberUserApi memberUserApi;
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +57,7 @@ public class AppBrokerageUserController {
 | 
			
		||||
    @Operation(summary = "获得个人分销信息")
 | 
			
		||||
    @PreAuthenticated
 | 
			
		||||
    public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
 | 
			
		||||
        Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId()));
 | 
			
		||||
        Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getOrCreateBrokerageUser(getLoginUserId()));
 | 
			
		||||
        // 返回数据
 | 
			
		||||
        AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
 | 
			
		||||
                .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false))
 | 
			
		||||
@@ -79,21 +78,22 @@ public class AppBrokerageUserController {
 | 
			
		||||
    @PreAuthenticated
 | 
			
		||||
    public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
 | 
			
		||||
        // 查询当前登录用户信息
 | 
			
		||||
        BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(getLoginUserId());
 | 
			
		||||
        Long userId = getLoginUserId();
 | 
			
		||||
        BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(userId);
 | 
			
		||||
        // 统计用户昨日的佣金
 | 
			
		||||
        LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
 | 
			
		||||
        LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
 | 
			
		||||
        LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
 | 
			
		||||
        Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(brokerageUser.getId(),
 | 
			
		||||
        Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(userId,
 | 
			
		||||
                BrokerageRecordBizTypeEnum.ORDER, BrokerageRecordStatusEnum.SETTLEMENT, beginTime, endTime);
 | 
			
		||||
        // 统计用户提现的佣金
 | 
			
		||||
        Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(brokerageUser.getId()),
 | 
			
		||||
        Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(userId),
 | 
			
		||||
                        BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream()
 | 
			
		||||
                .findFirst().map(BrokerageWithdrawSummaryRespBO::getPrice).orElse(0);
 | 
			
		||||
        // 统计分销用户数量(一级)
 | 
			
		||||
        Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 1);
 | 
			
		||||
        Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1);
 | 
			
		||||
        // 统计分销用户数量(二级)
 | 
			
		||||
        Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 2);
 | 
			
		||||
        Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2);
 | 
			
		||||
 | 
			
		||||
        // 拼接返回
 | 
			
		||||
        return success(BrokerageUserConvert.INSTANCE.convert(yesterdayPrice, withdrawPrice, firstBrokerageUserCount, secondBrokerageUserCount, brokerageUser));
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ import jakarta.validation.constraints.NotNull;
 | 
			
		||||
 | 
			
		||||
@Schema(description = "应用 App - 绑定推广员 Request VO")
 | 
			
		||||
@Data
 | 
			
		||||
public class AppBrokerageUserBindReqVO extends PageParam {
 | 
			
		||||
public class AppBrokerageUserBindReqVO {
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
 | 
			
		||||
    @NotNull(message = "推广员编号不能为空")
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokera
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
 | 
			
		||||
 | 
			
		||||
import jakarta.validation.constraints.NotNull;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@@ -67,6 +67,14 @@ public interface BrokerageUserService {
 | 
			
		||||
     */
 | 
			
		||||
    BrokerageUserDO getBindBrokerageUser(Long id);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得或创建分销用户
 | 
			
		||||
     *
 | 
			
		||||
     * @param id 用户编号
 | 
			
		||||
     * @return 分销用户
 | 
			
		||||
     */
 | 
			
		||||
    BrokerageUserDO getOrCreateBrokerageUser(Long id);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新用户佣金
 | 
			
		||||
     *
 | 
			
		||||
@@ -104,8 +112,8 @@ public interface BrokerageUserService {
 | 
			
		||||
    /**
 | 
			
		||||
     * 【会员】绑定推广员
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId       用户编号
 | 
			
		||||
     * @param bindUserId   推广员编号
 | 
			
		||||
     * @param userId     用户编号
 | 
			
		||||
     * @param bindUserId 推广员编号
 | 
			
		||||
     * @return 是否绑定
 | 
			
		||||
     */
 | 
			
		||||
    boolean bindBrokerageUser(@NotNull Long userId, @NotNull Long bindUserId);
 | 
			
		||||
@@ -134,4 +142,5 @@ public interface BrokerageUserService {
 | 
			
		||||
     * @return 下级分销统计分页
 | 
			
		||||
     */
 | 
			
		||||
    PageResult<AppBrokerageUserChildSummaryRespVO> getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
import cn.hutool.core.lang.Assert;
 | 
			
		||||
import cn.hutool.core.util.ArrayUtil;
 | 
			
		||||
import cn.hutool.core.util.BooleanUtil;
 | 
			
		||||
import cn.hutool.core.util.ObjUtil;
 | 
			
		||||
import cn.hutool.core.util.StrUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
 | 
			
		||||
@@ -25,10 +26,10 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.validation.annotation.Validated;
 | 
			
		||||
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
@@ -127,6 +128,19 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
 | 
			
		||||
                .orElse(null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public BrokerageUserDO getOrCreateBrokerageUser(Long id) {
 | 
			
		||||
        BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(id);
 | 
			
		||||
        // 特殊:人人分销的情况下,如果分销人为空则创建分销人
 | 
			
		||||
        if (brokerageUser == null && ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(),
 | 
			
		||||
                tradeConfigService.getTradeConfig().getBrokerageEnabledCondition())) {
 | 
			
		||||
            brokerageUser = new BrokerageUserDO().setId(id).setBrokerageEnabled(true).setBrokeragePrice(0)
 | 
			
		||||
                    .setBrokerageTime(LocalDateTime.now()).setFrozenPrice(0);
 | 
			
		||||
            brokerageUserMapper.insert(brokerageUser);
 | 
			
		||||
        }
 | 
			
		||||
        return brokerageUser;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean updateUserPrice(Long id, Integer price) {
 | 
			
		||||
        if (price > 0) {
 | 
			
		||||
@@ -184,7 +198,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
 | 
			
		||||
            if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
 | 
			
		||||
                brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
 | 
			
		||||
            }
 | 
			
		||||
            brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now());
 | 
			
		||||
            brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
 | 
			
		||||
        } else {
 | 
			
		||||
            brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
 | 
			
		||||
@@ -294,18 +307,23 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void validateCanBindUser(BrokerageUserDO user, Long bindUserId) {
 | 
			
		||||
        // 校验要绑定的用户有无推广资格
 | 
			
		||||
        BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId);
 | 
			
		||||
        // 1.1 校验推广人是否存在
 | 
			
		||||
        MemberUserRespDTO bindUserInfo = memberUserApi.getUser(bindUserId);
 | 
			
		||||
        if (bindUserInfo == null) {
 | 
			
		||||
            throw exception(BROKERAGE_USER_NOT_EXISTS);
 | 
			
		||||
        }
 | 
			
		||||
        // 1.2 校验要绑定的用户有无推广资格
 | 
			
		||||
        BrokerageUserDO bindUser = getOrCreateBrokerageUser(bindUserId);
 | 
			
		||||
        if (bindUser == null || BooleanUtil.isFalse(bindUser.getBrokerageEnabled())) {
 | 
			
		||||
            throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 校验绑定自己
 | 
			
		||||
        // 2. 校验绑定自己
 | 
			
		||||
        if (Objects.equals(user.getId(), bindUserId)) {
 | 
			
		||||
            throw exception(BROKERAGE_BIND_SELF);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 下级不能绑定自己的上级
 | 
			
		||||
        // 3. 下级不能绑定自己的上级
 | 
			
		||||
        for (int i = 0; i <= Short.MAX_VALUE; i++) {
 | 
			
		||||
            if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
 | 
			
		||||
                throw exception(BROKERAGE_BIND_LOOP);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user