refactor(service): 重构用户服务数据库查询逻辑,将DBM调用封装为Model方法并添加GetModel注释
This commit is contained in:
@@ -420,6 +420,8 @@ func (s *Service) ModifyAfter(ctx context.Context, method string, param g.MapStr
|
|||||||
func (s *Service) GetModel() IModel {
|
func (s *Service) GetModel() IModel {
|
||||||
return s.Model
|
return s.Model
|
||||||
}
|
}
|
||||||
|
// GetModel 获取model
|
||||||
|
|
||||||
|
|
||||||
// NewService 新建一个service
|
// NewService 新建一个service
|
||||||
func NewService(model IModel) *Service {
|
func NewService(model IModel) *Service {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
// todo 待实现xml解析判断是否溢出
|
// todo 待实现xml解析判断是否溢出
|
||||||
func (s *UserService) TalkCheck() map[uint32]uint32 {
|
func (s *UserService) TalkCheck() map[uint32]uint32 {
|
||||||
|
|
||||||
m1 := cool.DBM(s.talk.Model).Where("player_id", s.userid)
|
m1 := s.Model(s.talk.Model)
|
||||||
|
|
||||||
var talks []model.Talk
|
var talks []model.Talk
|
||||||
m1.Scan(&talks)
|
m1.Scan(&talks)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserService struct {
|
type UserService struct {
|
||||||
@@ -29,3 +31,7 @@ func NewUserService(id uint32) *UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func (s *UserService) Model(m cool.IModel) *gdb.Model {
|
||||||
|
|
||||||
|
return cool.DBM(m).Where("player_id", s.userid)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user