go_dreamfactory/modules/practice/modelQiecuo.go
2023-03-03 15:46:58 +08:00

75 lines
1.9 KiB
Go

package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"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 modelQiecuo struct {
modules.MCompModel
module *Practice
}
func (this *modelQiecuo) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.TableName = comm.TablePandataQiecuo
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Practice)
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
// 切磋请求处理
func (this *modelQiecuo) queryQiecuo(uid string) (result *pb.DBPracticeQiecuoRecord, err error) {
result = &pb.DBPracticeQiecuoRecord{}
if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
}
if err == mgo.MongodbNil {
result = &pb.DBPracticeQiecuoRecord{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Targets: make([]*pb.DBPracticeQiecuoInvite, 0),
}
if err = this.Add(uid, result); err != nil {
this.module.Errorln(err)
return
}
}
err = nil
return
}
func (this *modelQiecuo) endQiecuo(uid string) (result *pb.DBPracticeQiecuoRecord, err error) {
result = &pb.DBPracticeQiecuoRecord{}
if err = this.Get(uid, result); err != nil {
this.module.Errorln(err)
}
this.Change(uid, map[string]interface{}{
"status": 0,
"battid": "",
"targets": []*pb.DBPracticeQiecuoInvite{},
"member": []string{},
})
for _, v := range result.Member {
if v != uid {
this.Change(v, map[string]interface{}{
"status": 0,
"battid": "",
"targets": []*pb.DBPracticeQiecuoInvite{},
"member": []string{},
})
}
}
return
}