diff --git a/comm/const.go b/comm/const.go index 50f413d9e..52c69ca03 100644 --- a/comm/const.go +++ b/comm/const.go @@ -190,6 +190,9 @@ const ( TablePrivilege = "privilege" //联盟学院 TableAcademy = "academy" + + // 签到 + TableSign = "sign" ) //RPC服务接口定义处 diff --git a/modules/comp_configure.go b/modules/comp_configure.go index b7cadb005..8c315ba29 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -277,20 +277,15 @@ func (this *MCompConfigure) GetSignConf(day, group int32) *cfg.GameSignData { } // 获取组id -func (this *MCompConfigure) GetSignResetConf(id int32) (groups int32) { - if v, err := this.GetConfigure(game_signreset); err != nil { - return - } else { - if configure, ok := v.(*cfg.GameSignReset); !ok { - err = fmt.Errorf("%T no is *cfg.GameSignData", v) - return - } else { +func (this *MCompConfigure) GetSignResetConf(id int32) int32 { + if v, err := this.GetConfigure(game_signreset); err == nil { + if configure, ok := v.(*cfg.GameSignReset); ok { if configure != nil { - groups = configure.Get(id).Groups + return configure.Get(id).Groups } } } - return + return -1 } func (this *MCompConfigure) LoadSignData() { if v, err := this.GetConfigure(game_sign); err == nil { diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index 66221aa30..318f3d7be 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -58,8 +58,19 @@ func (this *TestService) InitSys() { log.Infof("init sys.configure success!") } } - +func GetMonthStartEnd() (int64, int64) { + t := time.Now() + monthStartDay := t.AddDate(0, 0, -t.Day()+1) + monthStartTime := time.Date(monthStartDay.Year(), monthStartDay.Month(), monthStartDay.Day(), 0, 0, 0, 0, t.Location()) + monthEndDay := monthStartTime.AddDate(0, 1, -1) + monthEndTime := time.Date(monthEndDay.Year(), monthEndDay.Month(), monthEndDay.Day(), 23, 59, 59, 0, t.Location()) + _d1 := monthStartTime.Unix() + _d2 := monthEndTime.Unix() + fmt.Printf("%d,%d", _d1, _d2) + return _d1, _d2 +} func Test_Main(t *testing.T) { + GetMonthStartEnd() fmt.Printf("%d", 9/10) ids := utils.RandomNumbers(0, 10, 5) for _, v := range ids { diff --git a/modules/troll/api.go b/modules/troll/api.go index 39cde8023..96ce2fa82 100644 --- a/modules/troll/api.go +++ b/modules/troll/api.go @@ -14,6 +14,7 @@ const ( GourmetGetRandUserResp = "getranduser" TrollRankListResp = "ranklist" TrollRecordListResp = "recordlist" + TrollAfkSetResp = "afkset" ) type apiComp struct { diff --git a/modules/troll/api_afkset.go b/modules/troll/api_afkset.go index e32c798cf..d37b43b8e 100644 --- a/modules/troll/api_afkset.go +++ b/modules/troll/api_afkset.go @@ -32,6 +32,6 @@ func (this *apiComp) AfkSet(session comm.IUserSession, req *pb.TrollAfkSetReq) ( update["sell"] = troll.Sell update["aiCount"] = troll.AiCount this.module.ModifyTrollData(session.GetUserId(), update) - session.SendMsg(string(this.module.GetType()), TrollNpcRewardResp, &pb.TrollNpcRewardResp{Data: troll}) + session.SendMsg(string(this.module.GetType()), TrollAfkSetResp, &pb.TrollAfkSetResp{Data: troll}) return } diff --git a/modules/user/model_sign.go b/modules/user/model_sign.go new file mode 100644 index 000000000..6d0d36f79 --- /dev/null +++ b/modules/user/model_sign.go @@ -0,0 +1,72 @@ +package user + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + "go_dreamfactory/utils" + "time" + + "go.mongodb.org/mongo-driver/mongo" +) + +// 签到 +type ModelSign struct { + modules.MCompModel + module *User +} + +func (this *ModelSign) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.TableName = comm.TableSign + err = this.MCompModel.Init(service, module, comp, options) + this.module = module.(*User) + return +} + +func (this *ModelSign) GetUserSign(uid string) (result *pb.DBSign, err error) { + result = &pb.DBSign{} + if err = this.module.modelSign.Get(uid, result); err != nil && mongo.ErrNoDocuments != err { + return + } + err = nil + return result, err +} + +//修改用户签到数据 +func (this *ModelSign) ChangeUserSign(uid string, value map[string]interface{}) (err error) { + if len(value) == 0 { + return nil + } + return this.module.modelSign.Change(uid, value) +} + +// 累计登录天数 +func (this *ModelSign) updateSignData(uid string, sign *pb.DBSign) (err error) { + if !utils.IsToday(sign.SignTime) { + sign.SignCount += 1 + count := sign.SignCount + update := map[string]interface{}{ + "signCount": count, + "signTime": time.Now().UTC(), + } + this.ChangeUserSign(uid, update) + } + return +} + +// 重置签到数据 +func (this *ModelSign) resetSignData(uid string, sign *pb.DBSign) (err error) { + start, _ := utils.GetMonthStartEnd() + if sign.RTime < start { // 重置 + sign.RTime = time.Now().Unix() + sign.SignTime = sign.RTime + sign.SignCount = 1 + } + + if this.module.configure.GetSignResetConf(sign.Cid+1) != -1 { // 获取当前的组id + sign.Cid += 1 + } + + return +} diff --git a/modules/user/module.go b/modules/user/module.go index 19f9ce9ff..89986270d 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -47,6 +47,7 @@ type User struct { modelExpand *ModelExpand configure *modules.MCompConfigure service base.IRPCXService + modelSign *ModelSign // 签到 } func (this *User) GetType() core.M_Modules { diff --git a/pb/pagoda_msg.pb.go b/pb/pagoda_msg.pb.go index cd1306b54..d715d0307 100644 --- a/pb/pagoda_msg.pb.go +++ b/pb/pagoda_msg.pb.go @@ -672,7 +672,7 @@ type PagodaActivateResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Data *DBSeasonPagoda `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` + Data *DBPagoda `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` } func (x *PagodaActivateResp) Reset() { @@ -707,7 +707,7 @@ func (*PagodaActivateResp) Descriptor() ([]byte, []int) { return file_pagoda_pagoda_msg_proto_rawDescGZIP(), []int{13} } -func (x *PagodaActivateResp) GetData() *DBSeasonPagoda { +func (x *PagodaActivateResp) GetData() *DBPagoda { if x != nil { return x.Data } @@ -772,12 +772,12 @@ var file_pagoda_pagoda_msg_proto_rawDesc = []byte{ 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x44, 0x42, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x61, 0x67, - 0x6f, 0x64, 0x61, 0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x22, 0x39, + 0x6f, 0x64, 0x61, 0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x22, 0x33, 0x0a, 0x12, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x44, 0x42, 0x53, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x50, 0x61, 0x67, - 0x6f, 0x64, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, - 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x44, 0x42, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -813,7 +813,6 @@ var file_pagoda_pagoda_msg_proto_goTypes = []interface{}{ (*BattleInfo)(nil), // 16: BattleInfo (*BattleReport)(nil), // 17: BattleReport (*DBPagodaRecord)(nil), // 18: DBPagodaRecord - (*DBSeasonPagoda)(nil), // 19: DBSeasonPagoda } var file_pagoda_pagoda_msg_proto_depIdxs = []int32{ 14, // 0: PagodaGetListResp.data:type_name -> DBPagoda @@ -824,7 +823,7 @@ var file_pagoda_pagoda_msg_proto_depIdxs = []int32{ 14, // 5: PagodaChallengeOverResp.data:type_name -> DBPagoda 18, // 6: PagodaRankListResp.ranks:type_name -> DBPagodaRecord 18, // 7: PagodaQueryRecordResp.data:type_name -> DBPagodaRecord - 19, // 8: PagodaActivateResp.data:type_name -> DBSeasonPagoda + 14, // 8: PagodaActivateResp.data:type_name -> DBPagoda 9, // [9:9] is the sub-list for method output_type 9, // [9:9] is the sub-list for method input_type 9, // [9:9] is the sub-list for extension type_name diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 137d46d2a..e4e0126a1 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -477,6 +477,7 @@ type DBSign struct { SignCount int32 `protobuf:"varint,4,opt,name=signCount,proto3" json:"signCount" bson:"signCount"` //玩家累计签到次数 Group int32 `protobuf:"varint,5,opt,name=group,proto3" json:"group"` // 签到组id Cid int32 `protobuf:"varint,6,opt,name=cid,proto3" json:"cid"` //记录循环签到值,客户端忽略这个字段 + RTime int64 `protobuf:"varint,7,opt,name=rTime,proto3" json:"rTime" bson:"rTime"` //刷新时间 } func (x *DBSign) Reset() { @@ -553,6 +554,13 @@ func (x *DBSign) GetCid() int32 { return 0 } +func (x *DBSign) GetRTime() int64 { + if x != nil { + return x.RTime + } + return 0 +} + var File_user_user_db_proto protoreflect.FileDescriptor var file_user_user_db_proto_rawDesc = []byte{ @@ -621,7 +629,7 @@ var file_user_user_db_proto_rawDesc = []byte{ 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x78, 0x75, 0x61, 0x6e, 0x73, 0x68, 0x61, 0x6e, 0x67, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x78, 0x75, 0x61, 0x6e, 0x73, 0x68, 0x61, 0x6e, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x61, 0x69, 0x6a, 0x69, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, - 0x73, 0x61, 0x69, 0x6a, 0x69, 0x22, 0x8c, 0x01, 0x0a, 0x06, 0x44, 0x42, 0x53, 0x69, 0x67, 0x6e, + 0x73, 0x61, 0x69, 0x6a, 0x69, 0x22, 0xa2, 0x01, 0x0a, 0x06, 0x44, 0x42, 0x53, 0x69, 0x67, 0x6e, 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, 0x73, 0x69, 0x67, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x03, @@ -630,8 +638,9 @@ var file_user_user_db_proto_rawDesc = []byte{ 0x05, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x03, 0x63, 0x69, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x03, 0x63, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x05, 0x72, 0x54, 0x69, 0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/utils/time.go b/utils/time.go index cf675b139..170b83381 100644 --- a/utils/time.go +++ b/utils/time.go @@ -79,3 +79,16 @@ func IsInCDHour(cdTime int64) bool { } return time.Now().Unix() < cdTime } + +// 获取本月的开始和结束的时间戳 +func GetMonthStartEnd() (int64, int64) { + t := time.Now() + monthStartDay := t.AddDate(0, 0, -t.Day()+1) + monthStartTime := time.Date(monthStartDay.Year(), monthStartDay.Month(), monthStartDay.Day(), 0, 0, 0, 0, t.Location()) + monthEndDay := monthStartTime.AddDate(0, 1, -1) + monthEndTime := time.Date(monthEndDay.Year(), monthEndDay.Month(), monthEndDay.Day(), 23, 59, 59, 0, t.Location()) + _d1 := monthStartTime.Unix() + _d2 := monthEndTime.Unix() + fmt.Printf("%d,%d", _d1, _d2) + return _d1, _d2 +}