Compare commits
2 Commits
7a3a53f1a9
...
69028898a4
| Author | SHA1 | Date | |
|---|---|---|---|
| 69028898a4 | |||
| 4907853667 |
@ -4,7 +4,7 @@ Debug: true # 是否开启调试模式, 默认: false
|
||||
|
||||
JwtAuth: # JWT认证配置
|
||||
AccessSecret: CHANGE_ME_TO_A_RANDOM_SECRET # 访问令牌密钥, 请修改为随机字符串
|
||||
AccessExpire: 604800 # 访问令牌过期时间,单位秒, 默认: 604800 (7天)
|
||||
AccessExpire: 31536000 # 访问令牌过期时间,单位秒, 默认: 31536000 (365天); 用户每次活跃请求自动续期
|
||||
|
||||
Logger: # 日志配置
|
||||
FilePath: logs/ppanel.log # 日志文件路径
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
DELETE
|
||||
FROM `system`
|
||||
WHERE `category` = 'invite'
|
||||
AND `key` = 'GiftDays';
|
||||
14
initialize/migrate/database/02139_invite_gift_days.up.sql
Normal file
14
initialize/migrate/database/02139_invite_gift_days.up.sql
Normal file
@ -0,0 +1,14 @@
|
||||
INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
|
||||
SELECT 'invite',
|
||||
'GiftDays',
|
||||
'3',
|
||||
'int',
|
||||
'Invite gift days',
|
||||
NOW(3),
|
||||
NOW(3)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM `system`
|
||||
WHERE `category` = 'invite'
|
||||
AND `key` = 'GiftDays'
|
||||
);
|
||||
@ -61,7 +61,7 @@ type RedisConfig struct {
|
||||
|
||||
type JwtAuth struct {
|
||||
AccessSecret string `yaml:"AccessSecret"`
|
||||
AccessExpire int64 `yaml:"AccessExpire" default:"604800"`
|
||||
AccessExpire int64 `yaml:"AccessExpire" default:"31536000"` // JWT 签发有效期,单位秒,默认 365 天
|
||||
}
|
||||
|
||||
type Verify struct {
|
||||
|
||||
@ -43,11 +43,26 @@ func (l *UpdateInviteConfigLogic) UpdateInviteConfig(req *types.InviteConfig) er
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the invite config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'invite' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
// Update existing row; if missing (RowsAffected=0), create it to avoid silent config loss.
|
||||
updateResult := db.Model(&system.System{}).
|
||||
Where("`category` = 'invite' and `key` = ?", fieldName).
|
||||
Update("value", fieldValue)
|
||||
err = updateResult.Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if updateResult.RowsAffected == 0 {
|
||||
err = db.Create(&system.System{
|
||||
Category: "invite",
|
||||
Key: fieldName,
|
||||
Value: fieldValue,
|
||||
Type: getSystemFieldType(v.Field(i)),
|
||||
Desc: "invite config: " + fieldName,
|
||||
}).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@ -62,3 +77,24 @@ func (l *UpdateInviteConfigLogic) UpdateInviteConfig(req *types.InviteConfig) er
|
||||
initialize.Invite(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSystemFieldType(field reflect.Value) string {
|
||||
kind := field.Kind()
|
||||
if kind == reflect.Ptr && !field.IsNil() {
|
||||
kind = field.Elem().Kind()
|
||||
}
|
||||
switch kind {
|
||||
case reflect.Bool:
|
||||
return "bool"
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return "int"
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return "uint"
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return "float"
|
||||
case reflect.String:
|
||||
return "string"
|
||||
default:
|
||||
return "string"
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,11 +38,12 @@ func (l *GetUserListLogic) GetUserList(req *types.GetUserListRequest) (*types.Ge
|
||||
SubscribeId: req.SubscribeId,
|
||||
UserSubscribeId: req.UserSubscribeId,
|
||||
ShortCode: req.ShortCode,
|
||||
DeviceId: req.DeviceId,
|
||||
FamilyJoined: req.FamilyJoined,
|
||||
FamilyStatus: req.FamilyStatus,
|
||||
FamilyOwnerUserId: req.FamilyOwnerUserId,
|
||||
FamilyId: req.FamilyId,
|
||||
Order: "DESC",
|
||||
Order: req.SortOrder,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "GetUserListLogic failed: %v", err.Error())
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
|
||||
@ -67,6 +68,9 @@ func AuthMiddleware(svc *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// sliding session: refresh TTL on every active request
|
||||
svc.Redis.Expire(c, sessionIdCacheKey, time.Duration(svc.Config.JwtAuth.AccessExpire)*time.Second)
|
||||
|
||||
userInfo, err := svc.UserModel.FindOne(c, userId)
|
||||
if err != nil {
|
||||
logger.WithContext(c.Request.Context()).Debug("[AuthMiddleware] UserModel FindOne", logger.Field("error", err.Error()), logger.Field("userId", userId))
|
||||
|
||||
@ -63,6 +63,7 @@ type UserFilterParams struct {
|
||||
SubscribeId *int64
|
||||
UserSubscribeId *int64
|
||||
ShortCode string
|
||||
DeviceId *int64
|
||||
FamilyJoined *bool
|
||||
FamilyStatus string
|
||||
FamilyOwnerUserId *int64
|
||||
@ -187,6 +188,10 @@ func (m *customUserModel) QueryPageList(ctx context.Context, page, size int, fil
|
||||
conn = conn.Joins("LEFT JOIN user_device ON user.id = user_device.user_id").
|
||||
Where("user_device.short_code LIKE ?", "%"+filter.ShortCode+"%")
|
||||
}
|
||||
if filter.DeviceId != nil {
|
||||
conn = conn.Joins("LEFT JOIN user_device ud ON ud.user_id = user.id").
|
||||
Where("ud.id = ?", *filter.DeviceId)
|
||||
}
|
||||
|
||||
if filter.FamilyJoined != nil {
|
||||
if *filter.FamilyJoined {
|
||||
@ -228,7 +233,13 @@ func (m *customUserModel) QueryPageList(ctx context.Context, page, size int, fil
|
||||
}
|
||||
|
||||
if filter.Order != "" {
|
||||
conn = conn.Order(fmt.Sprintf("user.id %s", filter.Order))
|
||||
order := strings.ToUpper(filter.Order)
|
||||
if order != "ASC" && order != "DESC" {
|
||||
order = "DESC"
|
||||
}
|
||||
conn = conn.Order(fmt.Sprintf("user.id %s", order))
|
||||
} else {
|
||||
conn = conn.Order("user.id DESC")
|
||||
}
|
||||
if filter.Unscoped {
|
||||
conn = conn.Unscoped()
|
||||
|
||||
@ -1317,10 +1317,12 @@ type GetUserListRequest struct {
|
||||
SubscribeId *int64 `form:"subscribe_id,omitempty"`
|
||||
UserSubscribeId *int64 `form:"user_subscribe_id,omitempty"`
|
||||
ShortCode string `form:"short_code,omitempty"`
|
||||
DeviceId *int64 `form:"device_id,omitempty"`
|
||||
FamilyJoined *bool `form:"family_joined,omitempty"`
|
||||
FamilyStatus string `form:"family_status,omitempty"`
|
||||
FamilyOwnerUserId *int64 `form:"family_owner_user_id,omitempty"`
|
||||
FamilyId *int64 `form:"family_id,omitempty"`
|
||||
SortOrder string `form:"sort_order,omitempty"` // asc or desc, default desc
|
||||
}
|
||||
|
||||
type GetUserListResponse struct {
|
||||
|
||||
14
ppanel.json
14
ppanel.json
@ -5043,13 +5043,18 @@
|
||||
"only_first_purchase": {
|
||||
"type": "boolean",
|
||||
"format": "boolean"
|
||||
},
|
||||
"gift_days": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
},
|
||||
"title": "GetInviteConfigResponse",
|
||||
"required": [
|
||||
"forced_invite",
|
||||
"referral_percentage",
|
||||
"only_first_purchase"
|
||||
"only_first_purchase",
|
||||
"gift_days"
|
||||
]
|
||||
},
|
||||
"GetListByPageRequest": {
|
||||
@ -6383,13 +6388,18 @@
|
||||
"only_first_purchase": {
|
||||
"type": "boolean",
|
||||
"format": "boolean"
|
||||
},
|
||||
"gift_days": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
},
|
||||
"title": "UpdateInviteConfigRequest",
|
||||
"required": [
|
||||
"forced_invite",
|
||||
"referral_percentage",
|
||||
"only_first_purchase"
|
||||
"only_first_purchase",
|
||||
"gift_days"
|
||||
]
|
||||
},
|
||||
"UpdateNodeConfigRequest": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user