go_dreamfactory/modules/friend/model_friend.go
2022-07-01 16:30:57 +08:00

52 lines
1.1 KiB
Go

package friend
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson"
)
const (
TableFriend core.SqlTable = "friend"
TableUser core.SqlTable = "user" //用户表
)
type ModelFriend struct {
modules.MCompModel
}
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompModel.Init(service, module, comp, options)
this.TableName = string(TableFriend)
return
}
func (this *ModelFriend) Frined_FindCond(nickName string) *pb.DBUser {
var user *pb.DBUser
err := this.DB.FindOne(TableUser, bson.M{
"name": nickName,
}).Decode(&user)
if err != nil {
log.Errorf("findCond err:%v", err)
return nil
}
return user
}
//查询好友
func (this *ModelFriend) GetFriend(uid string) *pb.DBFriend {
friend := &pb.DBFriend{UId: uid}
if err := this.Get(uid, friend); err != nil {
if err == redis.RedisNil {
if err := this.Add(uid, friend); err != nil {
return nil
}
}
}
return friend
}