88 lines
2.4 KiB
Go
88 lines
2.4 KiB
Go
package venture
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) LvRewardCheck(session comm.IUserSession, req *pb.VentureLvRewardReq) (errdata *pb.ErrorData) {
|
|
if req.Cid == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) LvReward(session comm.IUserSession, req *pb.VentureLvRewardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
conf *cfg.GameVenturegiftsLvawardData
|
|
ventureLv *pb.DBVentureLv
|
|
atno []*pb.UserAtno
|
|
user *pb.DBUser
|
|
)
|
|
if errdata = this.LvRewardCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameVenturegiftsLvReward(req.Cid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if ventureLv, err = this.module.ModelLv.getUserVentureLvData(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
// 等级校验
|
|
if user, err = this.module.ModuleUser.GetUser(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf.Lvcondition > user.Lv { // 等级不够
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ActivityCantReward,
|
|
Title: pb.ErrorCode_ActivityCantReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if _, ok := ventureLv.Reward[req.Cid]; ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ActivityRepatReward,
|
|
Title: pb.ErrorCode_ActivityRepatReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if errdata, atno = this.module.DispenseAtno(session, []*cfg.Gameatn{conf.Reward}, true); errdata != nil {
|
|
return
|
|
}
|
|
ventureLv.Reward[req.Cid] = 1
|
|
this.module.ModelLv.Change(session.GetUserId(), map[string]interface{}{
|
|
"reward": ventureLv.Reward,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "lvreward", &pb.VentureLvRewardResp{
|
|
Data: ventureLv,
|
|
Atno: atno,
|
|
})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "VentureLvRewardReq", atno)
|
|
})
|
|
return
|
|
}
|