Files
bl/modules/player/service/friend.go
昔念 e5c75f7359
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
1
2026-02-13 22:57:05 +08:00

72 lines
1.2 KiB
Go

package service
import (
"blazing/cool"
"blazing/modules/player/model"
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
type FriendService struct {
BaseService
}
func (s *FriendService) Get() ([]uint32, []uint32) {
m1 := s.dbm(s.Model)
var talks *model.Friend
m1.Scan(&talks)
if talks == nil {
return []uint32{}, []uint32{}
}
return talks.Friend, talks.Black
}
func (s *FriendService) Add(id uint32) bool {
m1, _ := s.dbm(s.Model).Exist()
if !m1 {
m := s.dbm(s.Model)
data := g.Map{
"player_id": s.userid,
"friend": []uint32{},
"black": []uint32{},
"is_vip": cool.Config.ServerInfo.IsVip,
}
m.Data(data).Insert()
return true
}
m := s.dbm(s.Model)
m.Data(g.Map{
"friend": gdb.Raw(fmt.Sprintf("friend|| '%d'::jsonb", id)),
}).Update()
return true
}
func (s *FriendService) Del(id uint32) bool {
m := s.dbm(s.Model)
m.Data(g.Map{
"friend": gdb.Raw(fmt.Sprintf("jsonb_array_remove(friend, '%d'::jsonb)", id)),
}).Update()
return true
}
func NewFriendService(id uint32) *FriendService {
return &FriendService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewFriend()},
},
}
}