122 lines
3.1 KiB
Go
122 lines
3.1 KiB
Go
/*
|
|
模块名:Smithy
|
|
描述:美食家模块
|
|
开发:梅雄风
|
|
*/
|
|
package smithy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type Smithy struct {
|
|
modules.ModuleBase
|
|
modelTrade *modelTrade
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelStove *modelStove
|
|
modelAtlas *modelAtlas
|
|
modelTask *modelTask
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Smithy{}
|
|
}
|
|
|
|
func (this *Smithy) GetType() core.M_Modules {
|
|
return comm.ModuleSmithy
|
|
}
|
|
|
|
func (this *Smithy) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
|
|
return
|
|
}
|
|
|
|
func (this *Smithy) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
this.modelTrade = this.RegisterComp(new(modelTrade)).(*modelTrade)
|
|
this.modelStove = this.RegisterComp(new(modelStove)).(*modelStove)
|
|
this.modelAtlas = this.RegisterComp(new(modelAtlas)).(*modelAtlas)
|
|
this.modelTask = this.RegisterComp(new(modelTask)).(*modelTask)
|
|
}
|
|
|
|
func (this *Smithy) CheckActivateAtlasCollect(uid string, id string) {
|
|
atlasConf, err := this.configure.GetSmithyAtlasConf(id)
|
|
if err != nil || atlasConf.TypeId != 2 {
|
|
return
|
|
}
|
|
|
|
if this.IsCross() {
|
|
atlas := &pb.DBAtlas{}
|
|
if model, err := this.GetDBModelByUid(uid, this.modelAtlas.TableName); err == nil {
|
|
|
|
if err := model.Get(uid, atlas); err != nil { // 防止数据没有初始化情况
|
|
if mongo.ErrNoDocuments == err {
|
|
atlas.Id = primitive.NewObjectID().Hex()
|
|
atlas.Uid = uid
|
|
atlas.Atlas = make(map[string]*pb.ForgeList, 0)
|
|
atlas.Collect = make(map[string]*pb.CollectData, 0)
|
|
atlas.Award = 1 // 初始1级
|
|
|
|
atlas.Collect[id] = &pb.CollectData{
|
|
Id: id,
|
|
Score: 0,
|
|
Time: configure.Now().Unix(),
|
|
Activate: false,
|
|
}
|
|
update := make(map[string]interface{}, 0)
|
|
update["collect"] = atlas.Collect
|
|
if err := model.Add(uid, update); err != nil {
|
|
this.Errorf("err:%v", err)
|
|
}
|
|
return
|
|
} else {
|
|
this.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
if _, ok := atlas.Collect[id]; !ok {
|
|
atlas.Collect[id] = &pb.CollectData{
|
|
Id: id,
|
|
Score: 0,
|
|
Time: configure.Now().Unix(),
|
|
Activate: false,
|
|
}
|
|
update := make(map[string]interface{}, 0)
|
|
update["collect"] = atlas.Collect
|
|
if err := model.Change(uid, update); err != nil {
|
|
this.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
|
|
if list, err := this.modelAtlas.getSmithyAtlasList(uid); err == nil {
|
|
if _, ok := list.Collect[id]; !ok {
|
|
list.Collect[id] = &pb.CollectData{
|
|
Id: id,
|
|
Score: 0,
|
|
Time: configure.Now().Unix(),
|
|
Activate: false,
|
|
}
|
|
update := make(map[string]interface{}, 0)
|
|
update["collect"] = list.Collect
|
|
this.modelAtlas.modifySmithyAtlasList(uid, update) // 更新信息
|
|
return
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|