trade: 增加交易中心配置表

This commit is contained in:
owen 2023-09-05 22:31:36 +08:00
parent 9eb7837b67
commit 6474502738
10 changed files with 384 additions and 20 deletions

View File

@ -1,24 +1,25 @@
-- 增加配置
alter table member_point_config
add column brokerage_enabled bit default 1 not null comment '是否启用分佣';
alter table member_point_config
add column brokerage_enabled_condition tinyint default 0 not null comment '分佣模式0-人人分销 1-指定分销';
alter table member_point_config
add column brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人1-新用户';
alter table member_point_config
add column brokerage_post_urls varchar(2000) null comment '分销海报图地址数组';
alter table member_point_config
add column brokerage_first_percent int not null comment '一级返佣比例';
alter table member_point_config
add column brokerage_second_percent int not null comment '二级返佣比例';
alter table member_point_config
add column brokerage_withdraw_min_price int not null comment '用户提现最低金额';
alter table member_point_config
add column brokerage_bank_names varchar(200) not null comment '提现银行字典类型=brokerage_bank_name';
alter table member_point_config
add column brokerage_frozen_days int default 7 not null comment '佣金冻结时间()';
alter table member_point_config
add column brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式1-钱包2-银行卡3-微信4-支付宝';
create table trade_config
(
id bigint auto_increment comment '自增主键'
primary key,
brokerage_enabled bit default 1 not null comment '是否启用分佣',
brokerage_enabled_condition tinyint default 0 not null comment '分佣模式0-人人分销 1-指定分销',
brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人1-新用户',
brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组',
brokerage_first_percent int default 0 not null comment '一级返佣比例',
brokerage_second_percent int default 0 not null comment '二级返佣比例',
brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额',
brokerage_bank_names varchar(200) default '' not null comment '提现银行字典类型=brokerage_bank_name',
brokerage_frozen_days int default 7 not null comment '佣金冻结时间()',
brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式1-钱包2-银行卡3-微信4-支付宝',
creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
deleted bit default b'0' not null comment '是否删除',
tenant_id bigint default 0 not null comment '租户编号'
) comment '交易中心配置';
-- 用户表增加分销相关字段
alter table member_user
@ -187,3 +188,17 @@ SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('佣金提现查询', 'member:brokerage-withdraw:query', 3, 1, @parentId, '', '', '', 0);
-- 交易中心配置菜单 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name)
VALUES ('交易中心配置', '', 2, 0, 2072, 'config', '', 'trade/config/index', 0, 'TradeConfig');
-- 按钮父菜单ID
-- 暂时只支持 MySQL如果你是 OraclePostgreSQLSQLServer 的话需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('交易中心配置查询', 'trade:config:query', 3, 1, @parentId, '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES ('交易中心配置保存', 'trade:config:save', 3, 2, @parentId, '', '', '', 0);

View File

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.trade.controller.admin.config;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 交易中心配置")
@RestController
@RequestMapping("/trade/config")
@Validated
public class TradeConfigController {
@Resource
private TradeConfigService tradeConfigService;
@PutMapping("/save")
@Operation(summary = "更新交易中心配置")
@PreAuthorize("@ss.hasPermission('trade:config:save')")
public CommonResult<Boolean> updateConfig(@Valid @RequestBody TradeConfigSaveReqVO updateReqVO) {
tradeConfigService.saveTradeConfig(updateReqVO);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得交易中心配置")
@PreAuthorize("@ss.hasPermission('trade:config:query')")
public CommonResult<TradeConfigRespVO> getConfig() {
TradeConfigDO config = tradeConfigService.getTradeConfig();
return success(TradeConfigConvert.INSTANCE.convert(config));
}
}

View File

@ -0,0 +1,71 @@
package cn.iocoder.yudao.module.trade.controller.admin.config.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum;
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum;
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import java.util.List;
/**
* 交易中心配置 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class TradeConfigBaseVO {
// ========== 分销相关 ==========
@Schema(description = "是否启用分佣", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "是否启用分佣不能为空")
private Boolean brokerageEnabled;
@Schema(description = "分佣模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
@NotNull(message = "分佣模式不能为空")
@InEnum(value = BrokerageEnabledConditionEnum.class, message = "分佣模式必须是 {value}")
private Integer brokerageEnabledCondition;
@Schema(description = "分销关系绑定模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
@NotNull(message = "分销关系绑定模式不能为空")
@InEnum(value = BrokerageBindModeEnum.class, message = "分销关系绑定模式必须是 {value}")
private Integer brokerageBindMode;
@Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]")
private List<String> brokeragePostUrls;
@Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
@NotNull(message = "一级返佣比例不能为空")
@Range(min = 0, max = 100, message = "一级返佣比例必须在 0 - 100 之间")
private Integer brokerageFirstPercent;
@Schema(description = "二级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
@NotNull(message = "二级返佣比例不能为空")
@Range(min = 0, max = 100, message = "二级返佣比例必须在 0 - 100 之间")
private Integer brokerageSecondPercent;
@Schema(description = "用户提现最低金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
@NotNull(message = "用户提现最低金额不能为空")
@PositiveOrZero(message = "用户提现最低金额不能是负数")
private Integer brokerageWithdrawMinPrice;
@Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]")
@NotEmpty(message = "提现银行不能为空")
private List<Integer> brokerageBankNames;
@Schema(description = "佣金冻结时间(天)", requiredMode = Schema.RequiredMode.REQUIRED, example = "7")
@NotNull(message = "佣金冻结时间(天)不能为空")
@PositiveOrZero(message = "佣金冻结时间不能是负数")
private Integer brokerageFrozenDays;
@Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]")
@NotNull(message = "提现方式不能为空")
@InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}")
private List<Integer> brokerageWithdrawType;
}

View File

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.trade.controller.admin.config.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 交易中心配置 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TradeConfigRespVO extends TradeConfigBaseVO {
@Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.trade.controller.admin.config.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 交易中心配置更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TradeConfigSaveReqVO extends TradeConfigBaseVO {
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.trade.convert.config;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* 交易中心配置 Convert
*
* @author owen
*/
@Mapper
public interface TradeConfigConvert {
TradeConfigConvert INSTANCE = Mappers.getMapper(TradeConfigConvert.class);
TradeConfigDO convert(TradeConfigSaveReqVO bean);
TradeConfigRespVO convert(TradeConfigDO bean);
}

View File

@ -0,0 +1,90 @@
package cn.iocoder.yudao.module.trade.dal.dataobject.config;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler;
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum;
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum;
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import java.util.List;
/**
* 交易中心配置 DO
*
* @author owen
*/
@TableName(value = "trade_config", autoResultMap = true)
@KeySequence("trade_config_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TradeConfigDO extends BaseDO {
/**
* 自增主键
*/
@TableId
private Long id;
// ========== 分销相关 ==========
/**
* 是否启用分佣
*/
private Boolean brokerageEnabled;
/**
* 分佣模式
* <p>
* 枚举 {@link BrokerageEnabledConditionEnum 对应的类}
*/
private Integer brokerageEnabledCondition;
/**
* 分销关系绑定模式
* <p>
* 枚举 {@link BrokerageBindModeEnum 对应的类}
*/
private Integer brokerageBindMode;
/**
* 分销海报图地址数组
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> brokeragePostUrls;
/**
* 一级返佣比例
*/
private Integer brokerageFirstPercent;
/**
* 二级返佣比例
*/
private Integer brokerageSecondPercent;
/**
* 用户提现最低金额
*/
private Integer brokerageWithdrawMinPrice;
/**
* 提现银行
*/
@TableField(typeHandler = IntegerListTypeHandler.class)
private List<Integer> brokerageBankNames;
/**
* 佣金冻结时间()
*/
private Integer brokerageFrozenDays;
/**
* 提现方式
* <p>
* 枚举 {@link BrokerageWithdrawTypeEnum 对应的类}
*/
@TableField(typeHandler = IntegerListTypeHandler.class)
private List<Integer> brokerageWithdrawType;
}

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.trade.dal.mysql.config;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 交易中心配置 Mapper
*
* @author owen
*/
@Mapper
public interface TradeConfigMapper extends BaseMapperX<TradeConfigDO> {
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.trade.service.config;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import javax.validation.Valid;
/**
* 交易中心配置 Service 接口
*
* @author owen
*/
public interface TradeConfigService {
/**
* 更新交易中心配置
*
* @param updateReqVO 更新信息
*/
void saveTradeConfig(@Valid TradeConfigSaveReqVO updateReqVO);
/**
* 获得交易中心配置
*
* @return 交易中心配置
*/
TradeConfigDO getTradeConfig();
}

View File

@ -0,0 +1,44 @@
package cn.iocoder.yudao.module.trade.service.config;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
import cn.iocoder.yudao.module.trade.dal.mysql.config.TradeConfigMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
/**
* 交易中心配置 Service 实现类
*
* @author owen
*/
@Service
@Validated
public class TradeConfigServiceImpl implements TradeConfigService {
@Resource
private TradeConfigMapper tradeConfigMapper;
@Override
public void saveTradeConfig(TradeConfigSaveReqVO saveReqVO) {
// 存在则进行更新
TradeConfigDO dbConfig = getTradeConfig();
if (dbConfig != null) {
tradeConfigMapper.updateById(TradeConfigConvert.INSTANCE.convert(saveReqVO).setId(dbConfig.getId()));
return;
}
// 不存在则进行插入
tradeConfigMapper.insert(TradeConfigConvert.INSTANCE.convert(saveReqVO));
}
@Override
public TradeConfigDO getTradeConfig() {
List<TradeConfigDO> list = tradeConfigMapper.selectList();
return CollectionUtils.getFirst(list);
}
}