v1.0
This commit is contained in:
@@ -34,6 +34,14 @@ func (l *AdminGetAgentConfigLogic) AdminGetAgentConfig() (resp *types.AdminGetAg
|
||||
value, _ := strconv.ParseFloat(config.ConfigValue, 64)
|
||||
return value
|
||||
}
|
||||
getConfigInt := func(key string) int64 {
|
||||
config, err := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
value, _ := strconv.ParseInt(config.ConfigValue, 10, 64)
|
||||
return value
|
||||
}
|
||||
|
||||
// 获取等级加成配置
|
||||
level1Bonus := getConfigFloat("level_1_bonus")
|
||||
@@ -48,11 +56,20 @@ func (l *AdminGetAgentConfigLogic) AdminGetAgentConfig() (resp *types.AdminGetAg
|
||||
upgradeToGoldRebate := getConfigFloat("upgrade_to_gold_rebate")
|
||||
upgradeToDiamondRebate := getConfigFloat("upgrade_to_diamond_rebate")
|
||||
|
||||
// 获取直接上级返佣配置
|
||||
directParentAmountDiamond := getConfigFloat("direct_parent_amount_diamond")
|
||||
directParentAmountGold := getConfigFloat("direct_parent_amount_gold")
|
||||
directParentAmountNormal := getConfigFloat("direct_parent_amount_normal")
|
||||
|
||||
// 获取黄金代理最大返佣金额
|
||||
maxGoldRebateAmount := getConfigFloat("max_gold_rebate_amount")
|
||||
|
||||
// 获取佣金冻结配置
|
||||
commissionFreezeRatio := getConfigFloat("commission_freeze_ratio")
|
||||
commissionFreezeThreshold := getConfigFloat("commission_freeze_threshold")
|
||||
commissionFreezeDays := getConfigInt("commission_freeze_days")
|
||||
|
||||
return &types.AdminGetAgentConfigResp{
|
||||
BasePrice: getConfigFloat("base_price"),
|
||||
SystemMaxPrice: getConfigFloat("system_max_price"),
|
||||
PriceThreshold: getConfigFloat("price_threshold"),
|
||||
PriceFeeRate: getConfigFloat("price_fee_rate"),
|
||||
LevelBonus: types.LevelBonusConfig{
|
||||
Normal: int64(level1Bonus),
|
||||
Gold: int64(level2Bonus),
|
||||
@@ -67,6 +84,17 @@ func (l *AdminGetAgentConfigLogic) AdminGetAgentConfig() (resp *types.AdminGetAg
|
||||
NormalToGoldRebate: upgradeToGoldRebate,
|
||||
ToDiamondRebate: upgradeToDiamondRebate,
|
||||
},
|
||||
DirectParentRebate: types.DirectParentRebateConfig{
|
||||
Diamond: directParentAmountDiamond,
|
||||
Gold: directParentAmountGold,
|
||||
Normal: directParentAmountNormal,
|
||||
},
|
||||
MaxGoldRebateAmount: maxGoldRebateAmount,
|
||||
CommissionFreeze: types.CommissionFreezeConfig{
|
||||
Ratio: commissionFreezeRatio,
|
||||
Threshold: commissionFreezeThreshold,
|
||||
Days: commissionFreezeDays,
|
||||
},
|
||||
TaxRate: getConfigFloat("tax_rate"),
|
||||
TaxExemptionAmount: getConfigFloat("tax_exemption_amount"),
|
||||
}, nil
|
||||
|
||||
@@ -31,10 +31,16 @@ func (l *AdminGetAgentProductConfigListLogic) AdminGetAgentProductConfigList(req
|
||||
builder := l.svcCtx.AgentProductConfigModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
// 如果提供了产品ID,直接过滤
|
||||
if req.ProductId != nil {
|
||||
builder = builder.Where("product_id = ?", *req.ProductId)
|
||||
}
|
||||
|
||||
// 如果提供了产品名称,通过关联查询 product 表过滤
|
||||
if req.ProductName != nil && *req.ProductName != "" {
|
||||
builder = builder.Where("product_id IN (SELECT id FROM product WHERE product_name LIKE ? AND del_state = ?)", "%"+*req.ProductName+"%", globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
page := req.Page
|
||||
if page <= 0 {
|
||||
@@ -50,9 +56,19 @@ func (l *AdminGetAgentProductConfigListLogic) AdminGetAgentProductConfigList(req
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询产品配置列表失败, %v", err)
|
||||
}
|
||||
|
||||
// 组装响应
|
||||
// 组装响应(通过 product_id 查询产品名称)
|
||||
items := make([]types.AgentProductConfigItem, 0, len(configs))
|
||||
for _, config := range configs {
|
||||
// 通过 product_id 查询产品信息获取产品名称
|
||||
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, config.ProductId)
|
||||
productName := ""
|
||||
if err == nil {
|
||||
productName = product.ProductName
|
||||
} else {
|
||||
// 如果产品不存在,记录日志但不影响主流程
|
||||
l.Infof("查询产品信息失败, productId: %d, err: %v", config.ProductId, err)
|
||||
}
|
||||
|
||||
priceThreshold := 0.0
|
||||
if config.PriceThreshold.Valid {
|
||||
priceThreshold = config.PriceThreshold.Float64
|
||||
@@ -66,7 +82,7 @@ func (l *AdminGetAgentProductConfigListLogic) AdminGetAgentProductConfigList(req
|
||||
items = append(items, types.AgentProductConfigItem{
|
||||
Id: config.Id,
|
||||
ProductId: config.ProductId,
|
||||
ProductName: config.ProductName,
|
||||
ProductName: productName,
|
||||
BasePrice: config.BasePrice,
|
||||
PriceRangeMin: config.BasePrice, // 最低定价等于基础底价
|
||||
PriceRangeMax: config.SystemMaxPrice,
|
||||
|
||||
@@ -41,19 +41,76 @@ func (l *AdminUpdateAgentConfigLogic) AdminUpdateAgentConfig(req *types.AdminUpd
|
||||
return l.svcCtx.AgentConfigModel.UpdateWithVersion(l.ctx, nil, config)
|
||||
}
|
||||
|
||||
// 更新各个配置项
|
||||
if err := updateConfig("base_price", req.BasePrice); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新基础底价失败, %v", err)
|
||||
// 更新等级加成配置
|
||||
if req.LevelBonus != nil {
|
||||
if err := updateConfig("level_1_bonus", func() *float64 { v := float64(req.LevelBonus.Normal); return &v }()); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新普通代理等级加成失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("level_2_bonus", func() *float64 { v := float64(req.LevelBonus.Gold); return &v }()); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新黄金代理等级加成失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("level_3_bonus", func() *float64 { v := float64(req.LevelBonus.Diamond); return &v }()); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新钻石代理等级加成失败, %v", err)
|
||||
}
|
||||
}
|
||||
if err := updateConfig("system_max_price", req.SystemMaxPrice); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新系统价格上限失败, %v", err)
|
||||
|
||||
// 更新升级费用配置
|
||||
if req.UpgradeFee != nil {
|
||||
if err := updateConfig("upgrade_to_gold_fee", &req.UpgradeFee.NormalToGold); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新普通→黄金升级费用失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("upgrade_to_diamond_fee", &req.UpgradeFee.NormalToDiamond); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新普通→钻石升级费用失败, %v", err)
|
||||
}
|
||||
// gold_to_diamond 是计算得出的,不需要更新
|
||||
}
|
||||
if err := updateConfig("price_threshold", req.PriceThreshold); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新提价标准阈值失败, %v", err)
|
||||
|
||||
// 更新升级返佣配置
|
||||
if req.UpgradeRebate != nil {
|
||||
if err := updateConfig("upgrade_to_gold_rebate", &req.UpgradeRebate.NormalToGoldRebate); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新普通→黄金返佣失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("upgrade_to_diamond_rebate", &req.UpgradeRebate.ToDiamondRebate); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新升级为钻石返佣失败, %v", err)
|
||||
}
|
||||
}
|
||||
if err := updateConfig("price_fee_rate", req.PriceFeeRate); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新提价手续费比例失败, %v", err)
|
||||
|
||||
// 更新直接上级返佣配置
|
||||
if req.DirectParentRebate != nil {
|
||||
if err := updateConfig("direct_parent_amount_diamond", &req.DirectParentRebate.Diamond); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新直接上级是钻石的返佣金额失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("direct_parent_amount_gold", &req.DirectParentRebate.Gold); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新直接上级是黄金的返佣金额失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("direct_parent_amount_normal", &req.DirectParentRebate.Normal); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新直接上级是普通的返佣金额失败, %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 更新黄金代理最大返佣金额
|
||||
if err := updateConfig("max_gold_rebate_amount", req.MaxGoldRebateAmount); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新黄金代理最大返佣金额失败, %v", err)
|
||||
}
|
||||
|
||||
// 更新佣金冻结配置
|
||||
if req.CommissionFreeze != nil {
|
||||
if err := updateConfig("commission_freeze_ratio", &req.CommissionFreeze.Ratio); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新佣金冻结比例失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("commission_freeze_threshold", &req.CommissionFreeze.Threshold); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新佣金冻结阈值失败, %v", err)
|
||||
}
|
||||
// 更新解冻天数(整数类型)
|
||||
if req.CommissionFreeze.Days > 0 {
|
||||
daysFloat := float64(req.CommissionFreeze.Days)
|
||||
if err := updateConfig("commission_freeze_days", &daysFloat); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新佣金冻结解冻天数失败, %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新税费配置
|
||||
if err := updateConfig("tax_rate", req.TaxRate); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新税率失败, %v", err)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,20 @@ func (l *AdminUpdateAgentProductConfigLogic) AdminUpdateAgentProductConfig(req *
|
||||
// 更新配置字段
|
||||
config.BasePrice = req.BasePrice
|
||||
config.SystemMaxPrice = req.PriceRangeMax
|
||||
config.PriceThreshold = sql.NullFloat64{Float64: req.PriceThreshold, Valid: true}
|
||||
config.PriceFeeRate = sql.NullFloat64{Float64: req.PriceFeeRate, Valid: true}
|
||||
|
||||
// 价格阈值(可选)
|
||||
if req.PriceThreshold != nil {
|
||||
config.PriceThreshold = sql.NullFloat64{Float64: *req.PriceThreshold, Valid: true}
|
||||
} else {
|
||||
config.PriceThreshold = sql.NullFloat64{Valid: false}
|
||||
}
|
||||
|
||||
// 提价手续费比例(可选)
|
||||
if req.PriceFeeRate != nil {
|
||||
config.PriceFeeRate = sql.NullFloat64{Float64: *req.PriceFeeRate, Valid: true}
|
||||
} else {
|
||||
config.PriceFeeRate = sql.NullFloat64{Valid: false}
|
||||
}
|
||||
|
||||
// 更新配置
|
||||
if err := l.svcCtx.AgentProductConfigModel.UpdateWithVersion(l.ctx, nil, config); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user