From 6a6219805ee43c72afa944f563f8889755caa531 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 1 Aug 2023 15:47:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E9=A2=86=E5=A5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 3 ++ comm/imodule.go | 2 +- modules/activity/api_gethddata.go | 20 +++++++- modules/activity/api_getlist.go | 1 + modules/activity/api_getreward.go | 81 +++++++++++++++++++++++++++++++ modules/activity/model_hddata.go | 25 +++++++--- modules/activity/module.go | 19 +++++++- pb/activity_db.pb.go | 2 +- pb/activity_msg.pb.go | 72 ++++++++++++++++----------- 9 files changed, 183 insertions(+), 42 deletions(-) create mode 100644 modules/activity/api_getreward.go diff --git a/comm/const.go b/comm/const.go index 5d15b1872..539b97465 100644 --- a/comm/const.go +++ b/comm/const.go @@ -975,6 +975,9 @@ const ( ) const ( + HdTypeSign = 9 // 七日签到 + HdTypeWarorder = 1 // 圣桃战令类型 HdTypePay = 2 // 圣桃充值礼包 + ) diff --git a/comm/imodule.go b/comm/imodule.go index 5f4fab64b..28f8a79d7 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -594,7 +594,7 @@ type ( GetHdInfoByHdId(oid string) (result *pb.DBHuodong, err error) // 通过活动id 获取活动信息 GetAllHdInfo() (result []*pb.DBHuodong, err error) // 获取所有活动信息 - UpdateActivitySlider(session IUserSession, oid string, val int32) // 修改活动进度 + UpdateActivitySlider(session IUserSession) // 修改活动进度 } //每日任务 IDailytask interface { diff --git a/modules/activity/api_gethddata.go b/modules/activity/api_gethddata.go index fc9c97a43..ecefe3487 100644 --- a/modules/activity/api_gethddata.go +++ b/modules/activity/api_gethddata.go @@ -3,6 +3,8 @@ package activity import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + "go_dreamfactory/utils" ) //参数校验 @@ -13,7 +15,7 @@ func (this *apiComp) GetHdDataCheck(session comm.IUserSession, req *pb.ActivityG func (this *apiComp) GetHdData(session comm.IUserSession, req *pb.ActivityGetHdDataReq) (errdata *pb.ErrorData) { - list, err := this.module.modelhdData.getHddata(session.GetUserId(), req.Oid) + list, err := this.module.modelhdData.getHddataByOid(session.GetUserId(), req.Oid) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, @@ -21,6 +23,22 @@ func (this *apiComp) GetHdData(session comm.IUserSession, req *pb.ActivityGetHdD } return } + // 校验活动是否过期 + if a, err := this.module.modelhdList.getHdInfoByHdId(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) + } + } + } + session.SendMsg(string(this.module.GetType()), "gethddata", &pb.ActivityGetHdDataResp{ Data: list, }) diff --git a/modules/activity/api_getlist.go b/modules/activity/api_getlist.go index c8f3713a4..00a4e4d84 100644 --- a/modules/activity/api_getlist.go +++ b/modules/activity/api_getlist.go @@ -22,6 +22,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.ActivityGetListR } return } + session.SendMsg(string(this.module.GetType()), "getlist", &pb.ActivityGetListResp{ Data: list, }) diff --git a/modules/activity/api_getreward.go b/modules/activity/api_getreward.go new file mode 100644 index 000000000..9de0bd079 --- /dev/null +++ b/modules/activity/api_getreward.go @@ -0,0 +1,81 @@ +package activity + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" +) + +//参数校验 +func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.ActivityGetRewardReq) (errdata *pb.ErrorData) { + if req.Oid == "" { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + } + } + return +} + +func (this *apiComp) GetReward(session comm.IUserSession, req *pb.ActivityGetRewardReq) (errdata *pb.ErrorData) { + if errdata = this.GetRewardCheck(session, req); errdata != nil { + return + } + var ( + activity *pb.DBHuodong // 活动数据 + err error + reward []*cfg.Gameatn + atno []*pb.UserAtno + ) + if activity, err = this.module.modelhdList.getHdInfoByHdId(req.Oid); err != nil { + curTime := configure.Now().Unix() + + if activity.Stime <= curTime && curTime <= activity.Etime { + return + } + } else { // 补充错误码 + return + } + data, 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 + } 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 { + if v.Val == req.Val { + for _, v1 := range v.Prize { + reward = append(reward, &cfg.Gameatn{ + A: v1.A, + T: v1.T, + N: v1.N, + }) + } + if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata != nil { + return + } + } + } + data.Gotarr[req.Val] = true + update := make(map[string]interface{}) + update["gotarr"] = data.Gotarr + this.module.modelhdData.ModifyActivityList(session.GetUserId(), data.Id, update) + session.SendMsg(string(this.module.GetType()), "getreward", &pb.ActivityGetRewardResp{ + Data: data, + Atno: atno, + }) + return +} diff --git a/modules/activity/model_hddata.go b/modules/activity/model_hddata.go index 40855e768..0b537afdc 100644 --- a/modules/activity/model_hddata.go +++ b/modules/activity/model_hddata.go @@ -1,7 +1,6 @@ package activity import ( - "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" @@ -30,11 +29,21 @@ func (this *modelhdData) Init(service core.IService, module core.IModule, comp c return } -// 获取用户活动数据 -func (this *modelhdData) getHddata(uid string, oid string) (result []*pb.DBActivityData, err error) { - key := fmt.Sprintf("%s:%s-%s", this.TableName, uid, oid) +// 获取所有活动数据 +func (this *modelhdData) getHdAlldata(uid string, oid string) (result []*pb.DBActivityData, err error) { + result = make([]*pb.DBActivityData, 0) - if err = this.GetList(key, &result); err != nil { + if err = this.GetList(uid, &result); err != nil { + this.module.Errorf("err:%v", err) + return + } + return +} + +// 通过活动唯一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) return } @@ -42,14 +51,14 @@ func (this *modelhdData) getHddata(uid string, oid string) (result []*pb.DBActiv } // 新增一条活动数据 -func (this *modelhdData) Insert(key string, data *pb.DBActivityData) (err error) { - if err = this.AddList(key, data.Id, data); err != nil { +func (this *modelhdData) InsertHddata(uid string, data *pb.DBActivityData) (err error) { + if err = this.AddList(uid, data.Id, data); err != nil { this.module.Errorf("err:%v", err) return } return } -func (this *modelhdData) modifyActivityList(uid string, oid string, data map[string]interface{}) error { +func (this *modelhdData) ModifyActivityList(uid string, oid string, data map[string]interface{}) error { return this.ChangeList(uid, oid, data) } diff --git a/modules/activity/module.go b/modules/activity/module.go index 63c564680..6825922f8 100644 --- a/modules/activity/module.go +++ b/modules/activity/module.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" ) @@ -66,7 +67,15 @@ func (this *Activity) Start() (err error) { } } } - + // ac := &pb.DBActivityData{ + // Id: "", + // Uid: "", + // Hdoid: "64c8a90e510317d18960964a", + // Gotarr: map[int32]bool{}, + // Lasttime: configure.Now().Unix(), + // Val: 1, + // } + // this.modelhdData.InsertHddata("", ac) } return @@ -139,6 +148,12 @@ func (this *Activity) GetHdInfoByHdId(oid string) (result *pb.DBHuodong, err err return } -func (this *Activity) UpdateActivitySlider(session comm.IUserSession, oid string, val int32) { +// 更新签到进度 +func (this *Activity) UpdateSingnActivitySlider(session comm.IUserSession) { + curTime := configure.Now().Unix() + if rst, err := this.modelhdList.getHdInfoByHdType(comm.HdTypeSign); err == nil { + if rst.Stime <= curTime && curTime <= rst.Etime { + } + } } diff --git a/pb/activity_db.pb.go b/pb/activity_db.pb.go index a24db8d8e..66aee3609 100644 --- a/pb/activity_db.pb.go +++ b/pb/activity_db.pb.go @@ -128,7 +128,7 @@ type DBHuodong struct { unknownFields protoimpl.UnknownFields Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Hdid int32 `protobuf:"varint,2,opt,name=hdid,proto3" json:"hdid"` // 活动ID + Hdid int32 `protobuf:"varint,2,opt,name=hdid,proto3" json:"hdid"` // 活动ID 此字段不用 Rtime int64 `protobuf:"varint,3,opt,name=rtime,proto3" json:"rtime"` // 客户端显示的时间 Itype int32 `protobuf:"varint,4,opt,name=itype,proto3" json:"itype"` Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name"` diff --git a/pb/activity_msg.pb.go b/pb/activity_msg.pb.go index 9834824f8..0bb6a2f8e 100644 --- a/pb/activity_msg.pb.go +++ b/pb/activity_msg.pb.go @@ -159,7 +159,7 @@ type ActivityGetHdDataResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Data []*DBActivityData `protobuf:"bytes,1,rep,name=data,proto3" json:"data"` + Data *DBActivityData `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` } func (x *ActivityGetHdDataResp) Reset() { @@ -194,7 +194,7 @@ func (*ActivityGetHdDataResp) Descriptor() ([]byte, []int) { return file_activity_activity_msg_proto_rawDescGZIP(), []int{3} } -func (x *ActivityGetHdDataResp) GetData() []*DBActivityData { +func (x *ActivityGetHdDataResp) GetData() *DBActivityData { if x != nil { return x.Data } @@ -264,6 +264,7 @@ type ActivityGetRewardResp struct { unknownFields protoimpl.UnknownFields Data *DBActivityData `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` + Atno []*UserAtno `protobuf:"bytes,2,rep,name=atno,proto3" json:"atno"` } func (x *ActivityGetRewardResp) Reset() { @@ -305,33 +306,43 @@ func (x *ActivityGetRewardResp) GetData() *DBActivityData { return nil } +func (x *ActivityGetRewardResp) GetAtno() []*UserAtno { + if x != nil { + return x.Atno + } + return nil +} + var File_activity_activity_msg_proto protoreflect.FileDescriptor var file_activity_activity_msg_proto_rawDesc = []byte{ 0x0a, 0x1b, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2f, 0x61, 0x63, 0x74, 0x69, 0x76, - 0x69, 0x74, 0x79, 0x5f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1a, 0x61, - 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2f, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, - 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x63, 0x74, - 0x69, 0x76, 0x69, 0x74, 0x79, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, - 0x35, 0x0a, 0x13, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x47, 0x65, 0x74, 0x4c, 0x69, - 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 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, 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, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3a, - 0x0a, 0x14, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x47, 0x65, 0x74, 0x52, 0x65, 0x77, - 0x61, 0x72, 0x64, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x6f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6f, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x3c, 0x0a, 0x15, 0x41, 0x63, + 0x69, 0x74, 0x79, 0x5f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0a, 0x63, + 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1a, 0x61, 0x63, 0x74, 0x69, 0x76, + 0x69, 0x74, 0x79, 0x2f, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x5f, 0x64, 0x62, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, + 0x79, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x35, 0x0a, 0x13, 0x41, + 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 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, + 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, + 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x44, 0x42, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, + 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3a, 0x0a, 0x14, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x47, 0x65, 0x74, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x52, - 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x0f, 0x2e, 0x44, 0x42, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x44, 0x61, - 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x6f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6f, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x5b, 0x0a, 0x15, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, + 0x74, 0x79, 0x47, 0x65, 0x74, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, + 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, + 0x44, 0x42, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x12, 0x1d, 0x0a, 0x04, 0x61, 0x74, 0x6e, 0x6f, 0x18, 0x02, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x74, 0x6e, 0x6f, 0x52, 0x04, 0x61, + 0x74, 0x6e, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -356,16 +367,18 @@ var file_activity_activity_msg_proto_goTypes = []interface{}{ (*ActivityGetRewardResp)(nil), // 5: ActivityGetRewardResp (*DBHuodong)(nil), // 6: DBHuodong (*DBActivityData)(nil), // 7: DBActivityData + (*UserAtno)(nil), // 8: UserAtno } var file_activity_activity_msg_proto_depIdxs = []int32{ 6, // 0: ActivityGetListResp.data:type_name -> DBHuodong 7, // 1: ActivityGetHdDataResp.data:type_name -> DBActivityData 7, // 2: ActivityGetRewardResp.data:type_name -> DBActivityData - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 8, // 3: ActivityGetRewardResp.atno:type_name -> UserAtno + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_activity_activity_msg_proto_init() } @@ -373,6 +386,7 @@ func file_activity_activity_msg_proto_init() { if File_activity_activity_msg_proto != nil { return } + file_comm_proto_init() file_activity_activity_db_proto_init() if !protoimpl.UnsafeEnabled { file_activity_activity_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {