go_dreamfactory/modules/gourmet/model_food.go

59 lines
1.5 KiB
Go

package gourmet
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelAtlas struct {
modules.MCompModel
module *Gourmet
}
func (this *modelAtlas) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableGourmetAtlas)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Gourmet)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelAtlas) getGourmetAtlasList(uid string) (result *pb.DBGourmetAtlas, err error) {
result = &pb.DBGourmetAtlas{}
if err = this.Get(uid, result); err != nil {
if redis.RedisNil != err { // 没有数据直接创建新的数据
result.Id = primitive.NewObjectID().Hex()
result.Uid = uid
result.Atlas = make(map[string]int32)
}
}
err = nil
return result, err
}
func (this *modelAtlas) modifyGourmetAtlasByObjId(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}
// 美食城图鉴红点
func (this *modelAtlas) checkReddot2301(uid string) bool {
if rst, err := this.getGourmetAtlasList(uid); err == nil {
for _, v := range rst.Atlas {
if v == -1 {
return true
}
}
}
return false
}