Commit 64745027380a7e4d99cda3d5af2d393c084171c5

Authored by owen
1 parent 9eb7837b

trade: 增加交易中心配置表

sql/mysql/brokerage.sql
1 1 -- 增加配置
2   -alter table member_point_config
3   - add column brokerage_enabled bit default 1 not null comment '是否启用分佣';
4   -alter table member_point_config
5   - add column brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销';
6   -alter table member_point_config
7   - add column brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户';
8   -alter table member_point_config
9   - add column brokerage_post_urls varchar(2000) null comment '分销海报图地址数组';
10   -alter table member_point_config
11   - add column brokerage_first_percent int not null comment '一级返佣比例';
12   -alter table member_point_config
13   - add column brokerage_second_percent int not null comment '二级返佣比例';
14   -alter table member_point_config
15   - add column brokerage_withdraw_min_price int not null comment '用户提现最低金额';
16   -alter table member_point_config
17   - add column brokerage_bank_names varchar(200) not null comment '提现银行(字典类型=brokerage_bank_name)';
18   -alter table member_point_config
19   - add column brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)';
20   -alter table member_point_config
21   - add column brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝';
  2 +create table trade_config
  3 +(
  4 + id bigint auto_increment comment '自增主键'
  5 + primary key,
  6 + brokerage_enabled bit default 1 not null comment '是否启用分佣',
  7 + brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销',
  8 + brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户',
  9 + brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组',
  10 + brokerage_first_percent int default 0 not null comment '一级返佣比例',
  11 + brokerage_second_percent int default 0 not null comment '二级返佣比例',
  12 + brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额',
  13 + brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)',
  14 + brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)',
  15 + brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝',
  16 + creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者',
  17 + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
  18 + updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者',
  19 + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
  20 + deleted bit default b'0' not null comment '是否删除',
  21 + tenant_id bigint default 0 not null comment '租户编号'
  22 +) comment '交易中心配置';
22 23  
23 24 -- 用户表增加分销相关字段
24 25 alter table member_user
... ... @@ -187,3 +188,17 @@ SELECT @parentId := LAST_INSERT_ID();
187 188 -- 按钮 SQL
188 189 INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
189 190 VALUES ('佣金提现查询', 'member:brokerage-withdraw:query', 3, 1, @parentId, '', '', '', 0);
  191 +
  192 +-- 交易中心配置:菜单 SQL
  193 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
  194 +VALUES ('交易中心配置', '', 2, 0, 2072, 'config', '', 'trade/config/index', 0, 'TradeConfig');
  195 +
  196 +-- 按钮父菜单ID
  197 +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
  198 +SELECT @parentId := LAST_INSERT_ID();
  199 +
  200 +-- 按钮 SQL
  201 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  202 +VALUES ('交易中心配置查询', 'trade:config:query', 3, 1, @parentId, '', '', '', 0);
  203 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
  204 +VALUES ('交易中心配置保存', 'trade:config:save', 3, 2, @parentId, '', '', '', 0);
