公会任务优化

This commit is contained in:
wh_zcy 2023-01-05 14:39:27 +08:00
parent 1bd3981702
commit 0eb842110e
5 changed files with 77 additions and 51 deletions

View File

@ -261,6 +261,7 @@ const ( //Rpc
//公会任务列表
Rpc_ModuleSociatyTask core.Rpc_Key = "Rpc_ModuleSociatyTask"
Rpc_ModuleSociatyGetTask core.Rpc_Key = "Rpc_ModuleSociatyGetTask"
// RPC 通知来了邮件
Rpc_Mail core.Rpc_Key = "Rpc_Mail"

View File

@ -30,11 +30,14 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.SociatyReceiveRe
return
}
// 判断奖励是否已领
sociatyTask := this.module.modelSociaty.getUserTaskList(uid, sociaty.Id)
sociatyTask := this.module.modelSociatyTask.getUserTask(uid, sociaty.Id)
for _, v := range sociatyTask.TaskList {
if v.TaskId == req.TaskId {
if v.Status == 1 { //已领取
if v.Status != 1 {
code = pb.ErrorCode_SociatyTaskValidation
return
}
if v.Received == 1 { //已领取
code = pb.ErrorCode_SociatyRewardReceived
return
}
@ -42,18 +45,6 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.SociatyReceiveRe
}
}
// 验证任务是否完成
if err, ok := this.module.modelSociaty.validTask(uid, req.TaskId); err != nil || !ok {
code = pb.ErrorCode_SociatyTaskValidation
this.module.Error("公会任务未通过",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "sociatyId", Value: sociaty.Id},
log.Field{Key: "taskId", Value: req.TaskId},
log.Field{Key: "err", Value: err.Error()},
)
return
}
// 奖励领取
if err := this.module.modelSociatyTask.receive(req.TaskId, sociaty.Id, uid); err != nil {
code = pb.ErrorCode_SociatyRewardReceive

View File

@ -1,12 +1,16 @@
package sociaty
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go_dreamfactory/utils"
"go.mongodb.org/mongo-driver/bson"
)
type ModelSociatyTask struct {
@ -72,14 +76,25 @@ func (this *ModelSociatyTask) receive(taskId int32, sociatyId, uid string) error
this.GetListObj(sociatyId, uid, sociatyTask)
for _, t := range sociatyTask.TaskList {
if t.TaskId == taskId {
t.Status = 1 //领取
t.Received = 1 //领取
break
}
}
update := map[string]interface{}{
"taskList": sociatyTask.TaskList,
}
return this.ChangeList(sociatyId, uid, update)
if err := this.Redis.HMSet(fmt.Sprintf("%s:%s-%s", this.TableName,
sociatyId, uid), update); err != nil {
log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err.Error()})
return err
}
if err := this.UpdateModelLogs(this.TableName,
uid, bson.M{"sociatyid": sociatyId, "uid": uid}, update); err != nil {
return err
}
return nil
}
// 活跃度奖励领取

View File

@ -65,6 +65,7 @@ func (this *Sociaty) Start() (err error) {
this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociaty), this.RpcGetSociaty)
this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociatyUpdate), this.RpcUpdateSociaty)
this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociatyTask), this.RpcUpdateUserTask)
this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociatyGetTask), this.RpcGetUserTask)
this.globalConf = this.configure.GetGlobalConf()
if this.globalConf == nil {
err = errors.New("global config not found")
@ -238,7 +239,11 @@ func (this *Sociaty) TaskcondNotify(uid, sociatyId string, condId int32) error {
log.Field{Key: "uid", Value: uid},
log.Field{Key: "sociatyId", Value: sociatyId},
log.Field{Key: "condId", Value: condId})
dt := this.modelSociatyTask.getUserTask(uid, sociatyId)
dt := &pb.DBSociatyTask{}
err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(),
comm.Service_Worker, string(comm.Rpc_ModuleSociatyGetTask),
&pb.RPCGeneralReqA2{Param1: sociatyId, Param2: uid}, dt)
var flag bool
for _, v := range dt.TaskList {
@ -257,7 +262,7 @@ func (this *Sociaty) TaskcondNotify(uid, sociatyId string, condId int32) error {
"lastUpdateTime": configure.Now().Unix(),
}
err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(),
err = this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(),
comm.Service_Worker, string(comm.Rpc_ModuleSociatyTask),
&TaskParams{SociatyId: sociatyId, Uid: uid, Data: update}, &pb.EmptyResp{})
if err != nil {
@ -283,14 +288,18 @@ func (this *Sociaty) RpcUpdateUserTask(ctx context.Context, p *TaskParams, reply
p.Uid, bson.M{"sociatyid": p.SociatyId, "uid": p.Uid}, p.Data); err != nil {
return err
}
// task := &pb.DBSociatyTask{}
// if err := model.GetListObj(p.Param1, p.Param2, task); err != nil {
// return err
// }
// reply.TaskList = task.TaskList
// reply.Uid = task.Uid
// reply.ActivityList = task.ActivityList
// reply.SociatyId = task.SociatyId
// reply.LastUpdateTime = task.LastUpdateTime
return nil
}
func (this *Sociaty) RpcGetUserTask(ctx context.Context, p *pb.RPCGeneralReqA2, reply *pb.DBSociatyTask) error {
dt := this.modelSociatyTask.getUserTask(p.Param2, p.Param1)
if dt == nil {
return errors.New("not found")
}
reply.Uid = dt.Uid
reply.TaskList = dt.TaskList
reply.ActivityList = dt.ActivityList
reply.SociatyId = dt.SociatyId
reply.LastUpdateTime = dt.LastUpdateTime
return nil
}

