package integral import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.IntegralGetRewardReq) (errdata *pb.ErrorData) { if req.Itype != 1 && req.Itype != 2 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } func (this *apiComp) GetReward(session comm.IUserSession, req *pb.IntegralGetRewardReq) (errdata *pb.ErrorData) { var ( list *pb.DBIntegralBoss err error conf []*cfg.GameIntegralRewardData res []*cfg.Gameatn atno []*pb.UserAtno ) update := make(map[string]interface{}) list, err = this.module.modelIntegral.getIntegralList(session) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), } return } if conf, err = this.module.configure.GetIntegralReward(list.Hid, req.Itype); err != nil { // 配置校验 errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } for _, v := range conf { if req.Itype == 1 { if list.Reward1 < v.Val && list.Maxscore > v.Val { res = append(res, v.Prize...) list.Reward1 = v.Val } } else { if list.Reward2 < v.Val && list.Totalscore > v.Val { res = append(res, v.Prize...) list.Reward2 = v.Val } } } if len(res) > 0 { update["reward1"] = list.Reward1 update["reward2"] = list.Reward2 if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil { return } if err = this.module.modelIntegral.modifyIntegralData(session.GetUserId(), update); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_UserNoReward, Title: pb.ErrorCode_UserNoReward.ToString(), } return } session.SendMsg(string(this.module.GetType()), "getreward", &pb.IntegralGetRewardResp{ Data: list, Award: atno, }) return }