go_dreamfactory/modules/friend/model_friend.go
2022-07-12 16:12:29 +08:00

54 lines
1.2 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"
"go.mongodb.org/mongo-driver/mongo"
)
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}
err := this.Get(uid, friend)
if err != nil {
if err == redis.RedisNil || err == mongo.ErrNoDocuments {
if err := this.Add(uid, friend); err != nil {
return nil
}
}
}
return friend
}