trade: MemberBrokerageRecord 重命名为 TradeBrokerageRecord

This commit is contained in:
owen 2023-09-06 00:35:40 +08:00
parent 9336a0a102
commit fa53a3b15e
20 changed files with 183 additions and 183 deletions

View File

@ -42,7 +42,7 @@ create index idx_invite_user_id on trade_brokerage_user (brokerage_user_id) comm
create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员';
create table member_brokerage_record
create table trade_brokerage_record
(
id int auto_increment comment '编号'
primary key,
@ -65,12 +65,12 @@ create table member_brokerage_record
)
comment '佣金记录';
create index idx_user_id on member_brokerage_record (user_id) comment '用户编号';
create index idx_biz on member_brokerage_record (biz_type, biz_id) comment '业务';
create index idx_status on member_brokerage_record (status) comment '状态';
create index idx_user_id on trade_brokerage_record (user_id) comment '用户编号';
create index idx_biz on trade_brokerage_record (biz_type, biz_id) comment '业务';
create index idx_status on trade_brokerage_record (status) comment '状态';
create table member_brokerage_withdraw
create table trade_brokerage_withdraw
(
id int auto_increment comment '编号'
primary key,
@ -97,8 +97,8 @@ create table member_brokerage_withdraw
)
comment '佣金提现';
create index idx_user_id on member_brokerage_withdraw (user_id) comment '用户编号';
create index idx_audit_status on member_brokerage_withdraw (status) comment '状态';
create index idx_user_id on trade_brokerage_withdraw (user_id) comment '用户编号';
create index idx_audit_status on trade_brokerage_withdraw (status) comment '状态';
-- 增加字典
insert into system_dict_type(type, name)

View File

