过期时间调整

This commit is contained in:
meixiongfeng 2024-01-03 11:06:35 +08:00
parent 772d3d6f33
commit 795a468e93
4 changed files with 33 additions and 37 deletions

View File

@ -14,6 +14,7 @@ type apiComp struct {
module *Hero module *Hero
chat comm.IChat chat comm.IChat
} }
type DBHeroDrawCardRecord struct { type DBHeroDrawCardRecord struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID 主键id 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 Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID

View File

@ -8,8 +8,6 @@ import (
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"math/big" "math/big"
"go.mongodb.org/mongo-driver/bson/primitive"
) )
func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (errdata *pb.ErrorData) { 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 { if req.DrawType != 1 {
// 任务统计 // 任务统计
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { 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 var szHero []*pb.DBHero
for _, hero := range add { // 奖励一次性发放 for _, hero := range add { // 奖励一次性发放
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄 if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄

View File

@ -3,10 +3,7 @@ package hero
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" 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) { go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
if _, err = this.module.modelDrawRecode.DBModel.DB.InsertOne("drawrecode", &DBHeroDrawCardRecord{ this.module.modelDrawRecode.AddDrawRecord(session, curSzCard)
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.HeroLibrary(session, curSzCard, szHero) this.module.HeroLibrary(session, curSzCard, szHero)
this.module.SendTaskMsg(session, szStar, 10, 1, curSzCard) this.module.SendTaskMsg(session, szStar, 10, 1, curSzCard)
}) })

View File

@ -6,8 +6,11 @@ import (
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"time"
"go.mongodb.org/mongo-driver/bson" "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"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
mgooptions "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.TableName = comm.TableDrawRecode
this.MCompModel.Init(service, module, comp, opt) this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Hero) this.module = module.(*Hero)
// 通过uid创建索引 // 通过uid创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{}) if _, err = this.DB.CreateMany(core.SqlTable(this.TableName), []mongo.IndexModel{
{
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, {Key: "uid", Value: bsonx.Int32(1)},
}) {Key: "ctime", Value: bsonx.Int32(1)},
indexModel := mongo.IndexModel{ },
}, {
Keys: bson.M{"expireAt": 1}, Keys: bson.M{"expireAt": 1},
Options: mgooptions.Index().SetExpireAfterSeconds(6 * 30 * 24 * 3600), Options: mgooptions.Index().SetExpireAfterSeconds(0),
},
}); err != nil {
return
} }
_, err = this.DB.CreateIndex(core.SqlTable(this.TableName), indexModel) //设置 验证码过期时间索引
return 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) { func (this *modelDrawRecode) InstertDrawCardRecord(record *pb.DBHeroDrawRecord) (err error) {
if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), record); err != nil { if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), record); err != nil {
this.module.Errorln(err) this.module.Errorln(err)