95 lines
2.3 KiB
Go
95 lines
2.3 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
|
|
}
|
|
// TODO 等策划配置来再做数据校验
|
|
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.Condition]; !ok {
|
|
res = append(res, v.Reward...)
|
|
list.Reward[v.Condition] = 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.Condition]; !ok {
|
|
res = append(res, v.Reward...)
|
|
list.Gotarr[v.Condition] = 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,
|
|
})
|
|
return
|
|
}
|