diff --git a/comm/const.go b/comm/const.go index 952aa436e..05492aa9c 100644 --- a/comm/const.go +++ b/comm/const.go @@ -983,10 +983,9 @@ const ( ) const ( - HdTypeSign = 9 // 七日签到 - HdTypeWarorder = 1 // 圣桃战令类型 HdTypePay = 2 // 圣桃充值礼包 - - KFSevenTask = 3 //开服任务 + KFSevenTask = 3 //开服任务 + HdLevel = 4 //开服等级活动 + HdTypeSign = 5 // 七日签到 ) diff --git a/modules/activity/api_gethddata.go b/modules/activity/api_gethddata.go index 876a0c6d2..9a601fe81 100644 --- a/modules/activity/api_gethddata.go +++ b/modules/activity/api_gethddata.go @@ -1,6 +1,7 @@ package activity import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" @@ -13,41 +14,35 @@ func (this *apiComp) GetHdDataCheck(session comm.IUserSession, req *pb.ActivityG return } +// 活动活动 func (this *apiComp) GetHdData(session comm.IUserSession, req *pb.ActivityGetHdDataReq) (errdata *pb.ErrorData) { var ( - list *pb.DBActivityData - err error + result []*pb.DBActivityData + activity *pb.DBHuodong + err error ) - if req.Oid == "" { - - } else { - list, err = this.module.modelhdData.getHddataByOid(session.GetUserId(), req.Oid) - if err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DBError, - Title: pb.ErrorCode_DBError.ToString(), - } - return - } - - } - // 校验活动是否过期 - if a, err := this.module.modelhdList.getHdListByHdId(req.Oid); err != nil { - curTime := configure.Now().Unix() - - if a.Htype == comm.HdTypeSign && a.Stime <= curTime && curTime <= a.Etime { - if !utils.IsToday(list.Lasttime) { - list.Lasttime = curTime - list.Val += 1 - update := make(map[string]interface{}) - update["lasttime"] = list.Lasttime - update["val"] = list.Val - this.module.modelhdData.ModifyActivityList(session.GetUserId(), list.Id, update) + curTime := configure.Now().Unix() + for _, id := range req.Oid { + if activity, err = this.module.modelhdList.getHdListByHdId(id); err != nil { + if activity.Stime <= curTime && curTime <= activity.Etime { + continue } } + key := fmt.Sprintf("%s:%s", session.GetUserId(), id) + list, _ := this.module.modelhdData.getHddataByOid(session.GetUserId(), key) + if activity.Itype == comm.HdTypeSign && !utils.IsToday(list.Lasttime) { + list.Lasttime = curTime + list.Val += 1 + update := make(map[string]interface{}) + update["lasttime"] = list.Lasttime + update["val"] = list.Val + this.module.modelhdData.ModifyActivityList(session.GetUserId(), list.Id, update) + } + result = append(result, list) } + session.SendMsg(string(this.module.GetType()), "gethddata", &pb.ActivityGetHdDataResp{ - Data: []*pb.DBActivityData{list}, + Data: result, }) return } diff --git a/modules/activity/api_getreward.go b/modules/activity/api_getreward.go index 2879de49e..5e460c846 100644 --- a/modules/activity/api_getreward.go +++ b/modules/activity/api_getreward.go @@ -1,6 +1,7 @@ package activity import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" @@ -28,31 +29,47 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.ActivityGetRew reward []*cfg.Gameatn atno []*pb.UserAtno ) - if activity, err = this.module.modelhdList.getHdListByHdId(req.Oid); err != nil { - curTime := configure.Now().Unix() - - if activity.Stime <= curTime && curTime <= activity.Etime { + key := fmt.Sprintf("%s:%s", session.GetUserId(), req.Oid) + data, err := this.module.modelhdData.getHddataByOid(session.GetUserId(), key) + if err == nil { + if activity, err = this.module.modelhdList.getHdListByHdId(req.Oid); err == nil { + curTime := configure.Now().Unix() + if activity.Stime > curTime || curTime > activity.Etime { //不在活动时间范围内 + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ActivityNotIntime, + Title: pb.ErrorCode_ActivityNotIntime.ToString(), + } + return + } + } else { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ActivityInvalid, + Title: pb.ErrorCode_ActivityInvalid.ToString(), + } return } - } else { // 补充错误码 - return - } - data, err := this.module.modelhdData.getHddataByOid(session.GetUserId(), req.Oid) - if err != nil { + if data.Val <= req.Val { //没达到领奖条件 + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ActivityCantReward, + Title: pb.ErrorCode_ActivityCantReward.ToString(), + } + return + } + if data.Gotarr != nil { + if _, ok := data.Gotarr[req.Val]; ok { // 重复领奖 + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ActivityRepatReward, + Title: pb.ErrorCode_ActivityRepatReward.ToString(), + } + return + } + } + } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), } return - } else { - if data.Val <= req.Val { //没达到领奖条件 - return - } - if data.Gotarr != nil { - if _, ok := data.Gotarr[req.Val]; ok { // 重复领奖 - return - } - } } // 发奖 for _, v := range activity.Data.Prize { diff --git a/modules/activity/model_hddata.go b/modules/activity/model_hddata.go index 0b537afdc..839e1f74a 100644 --- a/modules/activity/model_hddata.go +++ b/modules/activity/model_hddata.go @@ -1,6 +1,7 @@ package activity import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" @@ -30,8 +31,7 @@ func (this *modelhdData) Init(service core.IService, module core.IModule, comp c } // 获取所有活动数据 -func (this *modelhdData) getHdAlldata(uid string, oid string) (result []*pb.DBActivityData, err error) { - +func (this *modelhdData) getHdAlldata(uid string) (result []*pb.DBActivityData, err error) { result = make([]*pb.DBActivityData, 0) if err = this.GetList(uid, &result); err != nil { this.module.Errorf("err:%v", err) @@ -42,9 +42,20 @@ func (this *modelhdData) getHdAlldata(uid string, oid string) (result []*pb.DBAc // 通过活动唯一ID 获取活动数据 func (this *modelhdData) getHddataByOid(uid string, oid string) (result *pb.DBActivityData, err error) { - result = &pb.DBActivityData{} - if err = this.GetListObj(uid, oid, &result); err != nil { - this.module.Errorf("err:%v", err) + result = &pb.DBActivityData{ + Id: "", + Uid: uid, + Hdoid: oid, + Gotarr: map[int32]int32{}, + Lasttime: 0, + Val: 0, + } + if err = this.GetListObj(uid, oid, &result); err == mongo.ErrNoDocuments { + result.Id = fmt.Sprintf("%s:%s", uid, oid) + result.Uid = uid + result.Hdoid = oid + this.AddList(uid, result.Id, result) + err = nil return } return diff --git a/pb/activity_db.pb.go b/pb/activity_db.pb.go index 54994408a..f1031592b 100644 --- a/pb/activity_db.pb.go +++ b/pb/activity_db.pb.go @@ -327,7 +327,7 @@ type DBActivityData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //自定义id uid+hdoid Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"` Hdoid string `protobuf:"bytes,3,opt,name=hdoid,proto3" json:"hdoid"` // 活动唯一id Gotarr map[int32]int32 `protobuf:"bytes,4,rep,name=gotarr,proto3" json:"gotarr" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` diff --git a/pb/activity_msg.pb.go b/pb/activity_msg.pb.go index 755dfd7cd..d701152fc 100644 --- a/pb/activity_msg.pb.go +++ b/pb/activity_msg.pb.go @@ -112,7 +112,7 @@ type ActivityGetHdDataReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Oid string `protobuf:"bytes,1,opt,name=oid,proto3" json:"oid"` // obj 为空 取所有的活动 + Oid []string `protobuf:"bytes,1,rep,name=oid,proto3" json:"oid"` // } func (x *ActivityGetHdDataReq) Reset() { @@ -147,11 +147,11 @@ func (*ActivityGetHdDataReq) Descriptor() ([]byte, []int) { return file_activity_activity_msg_proto_rawDescGZIP(), []int{2} } -func (x *ActivityGetHdDataReq) GetOid() string { +func (x *ActivityGetHdDataReq) GetOid() []string { if x != nil { return x.Oid } - return "" + return nil } // 获取活动数据列表 @@ -208,7 +208,7 @@ type ActivityGetRewardReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Oid string `protobuf:"bytes,1,opt,name=oid,proto3" json:"oid"` // 活动唯一id + Oid string `protobuf:"bytes,1,opt,name=oid,proto3" json:"oid"` Val int32 `protobuf:"varint,2,opt,name=val,proto3" json:"val"` } @@ -328,7 +328,7 @@ var file_activity_activity_msg_proto_rawDesc = []byte{ 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x48, 0x75, 0x6f, 0x64, 0x6f, 0x6e, 0x67, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x28, 0x0a, 0x14, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x47, 0x65, 0x74, 0x48, 0x64, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x6f, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6f, 0x69, 0x64, 0x22, 0x3c, 0x0a, 0x15, + 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x6f, 0x69, 0x64, 0x22, 0x3c, 0x0a, 0x15, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x47, 0x65, 0x74, 0x48, 0x64, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x44, 0x42, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index a16dd0d16..0aa1db5b6 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -424,6 +424,13 @@ const ( ErrorCode_StonehengeEnterRoomFailed ErrorCode = 4904 // 进入房间失败 ErrorCode_StonehengeRepeatedReward ErrorCode = 4905 // 事件重复完成 ErrorCode_StonehengeGotoRoomFailed ErrorCode = 4906 // 进入房间失败 + // 活动错误码 + ErrorCode_ActivityOver ErrorCode = 5001 //活动结束 + ErrorCode_ActivityUnOpened ErrorCode = 5002 // 活动未开启 + ErrorCode_ActivityRepatReward ErrorCode = 5003 // 重复领取 + ErrorCode_ActivityNotIntime ErrorCode = 5004 // 不在活动时间范围 + ErrorCode_ActivityInvalid ErrorCode = 5005 // 不存在的活动 + ErrorCode_ActivityCantReward ErrorCode = 5006 // 还不能领奖 ) // Enum value maps for ErrorCode. @@ -788,6 +795,12 @@ var ( 4904: "StonehengeEnterRoomFailed", 4905: "StonehengeRepeatedReward", 4906: "StonehengeGotoRoomFailed", + 5001: "ActivityOver", + 5002: "ActivityUnOpened", + 5003: "ActivityRepatReward", + 5004: "ActivityNotIntime", + 5005: "ActivityInvalid", + 5006: "ActivityCantReward", } ErrorCode_value = map[string]int32{ "Success": 0, @@ -1149,6 +1162,12 @@ var ( "StonehengeEnterRoomFailed": 4904, "StonehengeRepeatedReward": 4905, "StonehengeGotoRoomFailed": 4906, + "ActivityOver": 5001, + "ActivityUnOpened": 5002, + "ActivityRepatReward": 5003, + "ActivityNotIntime": 5004, + "ActivityInvalid": 5005, + "ActivityCantReward": 5006, } ) @@ -1183,7 +1202,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0xb4, 0x42, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xbf, 0x43, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, @@ -1714,8 +1733,17 @@ var file_errorcode_proto_rawDesc = []byte{ 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x10, 0xa9, 0x26, 0x12, 0x1d, 0x0a, 0x18, 0x53, 0x74, 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x47, 0x6f, 0x74, 0x6f, 0x52, 0x6f, 0x6f, 0x6d, 0x46, - 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0xaa, 0x26, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0xaa, 0x26, 0x12, 0x11, 0x0a, 0x0c, 0x41, 0x63, 0x74, 0x69, + 0x76, 0x69, 0x74, 0x79, 0x4f, 0x76, 0x65, 0x72, 0x10, 0x89, 0x27, 0x12, 0x15, 0x0a, 0x10, 0x41, + 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x55, 0x6e, 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x10, + 0x8a, 0x27, 0x12, 0x18, 0x0a, 0x13, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x52, 0x65, + 0x70, 0x61, 0x74, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x10, 0x8b, 0x27, 0x12, 0x16, 0x0a, 0x11, + 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x4e, 0x6f, 0x74, 0x49, 0x6e, 0x74, 0x69, 0x6d, + 0x65, 0x10, 0x8c, 0x27, 0x12, 0x14, 0x0a, 0x0f, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, + 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x8d, 0x27, 0x12, 0x17, 0x0a, 0x12, 0x41, 0x63, + 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x43, 0x61, 0x6e, 0x74, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, + 0x10, 0x8e, 0x27, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var (