go_dreamfactory/modules/friend/model_friend.go
2022-08-09 18:39:21 +08:00

51 lines
1.1 KiB
Go

package friend
import (
"go_dreamfactory/comm"
"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"
)
type ModelFriend struct {
modules.MCompModel
}
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableFriend
err = this.MCompModel.Init(service, module, comp, options)
return
}
func (this *ModelFriend) Frined_FindCond(nickName string) *pb.DBUser {
var user *pb.DBUser
err := this.DB.FindOne(comm.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
}