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