go_dreamfactory/modules/smithy/api_getReward.go
2022-09-02 17:19:06 +08:00

50 lines
1.2 KiB
Go

package smithy
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.SmithyGetRewardReq) (code pb.ErrorCode) {
return
}
///美食城领取奖励
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.SmithyGetRewardReq) (code pb.ErrorCode, data proto.Message) {
code = this.GetRewardCheck(session, req)
_gourmet, err := this.module.modelSmithy.getSmithyList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
if len(_gourmet.Items) > 0 {
res := make([]*cfg.Gameatn, 0)
for _, v := range _gourmet.Items {
res = append(res, &cfg.Gameatn{
A: v.A,
T: v.T,
N: v.N,
})
}
code = this.module.DispenseRes(session, res, true)
if code != pb.ErrorCode_Success {
return
}
// 随机任务
this.module.SendRdTask(session, _gourmet.Items)
_gourmet.Items = nil
mapData := make(map[string]interface{}, 0)
mapData["items"] = nil
code = this.module.ModifySmithyData(session.GetUserId(), mapData)
}
session.SendMsg(string(this.module.GetType()), SmithyGetRewardResp, &pb.SmithyGetRewardResp{Data: _gourmet})
return
}