refactor(service): 统一服务实例调用方式 将多个模块中手动创建服务实例的方式替换为全局单例模式, 包括 PetFusionService、PetFusionMaterialService 和 EffectService。 同时修改了相关调用代码以适配新的服务引用方式。 此外,重构了 talk 模块的数据结构与逻辑实现, 优化了挖矿次数检查及更新机制。 ```
41 lines
783 B
Go
41 lines
783 B
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/blazing/model"
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/os/gcache"
|
|
)
|
|
|
|
type EffectService struct {
|
|
*cool.Service
|
|
}
|
|
|
|
func (s *EffectService) Args(id uint32) (int, []int) {
|
|
ret, _ := s.Cache.GetOrSetFuncLock(context.Background(), id, func(context.Context) (interface{}, error) {
|
|
|
|
m := cool.DBM(s.Model).Where("se_idx", id)
|
|
var tt model.PlayerPetSpecialEffect
|
|
err := m.Scan(&tt)
|
|
if err != nil {
|
|
return 0, nil
|
|
}
|
|
return tt, nil
|
|
}, 0)
|
|
tt := ret.Interface().(model.PlayerPetSpecialEffect)
|
|
|
|
return int(tt.Eid), tt.Args
|
|
|
|
}
|
|
func NewEffectService() *EffectService {
|
|
return &EffectService{
|
|
&cool.Service{
|
|
Cache: gcache.New(),
|
|
Model: model.NewPlayerPetSpecialEffect(),
|
|
},
|
|
}
|
|
}
|
|
|
|
var Effects = NewEffectService()
|