go_dreamfactory/modules/sociaty/api_cross_activityreceive.go
2023-04-14 12:21:58 +08:00

78 lines
2.3 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
)
// 活跃度领取
func (this *apiComp) ActivityreceiveCheck(session comm.IUserSession, req *pb.SociatyActivityReceiveReq) (code pb.ErrorCode) {
if req.Id == 0 {
this.module.Error("活跃度领取参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) Activityreceive(session comm.IUserSession, req *pb.SociatyActivityReceiveReq) (code pb.ErrorCode, data *pb.ErrorData) {
if code = this.ActivityreceiveCheck(session, req); code != pb.ErrorCode_Success {
return
}
uid := session.GetUserId()
sociaty := this.module.modelSociaty.getUserSociaty(uid)
if sociaty == nil {
code = pb.ErrorCode_SociatyNoFound
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
return
}
// 判断奖励是否已领
sociatyTask := this.module.modelSociaty.getUserTaskList(uid, sociaty.Id)
for _, v := range sociatyTask.ActivityList {
if v.Id == req.Id {
if v.Status == 1 {
code = pb.ErrorCode_SociatyRewardReceived
return
}
break
}
}
conf, ok := this.module.sociatyActivityConf.GetDataMap()[req.Id]
if !ok {
code = pb.ErrorCode_ConfigNoFound
return
}
//是否满足领取条件
if sociaty.Activity < conf.Activity {
code = pb.ErrorCode_SociatyActivityNoEnough
this.module.Debug("活跃度不足",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "sociatyId", Value: sociaty.Id},
log.Field{Key: "confId", Value: req.Id},
log.Field{Key: "实际活跃度", Value: sociaty.Activity},
log.Field{Key: "期望活跃度", Value: conf.Activity},
)
return
}
// 活跃度领取
if err := this.module.modelSociatyTask.activityReceive(req.Id, sociaty.Id, uid); err != nil {
this.module.Error("活跃度领取", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
code = pb.ErrorCode_DBError
return
}
rsp := &pb.SociatyActivityReceiveResp{
Id: req.Id,
SociatyId: sociaty.Id,
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeActivityReceive, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}