go_dreamfactory/modules/jielong/api_reward.go
2023-11-17 16:11:32 +08:00

98 lines
2.4 KiB
Go

package jielong
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
// 参数校验
func (this *apiComp) RewardCheck(session comm.IUserSession, req *pb.JielongRewardReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) Reward(session comm.IUserSession, req *pb.JielongRewardReq) (errdata *pb.ErrorData) {
var (
list *pb.DBJielongData
err error
update map[string]interface{}
res []*cfg.Gameatn // 奖励
atno []*pb.UserAtno
)
update = make(map[string]interface{}, 0)
if errdata = this.RewardCheck(session, req); errdata != nil {
return
}
list, err = this.module.modelJielong.getUserJielongData(session.GetUserId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if req.Cur {
if c, e := this.module.configure.getGameFastDataByType(1); e != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
}
return
} else {
for _, v := range c {
if list.Weekmax >= v.Condition {
if _, ok := list.Reward[v.Key]; !ok {
res = append(res, v.Reward...)
list.Reward[v.Key] = 1
}
}
}
update["reward"] = list.Reward
}
} else {
if c, e := this.module.configure.getGameFastDataByType(2); e != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
}
return
} else {
for _, v := range c {
if list.Hisotry >= v.Condition {
if _, ok := list.Gotarr[v.Key]; !ok {
res = append(res, v.Reward...)
list.Gotarr[v.Key] = 1
}
}
}
update["gotarr"] = list.Gotarr
}
}
if len(res) > 0 {
errdata, atno = this.module.DispenseAtno(session, res, true)
if errdata != nil {
return
}
} else { // 没有奖励可以领取
errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserRepeadReward,
Title: pb.ErrorCode_UserRepeadReward.ToString(),
}
return
}
this.module.modelJielong.changeJielongData(session.GetUserId(), update)
session.SendMsg(string(this.module.GetType()), "reward", &pb.JielongRewardResp{
Data: list,
Res: atno,
})
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "JielongRewardReq", atno)
})
return
}