@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO;
import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO;
import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -24,28 +24,28 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 佣金记录")
@RestController
@RequestMapping("/trade/member-brokerage-record")
@RequestMapping("/trade/brokerage-record")
@Validated
public class MemberBrokerageRecordController {
public class TradeBrokerageRecordController {
@Resource
private MemberBrokerageRecordService memberBrokerageRecordService;
private TradeBrokerageRecordService tradeBrokerageRecordService;
@GetMapping("/get")
@Operation(summary = "获得佣金记录")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')")
public CommonResult<MemberBrokerageRecordRespVO> getMemberBrokerageRecord(@RequestParam("id") Integer id) {
MemberBrokerageRecordDO memberBrokerageRecord = memberBrokerageRecordService.getMemberBrokerageRecord(id);
return success(MemberBrokerageRecordConvert.INSTANCE.convert(memberBrokerageRecord));
@PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')")
public CommonResult<TradeBrokerageRecordRespVO> getBrokerageRecord(@RequestParam("id") Integer id) {
TradeBrokerageRecordDO tradeBrokerageRecord = tradeBrokerageRecordService.getBrokerageRecord(id);
return success(TradeBrokerageRecordConvert.INSTANCE.convert(tradeBrokerageRecord));
}
@GetMapping("/page")
@Operation(summary = "获得佣金记录分页")
@PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')")
public CommonResult<PageResult<MemberBrokerageRecordRespVO>> getMemberBrokerageRecordPage(@Valid MemberBrokerageRecordPageReqVO pageVO) {
PageResult<MemberBrokerageRecordDO> pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(pageVO);
return success(MemberBrokerageRecordConvert.INSTANCE.convertPage(pageResult));
@PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')")
public CommonResult<PageResult<TradeBrokerageRecordRespVO>> getBrokerageRecordPage(@Valid TradeBrokerageRecordPageReqVO pageVO) {
PageResult<TradeBrokerageRecordDO> pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(pageVO);
return success(TradeBrokerageRecordConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -14,7 +14,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class MemberBrokerageRecordBaseVO {
public class TradeBrokerageRecordBaseVO {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25973")
@NotNull(message = "用户编号不能为空")

View File

@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MemberBrokerageRecordPageReqVO extends PageParam {
public class TradeBrokerageRecordPageReqVO extends PageParam {
@Schema(description = "用户编号", example = "25973")
private Long userId;

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MemberBrokerageRecordRespVO extends MemberBrokerageRecordBaseVO {
public class TradeBrokerageRecordRespVO extends TradeBrokerageRecordBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28896")
private Integer id;

View File

@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.record;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
@ -19,22 +19,22 @@ import java.util.List;
* @author owen
*/
@Mapper
public interface MemberBrokerageRecordConvert {
public interface TradeBrokerageRecordConvert {
MemberBrokerageRecordConvert INSTANCE = Mappers.getMapper(MemberBrokerageRecordConvert.class);
TradeBrokerageRecordConvert INSTANCE = Mappers.getMapper(TradeBrokerageRecordConvert.class);
MemberBrokerageRecordRespVO convert(MemberBrokerageRecordDO bean);
TradeBrokerageRecordRespVO convert(TradeBrokerageRecordDO bean);
List<MemberBrokerageRecordRespVO> convertList(List<MemberBrokerageRecordDO> list);
List<TradeBrokerageRecordRespVO> convertList(List<TradeBrokerageRecordDO> list);
PageResult<MemberBrokerageRecordRespVO> convertPage(PageResult<MemberBrokerageRecordDO> page);
PageResult<TradeBrokerageRecordRespVO> convertPage(PageResult<TradeBrokerageRecordDO> page);
default MemberBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) {
default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) {
// 不冻结时佣金直接就是结算状态
Integer status = brokerageFrozenDays > 0
? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus()
: BrokerageRecordStatusEnum.SETTLEMENT.getStatus();
return new MemberBrokerageRecordDO()
return new TradeBrokerageRecordDO()
.setUserId(user.getId())
.setBizType(BrokerageRecordBizTypeEnum.ORDER.getType())
.setBizId(bizId)

View File

@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.pay.enums.DictTypeConstants;
@ -275,8 +275,8 @@ public interface TradeOrderConvert {
TradeOrderDO convert(TradeOrderRemarkReqVO reqVO);
default BrokerageAddReqDTO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) {
return new BrokerageAddReqDTO().setBizId(String.valueOf(item.getId()))
default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) {
return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId()))
.setPayPrice(item.getPayPrice()).setCount(item.getCount())
.setSkuFirstBrokeragePrice(sku.getSubCommissionFirstPrice())
.setSkuSecondBrokeragePrice(sku.getSubCommissionSecondPrice());

View File

@ -15,15 +15,15 @@ import java.time.LocalDateTime;
*
* @author owen
*/
@TableName("member_brokerage_record")
@KeySequence("member_brokerage_record_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@TableName("trade_brokerage_record")
@KeySequence("trade_brokerage_record_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MemberBrokerageRecordDO extends BaseDO {
public class TradeBrokerageRecordDO extends BaseDO {
/**
* 编号

View File

@ -1,47 +0,0 @@
package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.List;
/**
* 佣金记录 Mapper
*
* @author owen
*/
@Mapper
public interface MemberBrokerageRecordMapper extends BaseMapperX<MemberBrokerageRecordDO> {
default PageResult<MemberBrokerageRecordDO> selectPage(MemberBrokerageRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MemberBrokerageRecordDO>()
.eqIfPresent(MemberBrokerageRecordDO::getUserId, reqVO.getUserId())
.eqIfPresent(MemberBrokerageRecordDO::getBizType, reqVO.getBizType())
.eqIfPresent(MemberBrokerageRecordDO::getStatus, reqVO.getStatus())
.betweenIfPresent(MemberBrokerageRecordDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MemberBrokerageRecordDO::getId));
}
default List<MemberBrokerageRecordDO> selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) {
return selectList(new LambdaQueryWrapper<MemberBrokerageRecordDO>()
.eq(MemberBrokerageRecordDO::getStatus, status)
.lt(MemberBrokerageRecordDO::getUnfreezeTime, unfreezeTime));
}
default int updateByIdAndStatus(Integer id, Integer status, MemberBrokerageRecordDO updateObj) {
return update(updateObj, new LambdaQueryWrapper<MemberBrokerageRecordDO>()
.eq(MemberBrokerageRecordDO::getId, id)
.eq(MemberBrokerageRecordDO::getStatus, status));
}
default MemberBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) {
return selectOne(MemberBrokerageRecordDO::getBizType, bizType,
MemberBrokerageRecordDO::getBizId, bizId);
}
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.List;
/**
* 佣金记录 Mapper
*
* @author owen
*/
@Mapper
public interface TradeBrokerageRecordMapper extends BaseMapperX<TradeBrokerageRecordDO> {
default PageResult<TradeBrokerageRecordDO> selectPage(TradeBrokerageRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<TradeBrokerageRecordDO>()
.eqIfPresent(TradeBrokerageRecordDO::getUserId, reqVO.getUserId())
.eqIfPresent(TradeBrokerageRecordDO::getBizType, reqVO.getBizType())
.eqIfPresent(TradeBrokerageRecordDO::getStatus, reqVO.getStatus())
.betweenIfPresent(TradeBrokerageRecordDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(TradeBrokerageRecordDO::getId));
}
default List<TradeBrokerageRecordDO> selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) {
return selectList(new LambdaQueryWrapper<TradeBrokerageRecordDO>()
.eq(TradeBrokerageRecordDO::getStatus, status)
.lt(TradeBrokerageRecordDO::getUnfreezeTime, unfreezeTime));
}
default int updateByIdAndStatus(Integer id, Integer status, TradeBrokerageRecordDO updateObj) {
return update(updateObj, new LambdaQueryWrapper<TradeBrokerageRecordDO>()
.eq(TradeBrokerageRecordDO::getId, id)
.eq(TradeBrokerageRecordDO::getStatus, status));
}
default TradeBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) {
return selectOne(TradeBrokerageRecordDO::getBizType, bizType,
TradeBrokerageRecordDO::getBizId, bizId);
}
}

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.job.brokerage;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService;
import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -15,14 +15,14 @@ import javax.annotation.Resource;
*/
@Component
@TenantJob
public class MemberBrokerageRecordUnfreezeJob implements JobHandler {
public class TradeBrokerageRecordUnfreezeJob implements JobHandler {
@Resource
private MemberBrokerageRecordService memberBrokerageRecordService;
private TradeBrokerageRecordService tradeBrokerageRecordService;
@Override
public String execute(String param) {
int count = memberBrokerageRecordService.unfreezeRecord();
int count = tradeBrokerageRecordService.unfreezeRecord();
return StrUtil.format("解冻佣金 {} 个", count);
}

View File

@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.trade.service.brokerage.record;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO;
import java.util.List;
@ -12,7 +12,7 @@ import java.util.List;
*
* @author owen
*/
public interface MemberBrokerageRecordService {
public interface TradeBrokerageRecordService {
/**
* 获得佣金记录
@ -20,7 +20,7 @@ public interface MemberBrokerageRecordService {
* @param id 编号
* @return 佣金记录
*/
MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id);
TradeBrokerageRecordDO getBrokerageRecord(Integer id);
/**
* 获得佣金记录分页
@ -28,7 +28,7 @@ public interface MemberBrokerageRecordService {
* @param pageReqVO 分页查询
* @return 佣金记录分页
*/
PageResult<MemberBrokerageRecordDO> getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO);
PageResult<TradeBrokerageRecordDO> getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO);
/**
* 增加佣金
@ -36,7 +36,7 @@ public interface MemberBrokerageRecordService {
* @param userId 会员编号
* @param list 请求参数列表
*/
void addBrokerage(Long userId, List<BrokerageAddReqDTO> list);
void addBrokerage(Long userId, List<BrokerageAddReqBO> list);
/**
* 取消佣金将佣金记录状态修改为已失效

View File

@ -6,13 +6,13 @@ import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.MemberBrokerageRecordMapper;
import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper;
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.brokerage.user.TradeBrokerageUserService;
@ -37,28 +37,28 @@ import java.util.function.Function;
@Slf4j
@Service
@Validated
public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordService {
public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordService {
@Resource
private MemberBrokerageRecordMapper memberBrokerageRecordMapper;
private TradeBrokerageRecordMapper tradeBrokerageRecordMapper;
@Resource
private TradeConfigService tradeConfigService;
@Resource
private TradeBrokerageUserService tradeBrokerageUserService;
@Override
public MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id) {
return memberBrokerageRecordMapper.selectById(id);
public TradeBrokerageRecordDO getBrokerageRecord(Integer id) {
return tradeBrokerageRecordMapper.selectById(id);
}
@Override
public PageResult<MemberBrokerageRecordDO> getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO) {
return memberBrokerageRecordMapper.selectPage(pageReqVO);
public PageResult<TradeBrokerageRecordDO> getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO) {
return tradeBrokerageRecordMapper.selectPage(pageReqVO);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void addBrokerage(Long buyerId, List<BrokerageAddReqDTO> list) {
public void addBrokerage(Long buyerId, List<BrokerageAddReqBO> list) {
TradeConfigDO memberConfig = tradeConfigService.getTradeConfig();
// 0 未启用分销功能
if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) {
@ -73,7 +73,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
}
// 1.2 计算一级分佣
addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqDTO::getSkuFirstBrokeragePrice);
addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice);
// 2.1 获得二级推广员
@ -83,20 +83,20 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
}
// 2.2 计算二级分佣
addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqDTO::getSkuSecondBrokeragePrice);
addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSkuSecondBrokeragePrice);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelBrokerage(Long userId, String bizId) {
MemberBrokerageRecordDO record = memberBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId);
TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId);
if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) {
log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId);
return;
}
MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus());
int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj);
TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus());
int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj);
if (updateRows == 0) {
log.error("[cancelBrokerage][record({}) 更新为已失效失败]", record.getId());
return;
@ -140,8 +140,8 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
* @param brokeragePercent 佣金比例
* @param skuBrokeragePriceFun 商品 SKU 设置的佣金
*/
private void addBrokerage(TradeBrokerageUserDO user, List<BrokerageAddReqDTO> list, Integer brokerageFrozenDays,
Integer brokeragePercent, Function<BrokerageAddReqDTO, Integer> skuBrokeragePriceFun) {
private void addBrokerage(TradeBrokerageUserDO user, List<BrokerageAddReqBO> list, Integer brokerageFrozenDays,
Integer brokeragePercent, Function<BrokerageAddReqBO, Integer> skuBrokeragePriceFun) {
// 处理冻结时间
brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0);
LocalDateTime unfreezeTime = null;
@ -151,12 +151,12 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
// 计算分佣
int totalBrokerage = 0;
List<MemberBrokerageRecordDO> records = new ArrayList<>();
for (BrokerageAddReqDTO dto : list) {
List<TradeBrokerageRecordDO> records = new ArrayList<>();
for (BrokerageAddReqBO dto : list) {
int brokeragePerItem = calculateBrokerage(dto.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(dto));
if (brokeragePerItem > 0) {
int brokerage = brokeragePerItem * dto.getCount();
records.add(MemberBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime));
records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime));
totalBrokerage += brokerage;
}
}
@ -166,7 +166,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
}
// 保存佣金记录
memberBrokerageRecordMapper.insertBatch(records);
tradeBrokerageRecordMapper.insertBatch(records);
if (brokerageFrozenDays > 0) {
// 更新用户冻结佣金
@ -180,7 +180,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
@Override
public int unfreezeRecord() {
// 1. 查询待结算的佣金记录
List<MemberBrokerageRecordDO> records = memberBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt(
List<TradeBrokerageRecordDO> records = tradeBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt(
BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus(), LocalDateTime.now());
if (CollUtil.isEmpty(records)) {
return 0;
@ -188,7 +188,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
// 2. 遍历执行
int count = 0;
for (MemberBrokerageRecordDO record : records) {
for (TradeBrokerageRecordDO record : records) {
try {
boolean successful = getSelf().unfreezeRecord(record);
if (successful) {
@ -202,12 +202,12 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
}
@Transactional(rollbackFor = Exception.class)
public boolean unfreezeRecord(MemberBrokerageRecordDO record) {
public boolean unfreezeRecord(TradeBrokerageRecordDO record) {
// 更新记录状态
MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO()
TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO()
.setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus())
.setUnfreezeTime(LocalDateTime.now());
int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj);
int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj);
if (updateRows == 0) {
log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId());
return false;
@ -225,7 +225,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
*
* @return 自己
*/
private MemberBrokerageRecordServiceImpl getSelf() {
private TradeBrokerageRecordServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}

View File

@ -5,13 +5,13 @@ import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 佣金 增加 Request DTO
* 佣金 增加 Request BO
* @author owen
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BrokerageAddReqDTO {
public class BrokerageAddReqBO {
/**
* 业务ID
*/

View File

@ -12,8 +12,8 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.member.api.address.AddressApi;
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO;
import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService;
import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO;
import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
import cn.iocoder.yudao.module.member.api.point.MemberPointApi;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
@ -120,7 +120,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Resource
private MemberPointApi memberPointApi;
@Resource
private MemberBrokerageRecordService memberBrokerageRecordService;
private TradeBrokerageRecordService tradeBrokerageRecordService;
@Resource
private ProductCommentApi productCommentApi;
@ -752,14 +752,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Async
protected void addBrokerageAsync(Long userId, Long orderId) {
List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(orderId);
List<BrokerageAddReqDTO> list = convertList(orderItems,
List<BrokerageAddReqBO> list = convertList(orderItems,
item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId())));
memberBrokerageRecordService.addBrokerage(userId, list);
tradeBrokerageRecordService.addBrokerage(userId, list);
}
@Async
protected void cancelBrokerageAsync(Long userId, Long orderItemId) {
memberBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId));
tradeBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId));
}
/**

View File

@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record;
import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.MemberBrokerageRecordMapper;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO;
import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper;
import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService;
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
import org.junit.jupiter.api.Disabled;
@ -26,17 +26,17 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* {@link MemberBrokerageRecordServiceImpl} 的单元测试类
* {@link TradeBrokerageRecordServiceImpl} 的单元测试类
*
* @author owen
*/
@Import(MemberBrokerageRecordServiceImpl.class)
public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest {
@Import(TradeBrokerageRecordServiceImpl.class)
public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest {
@Resource
private MemberBrokerageRecordServiceImpl memberBrokerageRecordService;
private TradeBrokerageRecordServiceImpl tradeBrokerageRecordService;
@Resource
private MemberBrokerageRecordMapper memberBrokerageRecordMapper;
private TradeBrokerageRecordMapper tradeBrokerageRecordMapper;
@MockBean
private TradeConfigService tradeConfigService;
@ -45,36 +45,36 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest {
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetMemberBrokerageRecordPage() {
public void testGetBrokerageRecordPage() {
// mock 数据
MemberBrokerageRecordDO dbMemberBrokerageRecord = randomPojo(MemberBrokerageRecordDO.class, o -> { // 等会查询到
TradeBrokerageRecordDO dbBrokerageRecord = randomPojo(TradeBrokerageRecordDO.class, o -> { // 等会查询到
o.setUserId(null);
o.setBizType(null);
o.setStatus(null);
o.setCreateTime(null);
});
memberBrokerageRecordMapper.insert(dbMemberBrokerageRecord);
tradeBrokerageRecordMapper.insert(dbBrokerageRecord);
// 测试 userId 不匹配
memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setUserId(null)));
tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setUserId(null)));
// 测试 bizType 不匹配
memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setBizType(null)));
tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setBizType(null)));
// 测试 status 不匹配
memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setStatus(null)));
tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setStatus(null)));
// 测试 createTime 不匹配
memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setCreateTime(null)));
tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setCreateTime(null)));
// 准备参数
MemberBrokerageRecordPageReqVO reqVO = new MemberBrokerageRecordPageReqVO();
TradeBrokerageRecordPageReqVO reqVO = new TradeBrokerageRecordPageReqVO();
reqVO.setUserId(null);
reqVO.setBizType(null);
reqVO.setStatus(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<MemberBrokerageRecordDO> pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(reqVO);
PageResult<TradeBrokerageRecordDO> pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbMemberBrokerageRecord, pageResult.getList().get(0));
assertPojoEquals(dbBrokerageRecord, pageResult.getList().get(0));
}
@Test
@ -84,7 +84,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest {
Integer percent = randomInt(1, 101);
Integer skuBrokeragePrice = randomInt();
// 调用
int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice);
int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice);
// 断言
assertEquals(brokerage, skuBrokeragePrice);
}
@ -97,7 +97,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest {
Integer skuBrokeragePrice = randomEle(new Integer[]{0, null});
System.out.println("skuBrokeragePrice=" + skuBrokeragePrice);
// 调用
int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice);
int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice);
// 断言
assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue());
}
@ -109,7 +109,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest {
Integer percent = null;
Integer skuBrokeragePrice = null;
// 调用
int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice);
int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice);
// 断言
assertEquals(brokerage, 0);
}

