xiaoetech/service/user.go
2026-07-30 18:11:06 +08:00

273 lines
11 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"encoding/json"
"net/http"
)
type BaseUserInfo struct {
UserId *string `json:"userId,omitempty"` // 头像
Avatar *string `json:"avatar,omitempty"` // 头像
NickName *string `json:"nickname,omitempty"` // 昵称
Country *string `json:"country,omitempty"` // 国家
Province *string `json:"province,omitempty"` // 省份
City *string `json:"city,omitempty"` // 城市
Gender *int `json:"gender,omitempty"` // 性别 0-无 1-男 2-女
WxName *string `json:"wx_name,omitempty"` // 真实姓名
Name *string `json:"name,omitempty"` // 真实姓名
Company *string `json:"company,omitempty"` // 公司
Industry *string `json:"industry,omitempty"` // 行业
Job *string `json:"job,omitempty"` // 工作
WxEmail *string `json:"wx_email,omitempty"` // 邮箱
Birth *string `json:"birth,omitempty"` // 生日
Address *string `json:"address,omitempty"` // 地址
}
type RegisterUserRequestData struct {
WxUnionId *string `json:"wx_union_id,omitempty"`
Phone *string `json:"phone,omitempty"`
SdkUserId *string `json:"sdk_user_id,omitempty"`
SdkAppId *string `json:"sdk_app_id,omitempty"`
BaseUserInfo
}
type RegisterUserRequest struct {
Data RegisterUserRequestData `json:"data"`
}
type RegisterUserResponseData struct {
UserId string `json:"user_id"`
UserExists int `json:"user_exists"`
}
type RegisterUserResponse struct {
BaseResponse
Data RegisterUserResponseData `json:"data"`
}
type UpdateData struct {
BaseUserInfo
}
type UpdateUserRequestData struct {
UpdateData UpdateData `json:"update_data"`
}
type UpdateUserRequest struct {
UserId string `json:"user_id"`
Data UpdateUserRequestData `json:"data"`
}
type UpdateUserResponse struct {
BaseResponse
Data interface{} `json:"data"`
}
type FieldList struct {
WxUnionId *string `json:"wx_union_id,omitempty"` // 商家自有服务号绑定开放平台union_id
WxOpenId *string `json:"wx_open_id,omitempty"` // 商家自有服务号open_id
WxAppOpenId *string `json:"wx_app_open_id,omitempty"` // 商家授权小程序 open_id
WxEmail *string `json:"wx_email,omitempty"` // 微信邮箱
Nickname *string `json:"nickname,omitempty"` // 昵称
Name *string `json:"name,omitempty"` // 真实姓名
Avatar *string `json:"avatar,omitempty"` // 压缩后的头像
Gender *int `json:"gender,omitempty"` // 性别 0-无 1-男 2-女
City *string `json:"city,omitempty"` // 城市
Province *string `json:"province,omitempty"` // 省份
Country *string `json:"country,omitempty"` // 国家
Phone *string `json:"phone,omitempty"` // 手机号码
Birth *string `json:"birth,omitempty"` // 生日 1996-09-09
Address *string `json:"address,omitempty"` // 地址
Company *string `json:"company,omitempty"` // 公司
IsSeal *string `json:"is_seal,omitempty"` // 用户状态:-1-已注销0-正常1-已封号,-2-待注销3-待激活
Job *string `json:"job,omitempty"` // 职位
WxAccount *string `json:"wx_account,omitempty"` // 微信号
PhoneCollect *string `json:"phone_collect,omitempty"` // 信息采集手机号
SdkUserId *string `json:"sdk_user_id,omitempty"` // sdk用户id
CreatedAt *string `json:"created_at,omitempty"` // 创建时间
}
type UserInfoQueryData struct {
WxUnionId *string `json:"wx_union_id,omitempty"` // 微信 union_id
Phone *string `json:"phone,omitempty"` // 手机号码
WxOpenId *string `json:"wx_open_id,omitempty"` // 微信 open_id顶层
FieldList []string `json:"field_list"` // 必选,查询字段集合
}
type GetUserInfoRequest struct {
UserId *string `json:"user_id,omitempty"` // 用户id
Data UserInfoQueryData `json:"data"`
}
type GetUserInfoResponseData struct {
AppId string `json:"app_id"` // 店铺id
SdkUserId string `json:"sdk_user_id"` // sdk用户id
CreatedAt string `json:"created_at"` // 用户创建时间
UserId string `json:"user_id"` // 用户id
WxUnionId string `json:"wx_union_id"` // 微信 union_id
WxEmail string `json:"wx_email"` // 微信邮箱
Name string `json:"name"` // 真实姓名
Nickname string `json:"nickname"` // 昵称
Avatar string `json:"avatar"` // 压缩后的头像
WxAvatar string `json:"wx_avatar"` // 微信原始头像
Gender int `json:"gender"` // 性别 0-无 1-男 2-女
City string `json:"city"` // 城市
Province string `json:"province"` // 省份
Country string `json:"country"` // 国家
Age int `json:"age"` // 年龄
Birth string `json:"birth"` // 生日
Phone string `json:"phone"` // 电话若为空且phone_collect不为空则返回phone_collect
Address string `json:"address"` // 地址
Job string `json:"job"` // 工作
Company string `json:"company"` // 公司
Industry string `json:"industry"` // 行业
Tags string `json:"tags"` // 兴趣标签
WxAccount string `json:"wx_account"` // 用户微信号
PhoneCollect string `json:"phone_collect"` // 信息采集手机号
PhoneResource string `json:"phone_resource"` // phone来源标识 phone-来源手机号 collect-来源信息采集
}
type GetUserInfoResponse struct {
BaseResponse
Data GetUserInfoResponseData `json:"data"`
}
// 用户注册
func (client *Client) RegisterUser(req *RegisterUserRequest) (*RegisterUserResponse, error) {
paramsMap, err := ToMap(req)
if err != nil {
return nil, err
}
respByte, err := client.CurlDo(http.MethodPost, RegisterUserUrl, paramsMap)
if err != nil {
return nil, err
}
var resp = RegisterUserResponse{}
err = json.Unmarshal(respByte, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// 修改用户信息
func (client *Client) UpdateUserInfo(req *UpdateUserRequest) (*UpdateUserResponse, error) {
paramsMap, err := ToMap(req)
if err != nil {
return nil, err
}
respByte, err := client.CurlDo(http.MethodPost, UpdateUserUrl, paramsMap)
if err != nil {
return nil, err
}
var resp = UpdateUserResponse{}
err = json.Unmarshal(respByte, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// 获取单个用户信息
func (client *Client) GetUserInfo(req *GetUserInfoRequest) (*GetUserInfoResponse, error) {
paramsMap, err := ToMap(req)
if err != nil {
return nil, err
}
respByte, err := client.CurlDo(http.MethodPost, GetUserInfoUrl, paramsMap)
if err != nil {
return nil, err
}
var resp = GetUserInfoResponse{}
err = json.Unmarshal(respByte, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
type GetUserListRequest struct {
PageSize int `json:"page_size,omitempty"` // 必填实际有默认值每页条数最大50
EsSkip *string `json:"es_skip,omitempty"` // 可选上一页最后一条数据的es_skip字段用于翻页
Phone *string `json:"phone,omitempty"` // 可选,手机号(优先级高)
Nickname *string `json:"nickname,omitempty"` // 可选,昵称(优先级中)
Name *string `json:"name,omitempty"` // 可选,姓名(优先级低)
TagId *string `json:"tag_id,omitempty"` // 可选用户标签id多个用逗号隔开
From *string `json:"from,omitempty"` // 可选,用户来源:-1全部、0-微信...
UserType *string `json:"user_type,omitempty"` // 可选用户身份0-全部、1-黑名单、2-超级会员
LastPaytimeStart *string `json:"last_paytime_start,omitempty"` // 可选,支付起始时间 yyyy-MM-dd
LastPaytimeEnd *string `json:"last_paytime_end,omitempty"` // 可选,支付截止时间 yyyy-MM-dd
MinPaySum *string `json:"min_pay_sum,omitempty"` // 可选,支付最小金额
MaxPaySum *string `json:"max_pay_sum,omitempty"` // 可选,支付最大金额
MinPunchCount *string `json:"min_punch_count,omitempty"` // 可选,支付最小次数
MaxPunchCount *string `json:"max_punch_count,omitempty"` // 可选,支付最大次数
UserCreatedStart *string `json:"user_created_start,omitempty"` // 可选,用户创建起始时间 yyyy-mm-dd
UserCreatedEnd *string `json:"user_created_end,omitempty"` // 可选,用户创建截止时间 yyyy-mm-dd
LatestVisitedStart *string `json:"latest_visited_start,omitempty"` // 可选,最近访问起始时间 yyyy-mm-dd
LatestVisitedEnd *string `json:"latest_visited_end,omitempty"` // 可选,最近访问结束时间 yyyy-mm-dd
NeedColumn []string `json:"need_column,omitempty"` // 可选,需要返回的字段列表
}
// GetUserListData 用户列表数据
type GetUserListData struct {
List []UserItem `json:"list"` // 用户列表
Total int `json:"total"` // 查询结果记录数
EsSkip *EsSkip `json:"es_skip,omitempty"` // 翻页字段,用于下一页请求
}
// UserItem 用户信息
type UserItem struct {
UserId string `json:"user_id"` // 用户id
UserNickname string `json:"user_nickname"` // 用户昵称
BindPhone string `json:"bind_phone"` // 绑定手机号
CollectPhone string `json:"collect_phone"` // 采集手机号
Avatar string `json:"avatar"` // 头像
From string `json:"from"` // 用户来源0-微信1-sdk...
LatestVisitedAt int64 `json:"latest_visited_at"` // 最后一次访问时间毫秒时间戳0表示未访问
PaySum float64 `json:"pay_sum"` // 消费总额(单位:分)
PunchCount int `json:"punch_count"` // 购买次数
WxUnionId string `json:"wx_union_id"` // 微信 union_id
WxAppOpenId string `json:"wx_app_open_id"` // 小程序 open_id
WxOpenId string `json:"wx_open_id"` // 微信 open_id
UserCreatedAt string `json:"user_created_at"` // 用户创建时间
}
// EsSkip 翻页字段
type EsSkip struct {
Id string `json:"id"` // 用户id
UserCreatedAt string `json:"user_created_at"` // 用户创建时间戳
}
type GetUserListResponse struct {
BaseResponse
Data GetUserListData `json:"data"`
}
// 获取用户列表
func (client *Client) GetUserList(req *GetUserListRequest) (*GetUserListResponse, error) {
paramsMap, err := ToMap(req)
if err != nil {
return nil, err
}
respByte, err := client.CurlDo(http.MethodPost, GetUserListUrl, paramsMap)
if err != nil {
return nil, err
}
var resp = GetUserListResponse{}
err = json.Unmarshal(respByte, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}