go_dreamfactory/modules/friend/api_cross_getreward.go

68 lines
1.8 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) {
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
}
received := 2 //已领
update := map[string]interface{}{
"received": 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 = this.module.DispenseRes(session, globalConf.FriendPeize, true); errdata != nil {
this.module.Error("好友领奖励",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "reward", Value: globalConf.FriendPeize},
)
return
}
rsp := &pb.FriendGetrewardResp{Received: int32(received)}
session.SendMsg(string(this.module.GetType()), "getreward", rsp)
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "FriendGetrewardReq", globalConf.FriendPeize)
})
return
}