公会任务优化
This commit is contained in:
parent
e4be401bdb
commit
a686976b28
@ -259,6 +259,9 @@ const ( //Rpc
|
||||
// 公会更新
|
||||
Rpc_ModuleSociatyUpdate core.Rpc_Key = "Rpc_ModuleSociatyUpdate"
|
||||
|
||||
//公会任务列表
|
||||
Rpc_ModuleSociatyTask core.Rpc_Key = "Rpc_ModuleSociatyTask"
|
||||
|
||||
// RPC 通知来了邮件
|
||||
Rpc_Mail core.Rpc_Key = "Rpc_Mail"
|
||||
)
|
||||
|
@ -282,6 +282,8 @@ type (
|
||||
BingoSetExp(session IUserSession, exp int32) error
|
||||
// 设置工会活跃度
|
||||
BingoSetActivity(session IUserSession, activity int32) error
|
||||
// 任务条件达成通知
|
||||
TaskcondNotify(uid, sociatyId string, condId int32) error
|
||||
///红点
|
||||
IReddot
|
||||
}
|
||||
|
@ -184,7 +184,9 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
|
||||
})
|
||||
case comm.Rtype63:
|
||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||
find: this.modelRtaskRecord.equalFirstParam,
|
||||
verify: this.modelRtask.verifyRtype63,
|
||||
update: this.modelRtaskRecord.addUpdate,
|
||||
})
|
||||
case comm.Rtype16, comm.Rtype17,
|
||||
comm.Rtype35, comm.Rtype44,
|
||||
@ -291,33 +293,60 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
|
||||
if code := this.CheckCondi(uid, conf.Id); code == pb.ErrorCode_Success {
|
||||
module, err := this.service.GetModule(comm.ModuleWorldtask)
|
||||
if err == nil {
|
||||
// 世界任务
|
||||
if worldtask, ok := module.(comm.IWorldtask); ok {
|
||||
if err := worldtask.TaskcondNotify(session, conf.Id); err != nil {
|
||||
var customErr = new(comm.CustomError)
|
||||
if errors.As(err, &customErr) {
|
||||
notifyErr := &pb.NotifyErrorNotifyPush{
|
||||
ReqMainType: string(comm.ModuleWorldtask),
|
||||
ReqSubType: "finish",
|
||||
Message: "",
|
||||
}
|
||||
go func() {
|
||||
// 世界任务
|
||||
if worldtask, ok := module.(comm.IWorldtask); ok {
|
||||
if err := worldtask.TaskcondNotify(session, conf.Id); err != nil {
|
||||
var customErr = new(comm.CustomError)
|
||||
if errors.As(err, &customErr) {
|
||||
notifyErr := &pb.NotifyErrorNotifyPush{
|
||||
ReqMainType: string(comm.ModuleWorldtask),
|
||||
ReqSubType: "finish",
|
||||
Message: "",
|
||||
}
|
||||
|
||||
if customErr.Code == pb.ErrorCode_WorldtaskLvNotEnough {
|
||||
notifyErr.Code = pb.ErrorCode_WorldtaskLvNotEnough
|
||||
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
|
||||
} else if customErr.Code == pb.ErrorCode_UserSessionNobeing {
|
||||
notifyErr.Code = pb.ErrorCode_UserSessionNobeing
|
||||
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
|
||||
} else {
|
||||
log.Error("任务条件达成通知",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "condId", Value: conf.Id},
|
||||
log.Field{Key: "err", Value: err.Error()},
|
||||
)
|
||||
if customErr.Code == pb.ErrorCode_WorldtaskLvNotEnough {
|
||||
notifyErr.Code = pb.ErrorCode_WorldtaskLvNotEnough
|
||||
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
|
||||
} else if customErr.Code == pb.ErrorCode_UserSessionNobeing {
|
||||
notifyErr.Code = pb.ErrorCode_UserSessionNobeing
|
||||
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
|
||||
} else {
|
||||
log.Error("任务条件达成通知",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "condId", Value: conf.Id},
|
||||
log.Field{Key: "err", Value: err.Error()},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
userModule, err := this.service.GetModule(comm.ModuleUser)
|
||||
if err == nil {
|
||||
go func() {
|
||||
// 公会
|
||||
if user, ok := userModule.(comm.IUser); ok {
|
||||
ex, err := user.GetUserExpand(session.GetUserId())
|
||||
if err == nil && ex.SociatyId != "" {
|
||||
sociatyModule, err := this.service.GetModule(comm.ModuleSociaty)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if sociaty, ok := sociatyModule.(comm.ISociaty); ok {
|
||||
if err2 := sociaty.TaskcondNotify(uid, ex.SociatyId, conf.Id); err2 != nil {
|
||||
log.Error("公会任务条件达成通知",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "sociatyId", Value: ex.SociatyId},
|
||||
log.Field{Key: "condId", Value: conf.Id},
|
||||
log.Field{Key: "err", Value: err2.Error()},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package sociaty
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/base"
|
||||
"go_dreamfactory/lego/core"
|
||||
@ -14,6 +15,9 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/sys/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
var _ comm.ISociaty = (*Sociaty)(nil)
|
||||
@ -60,6 +64,7 @@ func (this *Sociaty) Start() (err error) {
|
||||
err = this.ModuleBase.Start()
|
||||
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.globalConf = this.configure.GetGlobalConf()
|
||||
if this.globalConf == nil {
|
||||
err = errors.New("global config not found")
|
||||
@ -220,3 +225,72 @@ func (this *Sociaty) BingoSetActivity(session comm.IUserSession, activity int32)
|
||||
}
|
||||
return this.modelSociaty.updateSociaty(sociaty.Id, update)
|
||||
}
|
||||
|
||||
type TaskParams struct {
|
||||
SociatyId string
|
||||
Uid string
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
// 任务条件达成通知
|
||||
func (this *Sociaty) TaskcondNotify(uid, sociatyId string, condId int32) error {
|
||||
log.Debug("公会任务",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "sociatyId", Value: sociatyId},
|
||||
log.Field{Key: "condId", Value: condId})
|
||||
dt := this.modelSociatyTask.getUserTask(uid, sociatyId)
|
||||
|
||||
var flag bool
|
||||
for _, v := range dt.TaskList {
|
||||
if v.TaskId == condId {
|
||||
v.Status = 1
|
||||
flag = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !flag {
|
||||
return nil
|
||||
}
|
||||
|
||||
update := map[string]interface{}{
|
||||
"taskList": dt.TaskList,
|
||||
"lastUpdateTime": configure.Now().Unix(),
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *Sociaty) RpcUpdateUserTask(ctx context.Context, p *TaskParams, reply *pb.EmptyResp) error {
|
||||
conn, err := db.Local()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModel(comm.TableSociatyTask, 0, conn)
|
||||
|
||||
if err := model.Redis.HMSet(fmt.Sprintf("%s:%s-%s", this.modelSociatyTask.TableName,
|
||||
p.SociatyId, p.Uid), p.Data); err != nil {
|
||||
log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err.Error()})
|
||||
return err
|
||||
}
|
||||
|
||||
if err := model.UpdateModelLogs(this.modelSociatyTask.TableName,
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user