View File

@ -2,4 +2,5 @@ DELETE FROM trade_order;
DELETE FROM trade_order_item;
DELETE FROM trade_after_sale;
DELETE FROM trade_after_sale_log;
DELETE FROM "trade_brokerage_user";
DELETE FROM trade_brokerage_user;
DELETE FROM trade_brokerage_record;

View File

@ -142,4 +142,25 @@ CREATE TABLE IF NOT EXISTS "trade_brokerage_user"
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL DEFAULT '0',
PRIMARY KEY ("id")
) COMMENT '分销用户';
) COMMENT '分销用户';
CREATE TABLE IF NOT EXISTS "trade_brokerage_record"
(
"id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"user_id" bigint NOT NULL,
"biz_id" varchar NOT NULL,
"biz_type" varchar NOT NULL,
"title" varchar NOT NULL,
"price" int NOT NULL,
"total_price" int NOT NULL,
"description" varchar NOT NULL,
"status" varchar NOT NULL,
"frozen_days" int NOT NULL,
"unfreeze_time" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint not null default '0',
PRIMARY KEY ("id")
) COMMENT '佣金记录';

View File

@ -2,5 +2,4 @@ DELETE FROM "member_user";
DELETE FROM "member_address";
DELETE FROM "member_tag";
DELETE FROM "member_level";
DELETE FROM "member_group";
DELETE FROM "member_brokerage_record";
DELETE FROM "member_group";

View File

@ -89,25 +89,4 @@ CREATE TABLE IF NOT EXISTS "member_group"
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint not null default '0',
PRIMARY KEY ("id")
) COMMENT '用户分组';
CREATE TABLE IF NOT EXISTS "member_brokerage_record"
(
"id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"user_id" bigint NOT NULL,
"biz_id" varchar NOT NULL,
"biz_type" varchar NOT NULL,
"title" varchar NOT NULL,
"price" int NOT NULL,
"total_price" int NOT NULL,
"description" varchar NOT NULL,
"status" varchar NOT NULL,
"frozen_days" int NOT NULL,
"unfreeze_time" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint not null default '0',
PRIMARY KEY ("id")
) COMMENT '佣金记录';
) COMMENT '用户分组';