76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 活跃度领取
|
|
func (this *apiComp) ActivityreceiveCheck(session comm.IUserSession, req *pb.SociatyActivityReceiveReq) (code pb.ErrorCode) {
|
|
if req.Id == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Activityreceive(session comm.IUserSession, req *pb.SociatyActivityReceiveReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.ActivityreceiveCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
sociaty := this.module.modelSociaty.getUserSociaty(uid)
|
|
if sociaty.Id == "" {
|
|
code = pb.ErrorCode_SociatyNoFound
|
|
this.module.Errorf("uid:%s not in sociaty", 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
|
|
}
|
|
}
|
|
|
|
ggt, err := this.module.configure.getSociatyActivityCfg()
|
|
if err != nil || ggt == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
conf, ok := ggt.GetDataMap()[req.Id]
|
|
if !ok {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
//是否满足领取条件
|
|
if sociaty.Activity < conf.Activity {
|
|
code = pb.ErrorCode_SociatyActivityNoEnough
|
|
this.module.Errorf("活跃度不足 sociatyId:%s uid:%s activity:%d", sociaty.Id, uid, sociaty.Activity)
|
|
return
|
|
}
|
|
|
|
// 活跃度领取
|
|
if err := this.module.modelSociatyTask.activityReceive(req.Id, sociaty.Id, uid); err != nil {
|
|
this.module.Errorf("活跃度领取失败:%v", err)
|
|
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
|
|
}
|