go_dreamfactory/modules/task/api_activereceive.go
2023-06-06 11:08:14 +08:00

117 lines
2.8 KiB
Go

package task
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
// 活跃度领取
func (this *apiComp) ActiveReceiveCheck(session comm.IUserSession, req *pb.TaskActiveReceiveReq) (errdata *pb.ErrorData) {
if req.Id == 0 {
code = pb.ErrorCode_TaskIdEmpty
} else if req.TaskTag <= 0 || req.TaskTag > 2 {
code = pb.ErrorCode_TaskTagEmpty
}
return
}
func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActiveReceiveReq) (errdata *pb.ErrorData) {
if errdata = this.ActiveReceiveCheck(session, req); errdata != nil {
return
}
uid := session.GetUserId()
ue, err := this.module.ModuleUser.GetUserExpand(uid)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if ue == nil {
code = pb.ErrorCode_UserExpandNull
return
}
var rewards []*cfg.Gameatn
var flag bool
update := map[string]interface{}{}
// 玩家的
activeList := this.module.modelTaskActive.getActiveList(uid)
// var activityData *pb.ActivityData
for _, v := range activeList {
if v.TaskId == req.Id {
if v.Received != 1 {
conf := this.module.configure.getTaskActiveById(v.TaskId)
if conf == nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if req.TaskTag == int32(comm.TASK_DAILY) {
if ue.Activeday < conf.Active {
code = pb.ErrorCode_TaskActiveNoenough
return
}
} else if req.TaskTag == int32(comm.TASK_WEEKLY) {
if ue.Activeweek < conf.Active {
code = pb.ErrorCode_TaskActiveNoenough
return
}
}
v.Received = 1
flag = true
rewards = append(rewards, conf.Reword...)
}
break
}
}
if flag {
update["activityList"] = activeList
if err := this.module.modelTaskActive.Change(session.GetUserId(), update); err != nil {
this.module.Errorf("updateReceive err %v", err)
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
}
if len(rewards) > 0 {
//派发奖励
if errdata = this.module.DispenseRes(session, rewards, true); errdata != nil {
this.module.Error("活跃度奖励",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "rewards", Value: rewards},
log.Field{Key: "code", Value: code},
)
}
go this.module.ModuleBuried.TriggerBuried(uid, comm.GetBuriedParam(comm.Rtype171, 1))
}
resp := &pb.TaskActiveReceiveResp{
TaskTag: req.TaskTag,
Id: req.Id,
}
err = session.SendMsg(string(this.module.GetType()), TaskSubTypeActiveReceive, resp)
if err != nil {
code = pb.ErrorCode_SystemError
}
return
}