活动领奖

This commit is contained in:
meixiongfeng 2023-08-01 15:47:15 +08:00
parent 5b1a020ffa
commit 6a6219805e
9 changed files with 183 additions and 42 deletions

View File

@ -975,6 +975,9 @@ const (
)
const (
HdTypeSign = 9 // 七日签到
HdTypeWarorder = 1 // 圣桃战令类型
HdTypePay = 2 // 圣桃充值礼包
)

View File

@ -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 {

View File

@ -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,
})

View File

@ -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,
})

View File

@ -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
}

View File

@ -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)
}

View File

@ -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 {
}
}
}

View File

@ -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"`

View File

@ -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{} {