1
This commit is contained in:
parent
ab83e6cb6f
commit
059a8db38a
@ -3,13 +3,11 @@ package user
|
|||||||
import (
|
import (
|
||||||
"q5"
|
"q5"
|
||||||
"f5"
|
"f5"
|
||||||
"errors"
|
|
||||||
"main/constant"
|
"main/constant"
|
||||||
"main/common"
|
"main/common"
|
||||||
"main/model"
|
"main/model"
|
||||||
"main/vo"
|
"main/vo"
|
||||||
"main/mt"
|
"main/mt"
|
||||||
"gorm.io/gorm"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,12 +25,10 @@ func (this *UserApi) Login(c *gin.Context) {
|
|||||||
UserInfo vo.User `json:"user_info"`
|
UserInfo vo.User `json:"user_info"`
|
||||||
}{}
|
}{}
|
||||||
nowTime := f5.GetApp().GetRealSeconds()
|
nowTime := f5.GetApp().GetRealSeconds()
|
||||||
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(user.TableName()).Take(
|
if err, found := user.Find(s.GetAccountId(), nowTime); err != nil {
|
||||||
user, "account_id = ?", s.GetAccountId()); result.Error != nil &&
|
|
||||||
!errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
|
||||||
f5.RspErr(c, 500, "server internal error")
|
f5.RspErr(c, 500, "server internal error")
|
||||||
return
|
return
|
||||||
} else if result.RowsAffected <= 0 {
|
} else if !found {
|
||||||
user.AccountId = s.GetAccountId()
|
user.AccountId = s.GetAccountId()
|
||||||
user.Avatar = ""
|
user.Avatar = ""
|
||||||
user.NickName = s.GetNickName()
|
user.NickName = s.GetNickName()
|
||||||
@ -41,22 +37,13 @@ func (this *UserApi) Login(c *gin.Context) {
|
|||||||
user.LastPresentDiceTime = q5.ToInt32(nowTime)
|
user.LastPresentDiceTime = q5.ToInt32(nowTime)
|
||||||
user.CreateTime = q5.ToInt32(nowTime)
|
user.CreateTime = q5.ToInt32(nowTime)
|
||||||
user.ModifyTime = q5.ToInt32(nowTime)
|
user.ModifyTime = q5.ToInt32(nowTime)
|
||||||
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Create(user); result.Error != nil {
|
if user.Create() != nil {
|
||||||
f5.RspErr(c, 500, "server internal error")
|
f5.RspErr(c, 500, "server internal error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f5.GetMsgQueue().FireEvent(constant.MSG_CREATE_USER, q5.Args{user})
|
f5.GetMsgQueue().FireEvent(constant.MSG_CREATE_USER, q5.Args{user})
|
||||||
}
|
}
|
||||||
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
|
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
|
||||||
if int32(q5.GetDaySeconds(nowTime, 0)) > user.LastPresentDiceTime {
|
|
||||||
user.Dice = mt.Table.Global.GetDailyDiceNum()
|
|
||||||
user.LastPresentDiceTime = q5.ToInt32(nowTime)
|
|
||||||
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Model(user).Select(
|
|
||||||
"dice", "last_present_dice_time").Updates(user); result.Error != nil {
|
|
||||||
f5.RspErr(c, 500, "server internal error")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rspObj.UserInfo.FromModel(user)
|
rspObj.UserInfo.FromModel(user)
|
||||||
c.JSON(200, rspObj)
|
c.JSON(200, rspObj)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"q5"
|
||||||
|
"f5"
|
||||||
|
"errors"
|
||||||
|
"main/constant"
|
||||||
|
"main/mt"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Idx int64 `gorm:"column:idx;AUTO_INCREMENT"`
|
Idx int64 `gorm:"column:idx;AUTO_INCREMENT"`
|
||||||
AccountId string `gorm:"column:account_id;primaryKey"`
|
AccountId string `gorm:"column:account_id;primaryKey"`
|
||||||
@ -15,3 +24,30 @@ type User struct {
|
|||||||
func (this *User) TableName() string {
|
func (this *User) TableName() string {
|
||||||
return "t_user"
|
return "t_user"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *User) Find(accountId string, nowTime int64) (error, bool) {
|
||||||
|
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take(
|
||||||
|
this, "account_id = ?", accountId); result.Error != nil &&
|
||||||
|
!errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
return result.Error, false
|
||||||
|
} else {
|
||||||
|
if result.RowsAffected > 0 {
|
||||||
|
if int32(q5.GetDaySeconds(nowTime, 0)) > this.LastPresentDiceTime {
|
||||||
|
this.Dice = mt.Table.Global.GetDailyDiceNum()
|
||||||
|
this.LastPresentDiceTime = q5.ToInt32(nowTime)
|
||||||
|
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Model(this).Select(
|
||||||
|
"dice", "last_present_dice_time").Updates(this); result.Error != nil {
|
||||||
|
return result.Error, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, result.RowsAffected > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *User) Create() error {
|
||||||
|
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Create(this); result.Error != nil {
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user