73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) RewardCheck(session comm.IUserSession, req *pb.EntertainRewardReq) (errdata *pb.ErrorData) {
|
|
if req.Key == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 赛季奖励
|
|
func (this *apiComp) Reward(session comm.IUserSession, req *pb.EntertainRewardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
list *pb.DBXXLData
|
|
err error
|
|
atno []*pb.UserAtno
|
|
)
|
|
list, err = this.module.model.getEntertainmList(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
user, err := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
if err == nil {
|
|
if conf, err := this.module.configure.GetGameConsumeintegralReward(req.Key); err == nil {
|
|
if user.Consumeexp < conf.Key {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_UserRepeadReward,
|
|
Title: pb.ErrorCode_UserRepeadReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if _, ok := list.Reward[conf.Key]; !ok {
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Rewards, true); errdata != nil {
|
|
return
|
|
}
|
|
list.Reward[conf.Key] = 1
|
|
this.module.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{
|
|
"reward": list.Reward,
|
|
})
|
|
} else { // 重复领取
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_UserRepeadReward,
|
|
Title: pb.ErrorCode_UserRepeadReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "reward", &pb.EntertainRewardResp{
|
|
Data: list,
|
|
Reward: atno,
|
|
})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(),0, "EntertainRewardReq", atno)
|
|
})
|
|
return
|
|
}
|