190 205 \ No newline at end of file
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/TradeConfigController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.controller.admin.config;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO;
  5 +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
  6 +import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert;
  7 +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
  8 +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
  9 +import io.swagger.v3.oas.annotations.Operation;
  10 +import io.swagger.v3.oas.annotations.tags.Tag;
  11 +import org.springframework.security.access.prepost.PreAuthorize;
  12 +import org.springframework.validation.annotation.Validated;
  13 +import org.springframework.web.bind.annotation.*;
  14 +
  15 +import javax.annotation.Resource;
  16 +import javax.validation.Valid;
  17 +
  18 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  19 +
  20 +@Tag(name = "管理后台 - 交易中心配置")
  21 +@RestController
  22 +@RequestMapping("/trade/config")
  23 +@Validated
  24 +public class TradeConfigController {
  25 +
  26 + @Resource
  27 + private TradeConfigService tradeConfigService;
  28 +
  29 + @PutMapping("/save")
  30 + @Operation(summary = "更新交易中心配置")
  31 + @PreAuthorize("@ss.hasPermission('trade:config:save')")
  32 + public CommonResult<Boolean> updateConfig(@Valid @RequestBody TradeConfigSaveReqVO updateReqVO) {
  33 + tradeConfigService.saveTradeConfig(updateReqVO);
  34 + return success(true);
  35 + }
  36 +
  37 + @GetMapping("/get")
  38 + @Operation(summary = "获得交易中心配置")
  39 + @PreAuthorize("@ss.hasPermission('trade:config:query')")
  40 + public CommonResult<TradeConfigRespVO> getConfig() {
  41 + TradeConfigDO config = tradeConfigService.getTradeConfig();
  42 + return success(TradeConfigConvert.INSTANCE.convert(config));
  43 + }
  44 +
  45 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.controller.admin.config.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  4 +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum;
  5 +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum;
  6 +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum;
  7 +import io.swagger.v3.oas.annotations.media.Schema;
  8 +import lombok.Data;
  9 +import org.hibernate.validator.constraints.Range;
  10 +
  11 +import javax.validation.constraints.NotEmpty;
  12 +import javax.validation.constraints.NotNull;
  13 +import javax.validation.constraints.PositiveOrZero;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * 交易中心配置 Base VO,提供给添加、修改、详细的子 VO 使用
  18 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  19 + */
  20 +@Data
  21 +public class TradeConfigBaseVO {
  22 +
  23 + // ========== 分销相关 ==========
  24 +
  25 + @Schema(description = "是否启用分佣", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  26 + @NotNull(message = "是否启用分佣不能为空")
  27 + private Boolean brokerageEnabled;
  28 +
  29 + @Schema(description = "分佣模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
  30 + @NotNull(message = "分佣模式不能为空")
  31 + @InEnum(value = BrokerageEnabledConditionEnum.class, message = "分佣模式必须是 {value}")
  32 + private Integer brokerageEnabledCondition;
  33 +
  34 + @Schema(description = "分销关系绑定模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
  35 + @NotNull(message = "分销关系绑定模式不能为空")
  36 + @InEnum(value = BrokerageBindModeEnum.class, message = "分销关系绑定模式必须是 {value}")
  37 + private Integer brokerageBindMode;
  38 +
  39 + @Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]")
  40 + private List<String> brokeragePostUrls;
  41 +
  42 + @Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  43 + @NotNull(message = "一级返佣比例不能为空")
  44 + @Range(min = 0, max = 100, message = "一级返佣比例必须在 0 - 100 之间")
  45 + private Integer brokerageFirstPercent;
  46 +
  47 + @Schema(description = "二级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  48 + @NotNull(message = "二级返佣比例不能为空")
  49 + @Range(min = 0, max = 100, message = "二级返佣比例必须在 0 - 100 之间")
  50 + private Integer brokerageSecondPercent;
  51 +
  52 + @Schema(description = "用户提现最低金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
  53 + @NotNull(message = "用户提现最低金额不能为空")
  54 + @PositiveOrZero(message = "用户提现最低金额不能是负数")
  55 + private Integer brokerageWithdrawMinPrice;
  56 +
  57 + @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]")
  58 + @NotEmpty(message = "提现银行不能为空")
  59 + private List<Integer> brokerageBankNames;
  60 +
  61 + @Schema(description = "佣金冻结时间(天)", requiredMode = Schema.RequiredMode.REQUIRED, example = "7")
  62 + @NotNull(message = "佣金冻结时间(天)不能为空")
  63 + @PositiveOrZero(message = "佣金冻结时间不能是负数")
  64 + private Integer brokerageFrozenDays;
  65 +
  66 + @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]")
  67 + @NotNull(message = "提现方式不能为空")
  68 + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}")
  69 + private List<Integer> brokerageWithdrawType;
  70 +
  71 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.controller.admin.config.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +@Schema(description = "管理后台 - 交易中心配置 Response VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class TradeConfigRespVO extends TradeConfigBaseVO {
  13 +
  14 + @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  15 + private Long id;
  16 +
  17 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.controller.admin.config.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +@Schema(description = "管理后台 - 交易中心配置更新 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class TradeConfigSaveReqVO extends TradeConfigBaseVO {
  13 +
  14 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.convert.config;
  2 +
  3 +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO;
  4 +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
  5 +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
  6 +import org.mapstruct.Mapper;
  7 +import org.mapstruct.factory.Mappers;
  8 +
  9 +/**
  10 + * 交易中心配置 Convert
  11 + *
  12 + * @author owen
  13 + */
  14 +@Mapper
  15 +public interface TradeConfigConvert {
  16 +
  17 + TradeConfigConvert INSTANCE = Mappers.getMapper(TradeConfigConvert.class);
  18 +
  19 + TradeConfigDO convert(TradeConfigSaveReqVO bean);
  20 +
  21 + TradeConfigRespVO convert(TradeConfigDO bean);
  22 +
  23 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.dal.dataobject.config;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler;
  5 +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum;
  6 +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum;
  7 +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum;
  8 +import com.baomidou.mybatisplus.annotation.KeySequence;
  9 +import com.baomidou.mybatisplus.annotation.TableField;
  10 +import com.baomidou.mybatisplus.annotation.TableId;
  11 +import com.baomidou.mybatisplus.annotation.TableName;
  12 +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
  13 +import lombok.*;
  14 +
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * 交易中心配置 DO
  19 + *
  20 + * @author owen
  21 + */
  22 +@TableName(value = "trade_config", autoResultMap = true)
  23 +@KeySequence("trade_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  24 +@Data
  25 +@EqualsAndHashCode(callSuper = true)
  26 +@ToString(callSuper = true)
  27 +@Builder
  28 +@NoArgsConstructor
  29 +@AllArgsConstructor
  30 +public class TradeConfigDO extends BaseDO {
  31 +
  32 + /**
  33 + * 自增主键
  34 + */
  35 + @TableId
  36 + private Long id;
  37 +
  38 + // ========== 分销相关 ==========
  39 +
  40 + /**
  41 + * 是否启用分佣
  42 + */
  43 + private Boolean brokerageEnabled;
  44 + /**
  45 + * 分佣模式
  46 + * <p>
  47 + * 枚举 {@link BrokerageEnabledConditionEnum 对应的类}
  48 + */
  49 + private Integer brokerageEnabledCondition;
  50 + /**
  51 + * 分销关系绑定模式
  52 + * <p>
  53 + * 枚举 {@link BrokerageBindModeEnum 对应的类}
  54 + */
  55 + private Integer brokerageBindMode;
  56 + /**
  57 + * 分销海报图地址数组
  58 + */
  59 + @TableField(typeHandler = JacksonTypeHandler.class)
  60 + private List<String> brokeragePostUrls;
  61 + /**
  62 + * 一级返佣比例
  63 + */
  64 + private Integer brokerageFirstPercent;
  65 + /**
  66 + * 二级返佣比例
  67 + */
  68 + private Integer brokerageSecondPercent;
  69 + /**
  70 + * 用户提现最低金额
  71 + */
  72 + private Integer brokerageWithdrawMinPrice;
  73 + /**
  74 + * 提现银行
  75 + */
  76 + @TableField(typeHandler = IntegerListTypeHandler.class)
  77 + private List<Integer> brokerageBankNames;
  78 + /**
  79 + * 佣金冻结时间(天)
  80 + */
  81 + private Integer brokerageFrozenDays;
  82 + /**
  83 + * 提现方式
  84 + * <p>
  85 + * 枚举 {@link BrokerageWithdrawTypeEnum 对应的类}
  86 + */
  87 + @TableField(typeHandler = IntegerListTypeHandler.class)
  88 + private List<Integer> brokerageWithdrawType;
  89 +
  90 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/config/TradeConfigMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.dal.mysql.config;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
  5 +import org.apache.ibatis.annotations.Mapper;
  6 +
  7 +/**
  8 + * 交易中心配置 Mapper
  9 + *
  10 + * @author owen
  11 + */
  12 +@Mapper
  13 +public interface TradeConfigMapper extends BaseMapperX<TradeConfigDO> {
  14 +
  15 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.service.config;
  2 +
  3 +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
  4 +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
  5 +
  6 +import javax.validation.Valid;
  7 +
  8 +/**
  9 + * 交易中心配置 Service 接口
  10 + *
  11 + * @author owen
  12 + */
  13 +public interface TradeConfigService {
  14 +
  15 +
  16 + /**
  17 + * 更新交易中心配置
  18 + *
  19 + * @param updateReqVO 更新信息
  20 + */
  21 + void saveTradeConfig(@Valid TradeConfigSaveReqVO updateReqVO);
  22 +
  23 + /**
  24 + * 获得交易中心配置
  25 + *
  26 + * @return 交易中心配置
  27 + */
  28 + TradeConfigDO getTradeConfig();
  29 +
  30 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.service.config;
  2 +
  3 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
  4 +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
  5 +import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert;
  6 +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
  7 +import cn.iocoder.yudao.module.trade.dal.mysql.config.TradeConfigMapper;
  8 +import org.springframework.stereotype.Service;
  9 +import org.springframework.validation.annotation.Validated;
  10 +
  11 +import javax.annotation.Resource;
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * 交易中心配置 Service 实现类
  16 + *
  17 + * @author owen
  18 + */
  19 +@Service
  20 +@Validated
  21 +public class TradeConfigServiceImpl implements TradeConfigService {
  22 +
  23 + @Resource
  24 + private TradeConfigMapper tradeConfigMapper;
  25 +
  26 + @Override
  27 + public void saveTradeConfig(TradeConfigSaveReqVO saveReqVO) {
  28 + // 存在,则进行更新
  29 + TradeConfigDO dbConfig = getTradeConfig();
  30 + if (dbConfig != null) {
  31 + tradeConfigMapper.updateById(TradeConfigConvert.INSTANCE.convert(saveReqVO).setId(dbConfig.getId()));
  32 + return;
  33 + }
  34 + // 不存在,则进行插入
  35 + tradeConfigMapper.insert(TradeConfigConvert.INSTANCE.convert(saveReqVO));
  36 + }
  37 +
  38 + @Override
  39 + public TradeConfigDO getTradeConfig() {
  40 + List<TradeConfigDO> list = tradeConfigMapper.selectList();
  41 + return CollectionUtils.getFirst(list);
  42 + }
  43 +
  44 +}
... ...