first commit

This commit is contained in:
2025-11-27 13:09:54 +08:00
commit 3440744179
570 changed files with 61861 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
package admin_agent
import (
"context"
"strconv"
"ycc-server/common/xerr"
"github.com/pkg/errors"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AdminUpdateAgentConfigLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAdminUpdateAgentConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentConfigLogic {
return &AdminUpdateAgentConfigLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AdminUpdateAgentConfigLogic) AdminUpdateAgentConfig(req *types.AdminUpdateAgentConfigReq) (resp *types.AdminUpdateAgentConfigResp, err error) {
// 更新配置的辅助函数
updateConfig := func(key string, value *float64) error {
if value == nil {
return nil
}
config, err := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
if err != 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)
}
// 更新各个配置项
if err := updateConfig("base_price", req.BasePrice); 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 err := updateConfig("price_threshold", req.PriceThreshold); 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 err := updateConfig("tax_rate", req.TaxRate); err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新税率失败, %v", err)
}
if err := updateConfig("tax_exemption_amount", req.TaxExemptionAmount); err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新免税额度失败, %v", err)
}
return &types.AdminUpdateAgentConfigResp{
Success: true,
}, nil
}