View File

@ -585,7 +585,8 @@ type SociatyTask struct {
unknownFields protoimpl.UnknownFields
TaskId int32 `protobuf:"varint,1,opt,name=taskId,proto3" json:"taskId" bson:"taskId"` //任务ID
Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status" bson:"status"` //领取状态:0未领取 1已领取
Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status" bson:"status"` //领取状态:0未完成 1已完成
Received int32 `protobuf:"varint,3,opt,name=received,proto3" json:"received" bson:"received"` //领取状态: 0未领取 1已领取
}
func (x *SociatyTask) Reset() {
@ -634,6 +635,13 @@ func (x *SociatyTask) GetStatus() int32 {
return 0
}
func (x *SociatyTask) GetReceived() int32 {
if x != nil {
return x.Received
}
return 0
}
// 活跃度
type SociatyActivity struct {
state protoimpl.MessageState
@ -839,29 +847,31 @@ var file_sociaty_sociaty_db_proto_rawDesc = []byte{
0x74, 0x79, 0x52, 0x0c, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x4c, 0x69, 0x73, 0x74,
0x12, 0x26, 0x0a, 0x0e, 0x6c, 0x61, 0x73, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69,
0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x6c, 0x61, 0x73, 0x74, 0x55, 0x70,
0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x3d, 0x0a, 0x0b, 0x53, 0x6f, 0x63, 0x69,
0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x59, 0x0a, 0x0b, 0x53, 0x6f, 0x63, 0x69,
0x61, 0x74, 0x79, 0x54, 0x61, 0x73, 0x6b, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x12,
0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52,
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x39, 0x0a, 0x0f, 0x53, 0x6f, 0x63, 0x69, 0x61,
0x74, 0x79, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74,
0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74,
0x75, 0x73, 0x22, 0x83, 0x01, 0x0a, 0x0d, 0x44, 0x42, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79,
0x52, 0x61, 0x6e, 0x6b, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79,
0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x03, 0x20, 0x01,
0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69,
0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69,
0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28,
0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x2a, 0x50, 0x0a, 0x0a, 0x53, 0x6f, 0x63, 0x69,
0x61, 0x74, 0x79, 0x4a, 0x6f, 0x62, 0x12, 0x09, 0x0a, 0x05, 0x4e, 0x4f, 0x4a, 0x4f, 0x42, 0x10,
0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4d, 0x45, 0x4d, 0x42, 0x45, 0x52, 0x10, 0x01, 0x12, 0x09, 0x0a,
0x05, 0x41, 0x44, 0x4d, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x56, 0x49, 0x43, 0x45,
0x50, 0x52, 0x45, 0x53, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x50,
0x52, 0x45, 0x53, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69,
0x76, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69,
0x76, 0x65, 0x64, 0x22, 0x39, 0x0a, 0x0f, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x41, 0x63,
0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73,
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x83,
0x01, 0x0a, 0x0d, 0x44, 0x42, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x52, 0x61, 0x6e, 0x6b,
0x12, 0x1c, 0x0a, 0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x12, 0x12,
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02,
0x6c, 0x76, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x18, 0x04,
0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x12, 0x14,
0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63,
0x74, 0x69, 0x6d, 0x65, 0x2a, 0x50, 0x0a, 0x0a, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x4a,
0x6f, 0x62, 0x12, 0x09, 0x0a, 0x05, 0x4e, 0x4f, 0x4a, 0x4f, 0x42, 0x10, 0x00, 0x12, 0x0a, 0x0a,
0x06, 0x4d, 0x45, 0x4d, 0x42, 0x45, 0x52, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x44, 0x4d,
0x49, 0x4e, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x56, 0x49, 0x43, 0x45, 0x50, 0x52, 0x45, 0x53,
0x49, 0x44, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x52, 0x45, 0x53, 0x49,
0x44, 0x45, 0x4e, 0x54, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (