refactor: param string

This commit is contained in:
wangfuduo 2026-07-08 17:18:47 +08:00
parent 7463e2dacd
commit 9cadffd46f
1 changed files with 19 additions and 13 deletions

View File

@ -13,9 +13,15 @@ import (
"github.com/spf13/cast" "github.com/spf13/cast"
) )
type Params map[string]any
func (p Params) Str(key string) string {
return cast.ToString(p[key])
}
type User struct { type User struct {
sess *session.ApiSession sess *session.ApiSession
params map[string]any params Params
ctx *gin.Context ctx *gin.Context
} }
@ -83,21 +89,21 @@ func (u *User) VipCheck() *response.Response {
// //
if expire < time.Now().Unix() { if expire < time.Now().Unix() {
resp = response.New(u.ctx, config.VipExpire, u.params[config.ServiceVipExpireNotice].(string)) resp = response.New(u.ctx, config.VipExpire, u.params.Str(config.ServiceVipExpireNotice))
window := &response.Window{Close: false} window := &response.Window{Close: false}
resp.Window(window) resp.Window(window)
buttons := make([]*response.Button, 0) buttons := make([]*response.Button, 0)
// 首次支付按钮 // 首次支付按钮
if u.sess.GetUserInfo().VipCreateTime == 0 { if u.sess.GetUserInfo().VipCreateTime == 0 {
if u.params[config.ServiceFirstPayWay] == config.FirstRechargeByCoupon { if u.params[config.ServiceFirstPayWay] == config.FirstRechargeByCoupon {
resp.Message(u.params[config.ServerCouponNotice].(string)) resp.Message(u.params.Str(config.ServerCouponNotice))
buttons = append(buttons, New(u.params).CouponButton()...) buttons = append(buttons, New(u.params).CouponButton()...)
} else { } else {
buttons = append(buttons, New(u.params).PayButton()...) buttons = append(buttons, New(u.params).PayButton()...)
} }
} else { } else {
if u.params[config.ServicePayWay] == config.FirstRechargeByCoupon { if u.params[config.ServicePayWay] == config.FirstRechargeByCoupon {
resp.Message(u.params[config.ServerCouponNotice].(string)) resp.Message(u.params.Str(config.ServerCouponNotice))
buttons = append(buttons, New(u.params).CouponButton()...) buttons = append(buttons, New(u.params).CouponButton()...)
} else { } else {
buttons = append(buttons, New(u.params).PayButton()...) buttons = append(buttons, New(u.params).PayButton()...)
@ -129,10 +135,10 @@ func (u *User) PkgCheck() *response.Response {
if pkg == nil { if pkg == nil {
panic(config.ErrData.New().Append(err)) panic(config.ErrData.New().Append(err))
} }
resp = response.New(u.ctx, config.UerNoPkg, u.params[config.ServiceUserPackageLack].(string)) resp = response.New(u.ctx, config.UerNoPkg, u.params.Str(config.ServiceUserPackageLack))
button := &response.Button{ button := &response.Button{
Text: u.params[config.ServicePackageLackButton].(string), Text: u.params.Str(config.ServicePackageLackButton),
Url: u.params[config.ServicePackageLackUrl].(string), Url: u.params.Str(config.ServicePackageLackUrl),
Type: config.ButtonClick, Type: config.ButtonClick,
} }
window := &response.Window{Close: false} window := &response.Window{Close: false}
@ -144,13 +150,13 @@ func (u *User) PkgCheck() *response.Response {
// 先判断是否强制更新 // 先判断是否强制更新
if resp = u.expireCheck(userPkg, cast.ToInt(u.params[config.ServiceForceUpdateDay])); resp != nil { if resp = u.expireCheck(userPkg, cast.ToInt(u.params[config.ServiceForceUpdateDay])); resp != nil {
resp.Window(&response.Window{Close: false, Title: u.params[config.ServiceForceUpdateNotice].(string)}) resp.Window(&response.Window{Close: false, Title: u.params.Str(config.ServiceForceUpdateNotice)})
return resp return resp
} }
// 判断是否提示更新 // 判断是否提示更新
if resp = u.expireCheck(userPkg, cast.ToInt(u.params[config.ServiceUpdateBeforeDay])); resp != nil { if resp = u.expireCheck(userPkg, cast.ToInt(u.params[config.ServiceUpdateBeforeDay])); resp != nil {
msg := fmt.Sprintf(u.params[config.ServiceUpdateNotice].(string), time.Unix(userPkg.Pkg.ExpireTime, 0).Format("2006-01-02")) msg := fmt.Sprintf(u.params.Str(config.ServiceUpdateNotice), time.Unix(userPkg.Pkg.ExpireTime, 0).Format("2006-01-02"))
resp.Window(&response.Window{Close: true, Title: msg}) resp.Window(&response.Window{Close: true, Title: msg})
return resp return resp
} }
@ -180,7 +186,7 @@ func (u *User) expireCheck(userPkg *model.UserPkgInfo, day int) *response.Respon
} }
// 3. 如果都不可用,则提示联系客服 // 3. 如果都不可用,则提示联系客服
if pkg == nil { if pkg == nil {
resp = response.New(u.ctx, config.NoPkg, u.params[config.ServiceContactCustomer].(string)) resp = response.New(u.ctx, config.NoPkg, u.params.Str(config.ServiceContactCustomer))
window := &response.Window{Close: false} window := &response.Window{Close: false}
resp.Window(window) resp.Window(window)
return resp return resp
@ -188,13 +194,13 @@ func (u *User) expireCheck(userPkg *model.UserPkgInfo, day int) *response.Respon
} }
// 否则返回强制更新 // 否则返回强制更新
message := u.params[config.ServiceForceUpdateNotice].(string) message := u.params.Str(config.ServiceForceUpdateNotice)
if pkg.Name != userPkg.Pkg.Name { if pkg.Name != userPkg.Pkg.Name {
message = u.params[config.ServiceUpdateOtherNotice].(string) message = u.params.Str(config.ServiceUpdateOtherNotice)
} }
resp = response.New(u.ctx, config.NeedUpgrade, message) resp = response.New(u.ctx, config.NeedUpgrade, message)
button := &response.Button{ button := &response.Button{
Text: u.params[config.ServiceInstallButton].(string), Text: u.params.Str(config.ServiceInstallButton),
Url: pkg.Link, Url: pkg.Link,
Type: config.ButtonClick, Type: config.ButtonClick,
} }