webui: Add user birthday settings

- Store birth month and day in user_pref with default 10/18
- Migrate existing user_pref rows to fill missing birthday fields
- Expose birthday editing in the webui profile page
- Replace hardcoded birthday values in user info, top info, and product list responses
- Fix birthday month/day field alignment in the profile form

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-06-05 05:48:36 +08:00
parent 101f7e8a3f
commit 947da92a66
14 changed files with 143 additions and 19 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ func api(ctx *gin.Context) {
case "notice":
result, err = notice.NoticeApi(v.Action)
case "payment":
result, err = payment.PaymentApi(v.Action)
result, err = payment.PaymentApi(ctx, v.Action)
case "profile":
result, err = profile.ProfileApi(ctx, v.Action, v.UserID)
case "scenario":
+1 -1
View File
@@ -11,7 +11,7 @@ func LoginApi(ctx *gin.Context, action string) (res any, err error) {
case "topInfo":
res, err = loginTopInfo(ctx)
case "topInfoOnce":
res, err = loginTopInfoOnce()
res, err = loginTopInfoOnce(ctx)
default:
err = fmt.Errorf("unimplemented action: login: %s", action)
}
+1 -1
View File
@@ -57,7 +57,7 @@ func loginTopInfo(ctx *gin.Context) (res any, err error) {
NoticeMailDatetime: now.Format("2006-01-02 15:04:05"),
FriendsApprovalWaitCnt: friendsApprovalWaitCnt,
FriendsRequestCnt: friendsRequestCnt,
IsTodayBirthday: false,
IsTodayBirthday: ss.UserPref.IsBirthdayToday(now),
LicenseInfo: loginapischema.LicenseInfo{
LicenseList: []any{},
LicensedInfo: []any{},
+7 -2
View File
@@ -2,10 +2,15 @@ package login
import (
loginapischema "honoka-chan/internal/schema/api/login"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func loginTopInfoOnce() (res any, err error) {
func loginTopInfoOnce(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
res = loginapischema.TopInfoOnceResp{
Result: loginapischema.TopInfoOnceData{
NewAchievementCnt: 0,
@@ -22,7 +27,7 @@ func loginTopInfoOnce() (res any, err error) {
Lbonus: false,
Event: false,
Secretbox: false,
Birthday: true,
Birthday: ss.UserPref.HasBirthDate(),
},
OpenArena: true,
CostumeStatus: true,
+7 -3
View File
@@ -1,11 +1,15 @@
package payment
import "fmt"
import (
"fmt"
func PaymentApi(action string) (res any, err error) {
"github.com/gin-gonic/gin"
)
func PaymentApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "productList":
res, err = productList()
res, err = productList(ctx)
default:
err = fmt.Errorf("unimplemented action: payment: %s", action)
}
+7 -2
View File
@@ -2,17 +2,22 @@ package payment
import (
paymentapischema "honoka-chan/internal/schema/api/payment"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func productList() (res any, err error) {
func productList(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
res = paymentapischema.ProductListResp{
Result: paymentapischema.ProductListData{
RestrictionInfo: paymentapischema.RestrictionInfo{
Restricted: false,
},
UnderAgeInfo: paymentapischema.UnderAgeInfo{
BirthSet: false,
BirthSet: ss.UserPref.HasBirthDate(),
HasLimit: false,
LimitAmount: nil,
MonthUsed: 0,
+8 -1
View File
@@ -2,6 +2,7 @@ package user
import (
userapischema "honoka-chan/internal/schema/api/user"
userschema "honoka-chan/internal/schema/user"
"honoka-chan/internal/session"
"time"
@@ -12,7 +13,13 @@ func userInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
res = userapischema.InfoResp{
Result: ss.GetUserInfo(),
Result: userschema.UserInfoData{
User: ss.GetUserInfo(),
Birth: userschema.Birth{
BirthMonth: ss.UserPref.EffectiveBirthMonth(),
BirthDay: ss.UserPref.EffectiveBirthDay(),
},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
+2
View File
@@ -278,6 +278,8 @@ func addUser(dbSession *xorm.Session, phone, password string, isDefault bool) (g
SnsCoin: usermodel.DefaultUserSnsCoin,
EnergyMax: usermodel.DefaultUserEnergyMax,
OverMaxEnergy: usermodel.DefaultUserOverMaxEnergy,
BirthMonth: usermodel.DefaultBirthMonth,
BirthDay: usermodel.DefaultBirthDay,
ProfileVersion: usermodel.CurrentUserPrefProfileVersion,
UpdateTime: time.Now().Unix(),
}
+1 -1
View File
@@ -21,7 +21,7 @@ func productList(ctx *gin.Context) {
Restricted: false,
},
UnderAgeInfo: paymentapischema.UnderAgeInfo{
BirthSet: true,
BirthSet: ss.UserPref.HasBirthDate(),
HasLimit: false,
LimitAmount: nil,
MonthUsed: 0,
+2 -2
View File
@@ -18,8 +18,8 @@ func userInfo(ctx *gin.Context) {
ResponseData: userschema.UserInfoData{
User: ss.GetUserInfo(),
Birth: userschema.Birth{
BirthMonth: 10,
BirthDay: 18,
BirthMonth: ss.UserPref.EffectiveBirthMonth(),
BirthDay: ss.UserPref.EffectiveBirthDay(),
},
ServerTimestamp: time.Now().Unix(),
},
+20
View File
@@ -89,6 +89,20 @@ func updateProfile(ctx *gin.Context) {
ctx.JSON(http.StatusOK, webuischema.Msg{Code: 1, Message: "当前体力格式有误!"})
return
}
birthMonth, err := parseInt("birth_month", 1)
if err != nil {
ctx.JSON(http.StatusOK, webuischema.Msg{Code: 1, Message: "生日月份格式有误!"})
return
}
birthDay, err := parseInt("birth_day", 1)
if err != nil {
ctx.JSON(http.StatusOK, webuischema.Msg{Code: 1, Message: "生日日期格式有误!"})
return
}
if !usermodel.IsValidBirthDate(birthMonth, birthDay) {
ctx.JSON(http.StatusOK, webuischema.Msg{Code: 1, Message: "生日日期无效!"})
return
}
pref := usermodel.UserPref{
UserName: userName,
@@ -101,6 +115,8 @@ func updateProfile(ctx *gin.Context) {
SnsCoin: snsCoin,
EnergyMax: energyMax,
OverMaxEnergy: overMaxEnergy,
BirthMonth: birthMonth,
BirthDay: birthDay,
ProfileVersion: usermodel.CurrentUserPrefProfileVersion,
UpdateTime: time.Now().Unix(),
}
@@ -117,6 +133,8 @@ func updateProfile(ctx *gin.Context) {
"sns_coin",
"energy_max",
"over_max_energy",
"birth_month",
"birth_day",
"profile_version",
"update_time",
).
@@ -163,6 +181,8 @@ func resetProfile(ctx *gin.Context) {
"sns_coin",
"energy_max",
"over_max_energy",
"birth_month",
"birth_day",
"profile_version",
"update_time",
).