95 lines
2.5 KiB
Go
95 lines
2.5 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) BoxRewardCheck(session comm.IUserSession, req *pb.EntertainBoxRewardReq) (errdata *pb.ErrorData) {
|
|
if req.Index < 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 赛季奖励
|
|
func (this *apiComp) BoxReward(session comm.IUserSession, req *pb.EntertainBoxRewardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
list *pb.DBXXLData
|
|
err error
|
|
atno []*pb.UserAtno
|
|
boxid int32
|
|
)
|
|
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
|
|
}
|
|
if len(list.Box) <= int(req.Index) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
// 校验时间
|
|
if configure.Now().Unix() >= list.Box[req.Index].Opentime {
|
|
boxid = list.Box[req.Index].Boxid
|
|
list.Box = append(list.Box[:req.Index], list.Box[req.Index+1:]...)
|
|
this.module.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{
|
|
"box": list.Box,
|
|
})
|
|
// 发奖
|
|
if conf, err := this.module.configure.GetGameConsumeBoxConf(boxid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
user, err := this.module.GetUserForSession(session)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
reward := this.module.ModuleTools.GetGroupDataByLottery(conf.Group, user.Vip, user.Lv)
|
|
if len(reward) > 0 {
|
|
if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
} else { // 时间没到不能开启
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_EntertainBoxEndTime,
|
|
Title: pb.ErrorCode_EntertainBoxEndTime.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "boxreward", &pb.EntertainBoxRewardResp{
|
|
Box: list.Box,
|
|
Reward: atno,
|
|
})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "EntertainBoxRewardReq", atno)
|
|
})
|
|
return
|
|
}
|