邀请 N天配置
This commit is contained in:
parent
7a3a53f1a9
commit
4907853667
@ -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'
|
||||
);
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
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