go_dreamfactory/modules/friend/api_cross_getreward.go
2023-12-19 11:21:41 +08:00

72 lines
1.9 KiB
Go

package friend
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
)
// 领取奖励
func (this *apiComp) GetrewardCheck(session comm.IUserSession, req *pb.FriendGetrewardReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) Getreward(session comm.IUserSession, req *pb.FriendGetrewardReq) (errdata *pb.ErrorData) {
var (
atno []*pb.UserAtno
)
uid := session.GetUserId()
//获取玩家自己好友数据
self, err := this.module.modelFriend.GetFriend(uid)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_FriendSelfNoData,
Title: pb.ErrorCode_FriendSelfNoData.ToString(),
}
return
}
if self.Received != 1 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_FriendNoreceived,
Title: pb.ErrorCode_FriendNoreceived.ToString(),
}
return
}
self.Received = 2 //已领
update := map[string]interface{}{
"received": self.Received,
}
if err := this.module.modelFriend.Change(self.Uid, update); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_FriendApplyError,
Title: pb.ErrorCode_FriendApplyError.ToString(),
}
this.module.Error("领奖",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "err", Value: err.Error()},
)
return
}
globalConf := this.module.ModuleTools.GetGlobalConf()
if errdata, atno = this.module.DispenseAtno(session, globalConf.FriendPeize, true); errdata != nil {
this.module.Error("好友领奖励",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "reward", Value: globalConf.FriendPeize},
)
return
}
session.SendMsg(string(this.module.GetType()), "getreward", &pb.FriendGetrewardResp{
Received: int32(self.Received),
Atno: atno,
})
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "FriendGetrewardReq", atno)
})
return
}