aozhiwei d8f430f88d 1
2024-11-06 11:34:48 +08:00

52 lines
1.2 KiB
Go

package user
import (
"q5"
"f5"
"errors"
"main/constant"
"main/common"
"main/model"
"main/vo"
"main/mt"
"gorm.io/gorm"
"github.com/gin-gonic/gin"
)
type UserApi struct {
}
func (this *UserApi) Login(c *gin.Context) {
s := c.MustGet(constant.SESSION_KEY).(common.Session)
if s == nil {
return
}
user := new(model.User)
rspObj := struct {
vo.BaseVo
UserInfo vo.User `json:"user_info"`
}{}
nowTime := f5.GetApp().GetRealSeconds()
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(user.TableName()).Take(
user, "account_id = ?", s.GetAccountId()); result.Error != nil &&
!errors.Is(result.Error, gorm.ErrRecordNotFound) {
f5.RspErr(c, 500, "server internal error")
return
} else if result.RowsAffected <= 0 {
user.AccountId = s.GetAccountId()
user.Avatar = ""
user.NickName = s.GetNickName()
user.Score = ""
user.Dice = mt.Table.Global.GetDailyDiceNum()
user.LastPresentDiceTime = q5.ToInt32(nowTime)
user.CreateTime = q5.ToInt32(nowTime)
user.ModifyTime = q5.ToInt32(nowTime)
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Create(user); result.Error != nil {
f5.RspErr(c, 500, "server internal error")
return
}
}
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}