mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
MALL-TRADE:新增 BrokerageUserService#getOrCreateBrokerageUser 获得或创建分销用户方法,解决父级推广人不存在的问题
This commit is contained in:
parent
ea7f923072
commit
ae493e66df
@ -1,7 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.trade.controller.app.brokerage;
|
package cn.iocoder.yudao.module.trade.controller.app.brokerage;
|
||||||
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.util.ObjUtil;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||||
@ -11,8 +10,6 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*;
|
|||||||
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
|
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
|
||||||
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
|
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
|
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum;
|
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
|
||||||
@ -20,7 +17,6 @@ import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
|
|||||||
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
|
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
|
||||||
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
|
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
|
||||||
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO;
|
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO;
|
||||||
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -55,22 +51,16 @@ public class AppBrokerageUserController {
|
|||||||
@Resource
|
@Resource
|
||||||
private BrokerageWithdrawService brokerageWithdrawService;
|
private BrokerageWithdrawService brokerageWithdrawService;
|
||||||
@Resource
|
@Resource
|
||||||
private TradeConfigService tradeConfigService;
|
|
||||||
@Resource
|
|
||||||
private MemberUserApi memberUserApi;
|
private MemberUserApi memberUserApi;
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "获得个人分销信息")
|
@Operation(summary = "获得个人分销信息")
|
||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
|
public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
|
||||||
Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId()));
|
Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getOrCreateBrokerageUser(getLoginUserId()));
|
||||||
// 获得交易中心配置
|
|
||||||
TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
|
|
||||||
// 如果是人人分佣 BrokerageUserDO 为 null 时,也有分销资格
|
|
||||||
boolean brokerageEnabled = ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(), tradeConfig.getBrokerageEnabledCondition());
|
|
||||||
// 返回数据
|
// 返回数据
|
||||||
AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
|
AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
|
||||||
.setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(brokerageEnabled))
|
.setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false))
|
||||||
.setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0))
|
.setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0))
|
||||||
.setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0));
|
.setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0));
|
||||||
return success(respVO);
|
return success(respVO);
|
||||||
|
@ -8,7 +8,7 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
|
|
||||||
@Schema(description = "应用 App - 绑定推广员 Request VO")
|
@Schema(description = "应用 App - 绑定推广员 Request VO")
|
||||||
@Data
|
@Data
|
||||||
public class AppBrokerageUserBindReqVO extends PageParam {
|
public class AppBrokerageUserBindReqVO {
|
||||||
|
|
||||||
@Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
@Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||||
@NotNull(message = "推广员编号不能为空")
|
@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.AppBrokerageUserRankByUserCountRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -67,6 +67,14 @@ public interface BrokerageUserService {
|
|||||||
*/
|
*/
|
||||||
BrokerageUserDO getBindBrokerageUser(Long id);
|
BrokerageUserDO getBindBrokerageUser(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得或创建分销用户
|
||||||
|
*
|
||||||
|
* @param id 用户编号
|
||||||
|
* @return 分销用户
|
||||||
|
*/
|
||||||
|
BrokerageUserDO getOrCreateBrokerageUser(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户佣金
|
* 更新用户佣金
|
||||||
*
|
*
|
||||||
@ -134,4 +142,5 @@ public interface BrokerageUserService {
|
|||||||
* @return 下级分销统计分页
|
* @return 下级分销统计分页
|
||||||
*/
|
*/
|
||||||
PageResult<AppBrokerageUserChildSummaryRespVO> getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId);
|
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.lang.Assert;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.BooleanUtil;
|
import cn.hutool.core.util.BooleanUtil;
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
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.enums.brokerage.BrokerageRecordStatusEnum;
|
||||||
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -127,6 +128,18 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
|||||||
.orElse(null);
|
.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
|
@Override
|
||||||
public boolean updateUserPrice(Long id, Integer price) {
|
public boolean updateUserPrice(Long id, Integer price) {
|
||||||
if (price > 0) {
|
if (price > 0) {
|
||||||
@ -184,7 +197,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
|||||||
if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
|
if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
|
||||||
brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
|
brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now());
|
|
||||||
brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
|
brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
|
||||||
} else {
|
} else {
|
||||||
brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
|
brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
|
||||||
@ -294,18 +306,23 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void validateCanBindUser(BrokerageUserDO user, Long bindUserId) {
|
private void validateCanBindUser(BrokerageUserDO user, Long bindUserId) {
|
||||||
// 校验要绑定的用户有无推广资格
|
// 1.1 校验推广人是否存在
|
||||||
BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId);
|
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())) {
|
if (bindUser == null || BooleanUtil.isFalse(bindUser.getBrokerageEnabled())) {
|
||||||
throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
|
throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验绑定自己
|
// 2. 校验绑定自己
|
||||||
if (Objects.equals(user.getId(), bindUserId)) {
|
if (Objects.equals(user.getId(), bindUserId)) {
|
||||||
throw exception(BROKERAGE_BIND_SELF);
|
throw exception(BROKERAGE_BIND_SELF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下级不能绑定自己的上级
|
// 3. 下级不能绑定自己的上级
|
||||||
for (int i = 0; i <= Short.MAX_VALUE; i++) {
|
for (int i = 0; i <= Short.MAX_VALUE; i++) {
|
||||||
if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
|
if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
|
||||||
throw exception(BROKERAGE_BIND_LOOP);
|
throw exception(BROKERAGE_BIND_LOOP);
|
||||||
|
Loading…
Reference in New Issue
Block a user