diff --git a/modules/hero/api.go b/modules/hero/api.go index 2e9ce281f..4137c7b20 100644 --- a/modules/hero/api.go +++ b/modules/hero/api.go @@ -14,6 +14,7 @@ type apiComp struct { module *Hero chat comm.IChat } + type DBHeroDrawCardRecord struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID 主键id Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index dc028b441..2427deed5 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -8,8 +8,6 @@ import ( "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "math/big" - - "go.mongodb.org/mongo-driver/bson/primitive" ) func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (errdata *pb.ErrorData) { @@ -324,18 +322,8 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq if req.DrawType != 1 { // 任务统计 go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.modelDrawRecode.AddDrawRecord(session, szCards) - if _, err = this.module.modelDrawRecode.DBModel.DB.InsertOne("drawrecode", &DBHeroDrawCardRecord{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - HeroId: szCards, - Drawtype: 1, - Ctime: configure.Now().Unix(), - ExpireAt: configure.Now(), - }); err != nil { - this.module.Errorln(err) - return - } var szHero []*pb.DBHero for _, hero := range add { // 奖励一次性发放 if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄 diff --git a/modules/hero/api_selectcard.go b/modules/hero/api_selectcard.go index 8feae1a4f..ed942541f 100644 --- a/modules/hero/api_selectcard.go +++ b/modules/hero/api_selectcard.go @@ -3,10 +3,7 @@ package hero import ( "go_dreamfactory/comm" "go_dreamfactory/pb" - "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" - - "go.mongodb.org/mongo-driver/bson/primitive" ) //参数校验 @@ -127,17 +124,8 @@ func (this *apiComp) SelectCard(session comm.IUserSession, req *pb.HeroSelectCar go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { - if _, err = this.module.modelDrawRecode.DBModel.DB.InsertOne("drawrecode", &DBHeroDrawCardRecord{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - HeroId: curSzCard, - Drawtype: 1, - Ctime: configure.Now().Unix(), - ExpireAt: configure.Now(), - }); err != nil { - this.module.Errorln(err) - return - } + this.module.modelDrawRecode.AddDrawRecord(session, curSzCard) + this.module.HeroLibrary(session, curSzCard, szHero) this.module.SendTaskMsg(session, szStar, 10, 1, curSzCard) }) diff --git a/modules/hero/model_drawrecord.go b/modules/hero/model_drawrecord.go index 63e291083..38dfe7fe3 100644 --- a/modules/hero/model_drawrecord.go +++ b/modules/hero/model_drawrecord.go @@ -6,8 +6,11 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + "time" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" mgooptions "go.mongodb.org/mongo-driver/mongo/options" @@ -24,21 +27,37 @@ func (this *modelDrawRecode) Init(service core.IService, module core.IModule, co this.TableName = comm.TableDrawRecode this.MCompModel.Init(service, module, comp, opt) this.module = module.(*Hero) - // 通过uid创建索引 - this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{}) - - this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ - Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, - }) - indexModel := mongo.IndexModel{ - Keys: bson.M{"expireAt": 1}, - Options: mgooptions.Index().SetExpireAfterSeconds(6 * 30 * 24 * 3600), + if _, err = this.DB.CreateMany(core.SqlTable(this.TableName), []mongo.IndexModel{ + { + Keys: bsonx.Doc{ + {Key: "uid", Value: bsonx.Int32(1)}, + {Key: "ctime", Value: bsonx.Int32(1)}, + }, + }, { + Keys: bson.M{"expireAt": 1}, + Options: mgooptions.Index().SetExpireAfterSeconds(0), + }, + }); err != nil { + return } - _, err = this.DB.CreateIndex(core.SqlTable(this.TableName), indexModel) //设置 验证码过期时间索引 return } +func (this *modelDrawRecode) AddDrawRecord(session comm.IUserSession, curSzCard []string) { + ExpireTime := time.Unix(configure.Now().Unix()+3*30*24*3600, 0) + if _, err := this.DBModel.DB.InsertOne("drawrecode", &DBHeroDrawCardRecord{ + Id: primitive.NewObjectID().Hex(), + Uid: session.GetUserId(), + HeroId: curSzCard, + Drawtype: 1, + Ctime: configure.Now().Unix(), + ExpireAt: ExpireTime, + }); err != nil { + this.module.Errorln(err) + return + } +} func (this *modelDrawRecode) InstertDrawCardRecord(record *pb.DBHeroDrawRecord) (err error) { if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), record); err != nil { this.module.Errorln(err) diff --git a/modules/modeluserlog.go b/modules/modeluserlog.go index 8f1586313..64a903a0e 100644 --- a/modules/modeluserlog.go +++ b/modules/modeluserlog.go @@ -5,7 +5,6 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" - "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" "go_dreamfactory/utils" @@ -39,6 +38,17 @@ func (this *modelUserLog) Init(service core.IService, module core.IModule, comp return } +type DBUserLogRecord struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //唯一ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"` + Logtype string `protobuf:"bytes,3,opt,name=logtype,proto3" json:"logtype"` + Tag string `protobuf:"bytes,4,opt,name=tag,proto3" json:"tag"` + Data string `protobuf:"bytes,5,opt,name=data,proto3" json:"data"` + Ctime int64 `protobuf:"varint,6,opt,name=ctime,proto3" json:"ctime"` // 写日志的时间 + Req string `protobuf:"bytes,7,opt,name=req,proto3" json:"req"` // 请求参数 + ExpireAt time.Time `bson:"expireAt,omitempty"` +} + // 用户操作明细数据记录 func (this *modelUserLog) AddUserLog(uid string, req interface{}, itype int32, tag string, data interface{}) { var ( @@ -76,15 +86,15 @@ func (this *modelUserLog) AddUserLog(uid string, req interface{}, itype int32, t if db.IsCross() { //如果是跨服 直接找到对应的本服 if tag, _, b := utils.UIdSplit(uid); b { if conn, err := db.ServerDBConn(tag); err == nil { - if _, err = conn.Mgo.InsertOne(core.SqlTable(this.TableName), &pb.DBUserLog{ + if _, err = conn.Mgo.InsertOne(core.SqlTable(this.TableName), &DBUserLogRecord{ Id: primitive.NewObjectID().Hex(), Uid: uid, - ExpireAt: time.Now().Add(time.Hour * 24 * 8).Unix(), Logtype: logType, Tag: tag, Data: string(jsonStr), Ctime: configure.Now().Unix(), Req: string(jsonReq), + ExpireAt: configure.Now().Add(time.Hour * 24 * 8), }); err != nil { log.Errorln(err) return @@ -92,15 +102,15 @@ func (this *modelUserLog) AddUserLog(uid string, req interface{}, itype int32, t } } } else { // 本服 直接操作本服数据 - if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), &pb.DBUserLog{ + if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), &DBUserLogRecord{ Id: primitive.NewObjectID().Hex(), Uid: uid, - ExpireAt: time.Now().Add(time.Hour * 24 * 8).Unix(), Logtype: logType, Tag: tag, Data: string(jsonStr), Ctime: configure.Now().Unix(), Req: string(jsonReq), + ExpireAt: configure.Now().Add(time.Hour * 24 * 8), }); err != nil { log.Errorln(err) return diff --git a/pb/userexpand.pb.go b/pb/userexpand.pb.go index 5ba271a7d..f3a0b397f 100644 --- a/pb/userexpand.pb.go +++ b/pb/userexpand.pb.go @@ -347,14 +347,13 @@ type DBUserLog struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //唯一ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"` - ExpireAt int64 `protobuf:"varint,3,opt,name=expireAt,proto3" json:"expireAt"` - Logtype string `protobuf:"bytes,4,opt,name=logtype,proto3" json:"logtype"` - Tag string `protobuf:"bytes,5,opt,name=tag,proto3" json:"tag"` - Data string `protobuf:"bytes,6,opt,name=data,proto3" json:"data"` - Ctime int64 `protobuf:"varint,7,opt,name=ctime,proto3" json:"ctime"` // 写日志的时间 - Req string `protobuf:"bytes,8,opt,name=req,proto3" json:"req"` // 请求参数 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //唯一ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"` + Logtype string `protobuf:"bytes,3,opt,name=logtype,proto3" json:"logtype"` + Tag string `protobuf:"bytes,4,opt,name=tag,proto3" json:"tag"` + Data string `protobuf:"bytes,5,opt,name=data,proto3" json:"data"` + Ctime int64 `protobuf:"varint,6,opt,name=ctime,proto3" json:"ctime"` // 写日志的时间 + Req string `protobuf:"bytes,7,opt,name=req,proto3" json:"req"` // 请求参数 } func (x *DBUserLog) Reset() { @@ -403,13 +402,6 @@ func (x *DBUserLog) GetUid() string { return "" } -func (x *DBUserLog) GetExpireAt() int64 { - if x != nil { - return x.ExpireAt - } - return 0 -} - func (x *DBUserLog) GetLogtype() string { if x != nil { return x.Logtype @@ -542,19 +534,18 @@ var file_userexpand_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x48, 0x65, 0x72, 0x6f, 0x66, 0x72, 0x61, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xb1, 0x01, 0x0a, 0x09, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x95, 0x01, 0x0a, 0x09, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x65, - 0x78, 0x70, 0x69, 0x72, 0x65, 0x41, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x65, - 0x78, 0x70, 0x69, 0x72, 0x65, 0x41, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6c, 0x6f, 0x67, 0x74, 0x79, - 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x6f, 0x67, 0x74, 0x79, 0x70, - 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x74, 0x61, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x10, 0x0a, - 0x03, 0x72, 0x65, 0x71, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x42, - 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6c, + 0x6f, 0x67, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x6f, + 0x67, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x63, + 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, + 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x71, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x72, 0x65, 0x71, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var (