go_dreamfactory/modules/friend/module.go
2022-09-08 15:49:17 +08:00

77 lines
1.7 KiB
Go

package friend
import (
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"github.com/spf13/cast"
)
var _ comm.IFriend = (*Friend)(nil)
func NewModule() core.IModule {
m := new(Friend)
return m
}
type Friend struct {
modules.ModuleBase
api *apiComp
modelFriend *ModelFriend
configure *modules.MCompConfigure
}
func (this *Friend) GetType() core.M_Modules {
return comm.ModuleFriend
}
func (this *Friend) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
return
}
func (this *Friend) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelFriend = this.RegisterComp(new(ModelFriend)).(*ModelFriend)
}
func (this *Friend) ResetFriend(uid string) {
// 重置点赞列表
zanUpdate := map[string]interface{}{
"zanIds": []string{},
"getZandIds": []string{},
}
if err := this.modelFriend.Change(uid, zanUpdate); err != nil {
log.Error("resetZanFriend err", log.Field{Key: "err", Value: err})
}
// 重置今日友情点
update := map[string]interface{}{
"friendPointID": 0,
"friendPointOD": 0,
}
if err := this.ModuleUser.ChangeUserExpand(uid, update); err != nil {
log.Error("resetFriend err", log.Field{Key: "err", Value: err})
}
}
func (this *Friend) GetFriendCount(uid string) (count int32) {
if friend := this.modelFriend.GetFriend(uid); friend != nil {
count = cast.ToInt32(len(friend.FriendIds))
}
return
}
func (this *Friend) GetFriendList(uid string) (uids []string) {
if friend := this.modelFriend.GetFriend(uid); friend != nil {
uids = friend.FriendIds
}
return
}