修改用户信息,用户未登录,登录查询游戏任务功能
This commit is contained in:
@ -22,11 +22,13 @@ type RankingRes struct {
|
||||
type NonLoginTaskListReq struct {
|
||||
g.Meta `path:"/task/getNonLoginTaskList" method:"get" tags:"Task" summary:"(PC)网吧未登录任务列表"`
|
||||
NetBarAccount string `json:"netBarAccount" v:"required#网关账号不能为空" dc:"网关账号"`
|
||||
Page int `json:"page" v:"required#分页索引不能为空" dc:"分页索引"`
|
||||
Size int `json:"size" v:"required#分页大小不能为空" dc:"分页大小"`
|
||||
Gid int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"`
|
||||
Source string `json:"source" v:"required#不能为空" dc:""`
|
||||
BrandId string `json:"brandId" dc:"品牌id(可选)"`
|
||||
//Page int `json:"page" v:"required#分页索引不能为空" dc:"分页索引"`
|
||||
//Size int `json:"size" v:"required#分页大小不能为空" dc:"分页大小"`
|
||||
Gid int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"`
|
||||
Num int `json:"num" v:"required#不能为空" dc:""`
|
||||
Pageidx string `json:"pageidx" dc:"分页索引"`
|
||||
Source string `json:"source" v:"required#不能为空" dc:""`
|
||||
BrandId string `json:"brandId" dc:"品牌id(可选)"`
|
||||
}
|
||||
|
||||
type NonLoginTaskListRes struct {
|
||||
@ -38,11 +40,12 @@ type NonLoginTaskListRes struct {
|
||||
type GetLoginTaskListReq struct {
|
||||
g.Meta `path:"/task/getLoginTaskList" method:"get" tags:"Task" summary:"(PC)网吧未登录任务列表"`
|
||||
NetBarAccount string `json:"netBarAccount" v:"required#网关账号不能为空" dc:"网关账号"`
|
||||
Page int `json:"page" v:"required#分页索引不能为空" dc:"分页索引"`
|
||||
Size int `json:"size" v:"required#分页大小不能为空" dc:"分页大小"`
|
||||
Gid int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"`
|
||||
Source string `json:"source" v:"required#不能为空" dc:""`
|
||||
BrandId string `json:"brandId" dc:"品牌id(可选)"`
|
||||
//Page int `json:"page" v:"required#分页索引不能为空" dc:"分页索引"`
|
||||
//Size int `json:"size" v:"required#分页大小不能为空" dc:"分页大小"`
|
||||
Num int `json:"num" v:"required#不能为空" dc:""`
|
||||
Pageidx string `json:"pageidx" dc:"分页索引"`
|
||||
Gid int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"`
|
||||
BrandId string `json:"brandId" dc:"品牌id(可选)"`
|
||||
}
|
||||
|
||||
type GetLoginTaskListRes struct {
|
||||
|
||||
@ -14,7 +14,7 @@ type ListRes struct {
|
||||
|
||||
type InfoReq struct {
|
||||
g.Meta `path:"/user/info" method:"get" tags:"User" summary:"(PC)获取用户信息"`
|
||||
OpenId string `json:"openId" v:"required#OpenId不能为空" dc:"OpenId"`
|
||||
//OpenId string `json:"openId" v:"required#OpenId不能为空" dc:"OpenId"`
|
||||
}
|
||||
|
||||
type InfoRes struct {
|
||||
|
||||
@ -11,10 +11,9 @@ import (
|
||||
func (c *ControllerV1) GetLoginTaskList(ctx context.Context, req *v1.GetLoginTaskListReq) (res *v1.GetLoginTaskListRes, err error) {
|
||||
out, err := service.Task().GetLoginTaskList(ctx, &model.GetLoginTaskListIn{
|
||||
NetBarAccount: req.NetBarAccount,
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Num: req.Num,
|
||||
Pageidx: req.Pageidx,
|
||||
Gid: req.Gid,
|
||||
Source: req.Source,
|
||||
BrandId: req.BrandId,
|
||||
})
|
||||
|
||||
|
||||
@ -12,11 +12,13 @@ func (c *ControllerV1) NonLoginTaskList(ctx context.Context, req *v1.NonLoginTas
|
||||
|
||||
out, err := service.Task().GetNonLoginTaskList(ctx, &model.GetNonLoginTaskListIn{
|
||||
NetBarAccount: req.NetBarAccount,
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Gid: req.Gid,
|
||||
Source: req.Source,
|
||||
BrandId: req.BrandId,
|
||||
//Page: req.Page,
|
||||
//Size: req.Size,
|
||||
Num: req.Num,
|
||||
Pageidx: req.Pageidx,
|
||||
Gid: req.Gid,
|
||||
Source: req.Source,
|
||||
BrandId: req.BrandId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@ -13,8 +13,8 @@ func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoR
|
||||
|
||||
id := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.User().Info(ctx, &model.UserInfoIn{
|
||||
OpenId: req.OpenId,
|
||||
Id: int(id),
|
||||
//OpenId: req.OpenId,
|
||||
Id: int(id),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -141,7 +141,7 @@ func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetNonLoginTa
|
||||
// 调用外部接口
|
||||
data, err := tencent.GetNonLoginTaskList(ctx, in)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("调用接口异常")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 任务列表数据处理
|
||||
|
||||
@ -139,7 +139,7 @@ func (s *sUser) WeChatLogin(ctx context.Context, in *model.WeChatLogin) (out *mo
|
||||
}
|
||||
|
||||
func (s *sUser) Info(ctx context.Context, in *model.UserInfoIn) (out *model.UserInfoOut, err error) {
|
||||
exist, err := dao.Users.Ctx(ctx).Where(do.Users{WxOpenId: in.OpenId, Id: in.Id}).OmitEmptyWhere().Exist()
|
||||
exist, err := dao.Users.Ctx(ctx).Where(do.Users{Id: in.Id}).OmitEmptyWhere().Exist()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("查找用户失败")
|
||||
}
|
||||
@ -147,7 +147,7 @@ func (s *sUser) Info(ctx context.Context, in *model.UserInfoIn) (out *model.User
|
||||
return nil, ecode.Params.Sub("用户不存在")
|
||||
}
|
||||
var user entity.Users
|
||||
if err := dao.Users.Ctx(ctx).Where(do.Users{WxOpenId: in.OpenId, Id: in.Id}).OmitEmptyWhere().Scan(&user); err != nil {
|
||||
if err := dao.Users.Ctx(ctx).Where(do.Users{Id: in.Id}).OmitEmptyWhere().Scan(&user); err != nil {
|
||||
return nil, ecode.Fail.Sub("查找用户失败")
|
||||
}
|
||||
out = &model.UserInfoOut{
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
package model
|
||||
|
||||
type GetNonLoginTaskListIn struct {
|
||||
NetBarAccount string `json:"netBarAccount"` //网关账号
|
||||
Page int `json:"page"` // 分页索引
|
||||
Size int `json:"size"` // 分页大小
|
||||
Gid int `json:"gid"` // 游戏唯一id
|
||||
Source string `json:"source"` // 不能为空
|
||||
BrandId string `json:"brandId"` // 品牌id(可选)
|
||||
NetBarAccount string `json:"netbar_account"` //网关账号
|
||||
//Page int `json:"page"` // 分页索引
|
||||
//Size int `json:"size"` // 分页大小
|
||||
Pageidx string `json:"pageidx"` // 分页索引
|
||||
Num int `json:"num"` //
|
||||
Gid int `json:"gid"` // 游戏唯一id
|
||||
Source string `json:"source"` // 不能为空
|
||||
BrandId string `json:"brand_id"` // 品牌id(可选)
|
||||
}
|
||||
|
||||
type GetNonLoginTaskListOut struct {
|
||||
@ -17,11 +19,13 @@ type GetNonLoginTaskListOut struct {
|
||||
|
||||
type GetLoginTaskListIn struct {
|
||||
NetBarAccount string `json:"netBarAccount"` //网关账号
|
||||
Page int `json:"page"` // 分页索引
|
||||
Size int `json:"size"` // 分页大小
|
||||
Gid int `json:"gid"` // 游戏唯一id
|
||||
Source string `json:"source"` // 不能为空
|
||||
BrandId string `json:"brandId"` // 品牌id(可选)
|
||||
//Page int `json:"page"` // 分页索引
|
||||
//Size int `json:"size"` // 分页大小
|
||||
Pageidx string `json:"pageidx"` // 分页索引
|
||||
Num int `json:"num"` //
|
||||
Gid int `json:"gid"` // 游戏唯一id
|
||||
Source string `json:"source"` // 不能为空
|
||||
BrandId string `json:"brandId"` // 品牌id(可选)
|
||||
}
|
||||
|
||||
type GetLoginTaskListOut struct {
|
||||
|
||||
@ -69,8 +69,8 @@ type UserLoginOut struct {
|
||||
}
|
||||
|
||||
type UserInfoIn struct {
|
||||
Id int
|
||||
OpenId string
|
||||
Id int
|
||||
//OpenId string
|
||||
}
|
||||
type UserInfoOut struct {
|
||||
Id int64
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
"io"
|
||||
"net/http"
|
||||
"server/internal/consts"
|
||||
@ -15,61 +15,111 @@ import (
|
||||
// GetNonLoginTaskList 获取下发到指定网吧的任务列表(未登录)
|
||||
func GetNonLoginTaskList(ctx context.Context, in *model.GetNonLoginTaskListIn) (data interface{}, err error) {
|
||||
|
||||
client := &http.Client{}
|
||||
//client := &http.Client{}
|
||||
//// 请求参数
|
||||
//jsonStr, err := json.Marshal(in)
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("参数序列化失败")
|
||||
//}
|
||||
//
|
||||
//req, err := http.NewRequest("POST", consts.TestAddr+"GetNonloginTaskList", bytes.NewBuffer(jsonStr))
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("创建请求失败")
|
||||
//}
|
||||
//req.Header.Set("Content-Type", "application/json")
|
||||
//
|
||||
//resp, err := client.Do(req)
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("请求失败")
|
||||
//}
|
||||
//defer resp.Body.Close()
|
||||
//
|
||||
//body, err := io.ReadAll(resp.Body) // 推荐用法
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("读取响应失败")
|
||||
//}
|
||||
//err = json.Unmarshal(body, &data)
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("解析响应失败")
|
||||
//}
|
||||
//return data, err
|
||||
|
||||
// 请求参数
|
||||
jsonStr, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("参数序列化失败")
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", consts.TestAddr+"GetNonloginTaskList", bytes.NewBuffer(jsonStr))
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("创建请求失败")
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
//req.Header.Set("Authorization", "Bearer 你的Token")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
resp, err := ctxhttp.Post(ctx, http.DefaultClient, consts.TestAddr+"GetNonloginTaskList", "application/json", bytes.NewBuffer(jsonStr))
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("请求失败")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body) // 推荐用法
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("读取响应失败")
|
||||
}
|
||||
fmt.Println("响应内容:", string(body))
|
||||
return nil, err
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("解析响应失败")
|
||||
}
|
||||
return data, err
|
||||
|
||||
}
|
||||
|
||||
// GetLoginTaskList 获取下发到指定网吧的任务列表(已登录)
|
||||
func GetLoginTaskList(ctx context.Context, in *model.GetLoginTaskListIn) (data interface{}, err error) {
|
||||
|
||||
client := &http.Client{}
|
||||
//client := &http.Client{}
|
||||
//// 请求参数
|
||||
//jsonStr, err := json.Marshal(in)
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("参数序列化失败")
|
||||
//}
|
||||
//
|
||||
//req, err := http.NewRequest("POST", consts.TestAddr+"GetTaskList", bytes.NewBuffer(jsonStr))
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("创建请求失败")
|
||||
//}
|
||||
//req.Header.Set("Content-Type", "application/json")
|
||||
////req.Header.Set("Authorization", "Bearer 你的Token")
|
||||
//
|
||||
//resp, err := client.Do(req)
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("请求失败")
|
||||
//}
|
||||
//defer resp.Body.Close()
|
||||
//
|
||||
//body, err := io.ReadAll(resp.Body) // 推荐用法
|
||||
//if err != nil {
|
||||
// return nil, ecode.Fail.Sub("读取响应失败")
|
||||
//}
|
||||
//fmt.Println("响应内容:", string(body))
|
||||
//return nil, err
|
||||
|
||||
// 请求参数
|
||||
jsonStr, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("参数序列化失败")
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", consts.TestAddr+"GetTaskList", bytes.NewBuffer(jsonStr))
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("创建请求失败")
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
//req.Header.Set("Authorization", "Bearer 你的Token")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
resp, err := ctxhttp.Post(ctx, http.DefaultClient, consts.TestAddr+"GetTaskList", "application/json", bytes.NewBuffer(jsonStr))
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("请求失败")
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body) // 推荐用法
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("读取响应失败")
|
||||
return nil, ecode.Fail.Sub("解析响应体失败")
|
||||
}
|
||||
fmt.Println("响应内容:", string(body))
|
||||
return nil, err
|
||||
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("反序列化异常")
|
||||
}
|
||||
|
||||
return data, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user