完善租客等级免押与积分管理

This commit is contained in:
yml2213
2026-07-26 18:07:10 +08:00
parent 379536e5c5
commit c594b543d1
24 changed files with 1296 additions and 178 deletions
@@ -37,7 +37,7 @@ var defaultConfigs = []defaultConfig{
{Key: listingPublishAgreementsConfigKey, Value: defaultListingPublishAgreementsConfigValue(), Description: "发布账号前协议配置 JSON"},
{Key: orderAgreementsConfigKey, Value: defaultOrderAgreementsConfigValue(), Description: "下单前协议配置 JSON"},
{Key: postRentalNoticeConfigKey, Value: defaultPostRentalNoticeConfigValue(), Description: "租后须知配置 JSON"},
{Key: rentergrowth.ConfigKey, Value: rentergrowth.DefaultConfigValue(), Description: "租客成长等级规则 JSON(积分门槛/下单折扣"},
{Key: rentergrowth.ConfigKey, Value: rentergrowth.DefaultConfigValue(), Description: "租客成长等级规则(积分门槛、租金折扣、等级免押额度"},
{Key: "chat.default_support_admin_id", Value: "2", Description: "默认客服 ID(必须是启用状态的客服角色)"},
{Key: "chat.auto_welcome_message", Value: "欢迎加入订单群聊!如有任何问题,请随时沟通。", Description: "建群后自动发送的欢迎话术"},
{Key: "chat.listing_group_welcome", Value: "欢迎加入账号群!请号主扫描下方二维码加入企业微信群,方便客服与您及时联系。", Description: "发布群创建后自动发送的欢迎语"},
@@ -135,6 +135,9 @@ func (r *Repository) Update(ctx context.Context, actorID uint64, key string, req
if err := tx.Save(&row).Error; err != nil {
return err
}
if err := syncRenterGrowthLevels(tx, key, req.Value); err != nil {
return err
}
if err := appendAuditLog(tx, actorID, "system_config.update", row.ID, meta, map[string]any{
"key": row.Key,
"before": before,
@@ -144,6 +147,9 @@ func (r *Repository) Update(ctx context.Context, actorID uint64, key string, req
}
return nil
}
if err := syncRenterGrowthLevels(tx, key, req.Value); err != nil {
return err
}
return appendAuditLog(tx, actorID, "system_config.create", row.ID, meta, map[string]any{
"key": row.Key,
"value": row.Value,
@@ -156,6 +162,17 @@ func (r *Repository) Update(ctx context.Context, actorID uint64, key string, req
return &dto, nil
}
func syncRenterGrowthLevels(tx *gorm.DB, key string, value string) error {
if key != rentergrowth.ConfigKey {
return nil
}
cfg, err := rentergrowth.ParseConfigValue(value)
if err != nil {
return err
}
return rentergrowth.SyncAllUserLevels(tx, cfg)
}
func (r *Repository) ensureDefaults(ctx context.Context) error {
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
for _, item := range defaultConfigs {
@@ -4,6 +4,8 @@ import (
"context"
"strconv"
"strings"
"hfb_sys/backend/internal/modules/rentergrowth"
)
func (s *Service) Update(ctx context.Context, actorID uint64, key string, req UpdateRequest, meta AuditMeta) (*ConfigDTO, error) {
@@ -19,5 +21,16 @@ func (s *Service) Update(ctx context.Context, actorID uint64, key string, req Up
return nil, ErrInvalidConfig
}
}
if key == rentergrowth.ConfigKey {
cfg, err := rentergrowth.ParseConfigValue(req.Value)
if err != nil {
return nil, ErrInvalidConfig
}
value, err := rentergrowth.MarshalConfig(cfg)
if err != nil {
return nil, ErrInvalidConfig
}
req.Value = value
}
return s.repo.Update(ctx, actorID, key, req, meta)
}