go_dreamfactory/modules/web/modelUser.go
2022-08-11 09:59:25 +08:00

39 lines
904 B
Go

package web
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"time"
uuid "github.com/satori/go.uuid"
"go.mongodb.org/mongo-driver/bson/primitive"
)
//用户数据模块
type modelUserComp struct {
modules.MCompModel
module *Web
}
func (this *modelUserComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.TableName = comm.TableUser
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Web)
return
}
func (this *modelUserComp) User_Create(user *pb.DBUser) (err error) {
now := time.Now().Unix()
_id := primitive.NewObjectID().Hex()
user.Id = _id
user.Uid = fmt.Sprintf("%s_%s", user.Sid, _id)
user.Uuid = uuid.NewV4().String()
user.Lv = 1 //初始等级
user.Ctime = now
user.Logintime = now
return this.Add(user.Uid, user)
}