v1.1
This commit is contained in:
@@ -2,6 +2,7 @@ package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strconv"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,17 +30,77 @@ func NewAdminUpdateAgentConfigLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
||||
}
|
||||
|
||||
func (l *AdminUpdateAgentConfigLogic) AdminUpdateAgentConfig(req *types.AdminUpdateAgentConfigReq) (resp *types.AdminUpdateAgentConfigResp, err error) {
|
||||
// 更新配置的辅助函数
|
||||
configTypeForKey := func(key string) string {
|
||||
switch key {
|
||||
case "level_1_bonus", "level_2_bonus", "level_3_bonus":
|
||||
return "bonus"
|
||||
case "upgrade_to_gold_fee", "upgrade_to_diamond_fee", "upgrade_to_gold_rebate", "upgrade_to_diamond_rebate":
|
||||
return "upgrade"
|
||||
case "direct_parent_amount_diamond", "direct_parent_amount_gold", "direct_parent_amount_normal", "max_gold_rebate_amount":
|
||||
return "rebate"
|
||||
case "commission_freeze_ratio", "commission_freeze_threshold", "commission_freeze_days":
|
||||
return "rebate"
|
||||
case "tax_rate", "tax_exemption_amount":
|
||||
return "tax"
|
||||
case "gold_max_uplift_amount", "diamond_max_uplift_amount":
|
||||
return "price"
|
||||
default:
|
||||
return "rebate"
|
||||
}
|
||||
}
|
||||
|
||||
updateConfig := func(key string, value *float64) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
valStr := strconv.FormatFloat(*value, 'f', -1, 64)
|
||||
config, err := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
cfg := &model.AgentConfig{
|
||||
ConfigKey: key,
|
||||
ConfigValue: valStr,
|
||||
ConfigType: configTypeForKey(key),
|
||||
Description: sql.NullString{},
|
||||
DeleteTime: sql.NullTime{},
|
||||
Version: 0,
|
||||
}
|
||||
_, insErr := l.svcCtx.AgentConfigModel.Insert(l.ctx, nil, cfg)
|
||||
if insErr != nil {
|
||||
return errors.Wrapf(insErr, "创建配置失败, key: %s", key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errors.Wrapf(err, "查询配置失败, key: %s", key)
|
||||
}
|
||||
config.ConfigValue = strconv.FormatFloat(*value, 'f', -1, 64)
|
||||
return l.svcCtx.AgentConfigModel.UpdateWithVersion(l.ctx, nil, config)
|
||||
config.ConfigValue = valStr
|
||||
if uErr := l.svcCtx.AgentConfigModel.UpdateWithVersion(l.ctx, nil, config); uErr != nil {
|
||||
if errors.Is(uErr, model.ErrNoRowsUpdate) {
|
||||
latestByKey, reErr := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
|
||||
if reErr != nil {
|
||||
if errors.Is(reErr, model.ErrNotFound) {
|
||||
cfg := &model.AgentConfig{
|
||||
ConfigKey: key,
|
||||
ConfigValue: valStr,
|
||||
ConfigType: configTypeForKey(key),
|
||||
Description: sql.NullString{},
|
||||
DeleteTime: sql.NullTime{},
|
||||
Version: 0,
|
||||
}
|
||||
_, insErr := l.svcCtx.AgentConfigModel.Insert(l.ctx, nil, cfg)
|
||||
if insErr != nil {
|
||||
return errors.Wrapf(insErr, "创建配置失败, key: %s", key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errors.Wrapf(reErr, "查询最新配置失败, key: %s", key)
|
||||
}
|
||||
latestByKey.ConfigValue = valStr
|
||||
return l.svcCtx.AgentConfigModel.UpdateWithVersion(l.ctx, nil, latestByKey)
|
||||
}
|
||||
return uErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 更新等级加成配置
|
||||
@@ -118,6 +180,13 @@ func (l *AdminUpdateAgentConfigLogic) AdminUpdateAgentConfig(req *types.AdminUpd
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新免税额度失败, %v", err)
|
||||
}
|
||||
|
||||
if err := updateConfig("gold_max_uplift_amount", req.GoldMaxUpliftAmount); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新黄金代理最高价上调金额失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("diamond_max_uplift_amount", req.DiamondMaxUpliftAmount); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新钻石代理最高价上调金额失败, %v", err)
|
||||
}
|
||||
|
||||
return &types.AdminUpdateAgentConfigResp{
|
||||
Success: true,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user