81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
package arena
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) DanReceiveCheck(session comm.IUserSession, req *pb.ArenaDanReceiveReq) (errdata *pb.ErrorData) {
|
|
if req.Dan == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) DanReceive(session comm.IUserSession, req *pb.ArenaDanReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameArenaActiveRewardData
|
|
info *pb.DBArenaUser
|
|
err error
|
|
atno []*pb.UserAtno
|
|
)
|
|
if errdata = this.DanReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil && err != mgo.MongodbNil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_CacheReadError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info.Danaward[req.Dan] == 1 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("%d received", req.Dan),
|
|
}
|
|
return
|
|
}
|
|
info.Danaward[req.Dan] = 1
|
|
if conf, err = this.module.configure.getActiveRewardById(req.Dan); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.ExReward, true); errdata != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if err = this.module.modelArena.Change(session.GetUserId(), map[string]interface{}{
|
|
"danaward": info.Danaward,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "danreceive", &pb.ArenaDanReceiveResp{Dan: req.Dan, Award: atno})
|
|
return
|
|
}
|