From dcc3d9a8ba038697bf69e3641fb72d2138a3d515 Mon Sep 17 00:00:00 2001 From: yanfan <1406317364@qq.com> Date: Wed, 7 Aug 2024 22:16:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=88=E5=85=94=E6=BC=94=E5=87=BA=E8=AE=A2?= =?UTF-8?q?=E5=8D=95api=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/shoutu-show/api.go | 70 ++++++++++++++++++++++++++++++++++ platform/shoutu-show/client.go | 36 +++++++++++++++++ platform/shoutu-show/consts.go | 15 ++++++++ platform/shoutu-show/types.go | 54 ++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 platform/shoutu-show/api.go create mode 100644 platform/shoutu-show/client.go create mode 100644 platform/shoutu-show/consts.go create mode 100644 platform/shoutu-show/types.go diff --git a/platform/shoutu-show/api.go b/platform/shoutu-show/api.go new file mode 100644 index 0000000..d87a5db --- /dev/null +++ b/platform/shoutu-show/api.go @@ -0,0 +1,70 @@ +package shoutu_show + +import ( + "context" + "errors" + "fmt" + "github.com/zeromicro/go-zero/core/logx" + "github.com/zywaited/xcopy" + "repository.lenntc.com/lenntc/third-platform-sdk/client" + "repository.lenntc.com/lenntc/third-platform-sdk/util" + "strings" +) + +// ShouTuShowApi 守兔演唱会 +type ShouTuShowApi interface { + // GenerateLink 生成推广链接 + GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) +} + +type ShouTuShowApiImpl struct { + log logx.Logger + client *Client +} + +func newShouTuShowApiImpl(log logx.Logger, client *Client) ShouTuShowApi { + return &ShouTuShowApiImpl{ + log: log, + client: client, + } +} + +func (a *ShouTuShowApiImpl) GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) { + if req.ActivityUrl == "" || req.Sid == "" { + return nil, errors.New("请求参数activityUrl或sid不能为空") + } + //测试联调地址 https://pre-show.shouto.cn/?distributorId=8&subChannelId= + //直接替换 + newUrl := strings.ReplaceAll(req.ActivityUrl, "subChannelId=", fmt.Sprintf("subChannelId=%s", req.Sid)) + return &GenerateLinkResponse{ + H5: newUrl, + }, nil +} + +// QueryOrderList 查询订单列表 +func (a *ShouTuShowApiImpl) QueryOrderList(ctx context.Context, req QueryOrderListRequest) ([]*OrderItem, error) { + if req.StartTime <= 0 || req.EndTime <= 0 { + return nil, errors.New("请求参数start_time或end_time为必传") + } + //sTime := time.Unix(req.StartTime, 0) + //eTime := time.Unix(req.EndTime, 0) + pageSize := 50 + + //todo时间筛选 + args := util.StructToMap(map[string]any{ + "pageNum": req.Page, + "pageSize": pageSize, + }) + request := &client.HttpRequest{Headers: a.client.headers, BodyArgs: args} + response := new(QueryOrderListResponse) + if err := a.client.HttpPost(GetOrderListUrl, request, &client.HttpResponse{Result: response}); err != nil { + return nil, err + } + responseData := make([]*OrderItem, 0) + if response.Data != nil && len(response.Data.Records) > 0 { + if err := xcopy.Copy(&responseData, response.Data.Records); err != nil { + return nil, err + } + } + return responseData, nil +} diff --git a/platform/shoutu-show/client.go b/platform/shoutu-show/client.go new file mode 100644 index 0000000..4176ec9 --- /dev/null +++ b/platform/shoutu-show/client.go @@ -0,0 +1,36 @@ +package shoutu_show + +import ( + "github.com/zeromicro/go-zero/core/logx" + "repository.lenntc.com/lenntc/third-platform-sdk/client" +) + +// AuthConfig api鉴权参数 +type AuthConfig struct { + AppKey string // api key + AppSecret string // api key +} + +// Client 连接第三方平台的client +type Client struct { + log logx.Logger + authConfig AuthConfig + client.HttpClient + headers map[string]string +} + +func NewApiClient(log logx.Logger, conf AuthConfig) ShouTuShowApi { + clt := newClient(log, conf) + return newShouTuShowApiImpl(log, clt) +} + +func newClient(log logx.Logger, conf AuthConfig) *Client { + return &Client{ + log: log, + authConfig: conf, + HttpClient: client.NewHttpClient(log), + headers: map[string]string{ + "Content-Type": "application/json", + }, + } +} diff --git a/platform/shoutu-show/consts.go b/platform/shoutu-show/consts.go new file mode 100644 index 0000000..d3f94a9 --- /dev/null +++ b/platform/shoutu-show/consts.go @@ -0,0 +1,15 @@ +package shoutu_show + +// 相关地址 +const ( + SiteDomain = "https://show.shoutoinfo.cn/prod-api" // Domain 后台域名 + SiteUrl = "https://show.shoutoinfo.cn/prod-api" // SiteUrl 后台地址 + DocUrl = "https://apifox.com/apidoc/shared-2c9bfdd9-5307-4d29-b71f-63b93393d607" // DocUrl 文档地址 + ApiDocUrl = "https://apifox.com/apidoc/shared-2c9bfdd9-5307-4d29-b71f-63b93393d607" // ApiDocUrl api文档地址 +) + +// 接口地址 +const ( + ApiDomain = "https://pre-show.shoutoinfo.cn/prod-api" // Domain api域名 + GetOrderListUrl = ApiDomain + "/api/open/channel-order/page" +) diff --git a/platform/shoutu-show/types.go b/platform/shoutu-show/types.go new file mode 100644 index 0000000..852cb6c --- /dev/null +++ b/platform/shoutu-show/types.go @@ -0,0 +1,54 @@ +package shoutu_show + +type GenerateLinkRequest struct { + ActivityUrl string `json:"activityUrl"` // 渠道方合作页地址 + Sid string `json:"sid"` // 必传 自定义参数 +} + +// GenerateLinkResponse 生成推广链接响应 +type GenerateLinkResponse struct { + H5 string `json:"h5"` // H5链接 +} + +type QueryOrderListRequest struct { + StartTime int64 `json:"start_time"` + EndTime int64 `json:"end_time"` + Page int64 `json:"page"` +} +type QueryOrderListResponse struct { + Code string `json:"code"` + Mse string `json:"mse"` + Success bool `json:"success"` + CurrTime int64 `json:"currTime"` + Data *OrderData `json:"data"` +} +type OrderData struct { + PageNum int64 `json:"pageNum"` //当前页码 + PageSize int64 `json:"pageSize"` //每页数量 + Total int64 `json:"total"` //总数 + Records []*OrderItem `json:"records"` +} +type OrderItem struct { + OrderNo string `json:"orderNo"` //订单号 + UserId int64 `json:"userId"` //用户Id + UserNickname string `json:"userNickname"` //用户昵称 + UserHeadPic string `json:"userHeadPic"` //用户头像 + ChannelId int64 `json:"channelId"` //一级分销id + SubChannelId int64 `json:"subChannelId"` //二级分销标识 + OrderSourceType string `json:"orderSourceType"` //订单来源类型【1-h5订单,2-api订单,3-微信小程序订单】 + PerformanceName string `json:"performanceName"` //演出信息 + SessionName string `json:"sessionName"` //场次信息 + TicketFaceName string `json:"ticketFaceName"` //票面信息 + BuyQty int `json:"buyQty"` //张数 + OrderType string `json:"orderType"` //订单类型 + OrderStatusDesc string `json:"orderStatusDesc"` //订单状态描述 + OrderStatus int `json:"orderStatus"` //订单状态值 + PayTime string `json:"payTime"` //订单支付时间 示例:2024-06-28 15:20:33 + PayAmt int `json:"payAmt"` //订单金额 单位:元 + CommissionAmt int `json:"commissionAmt"` //订单预估利润 单位:元 + CommissionRate int `json:"commissionRate"` //渠道分润比例 单位:% + SettleTime string `json:"settleTime"` //渠道分润结算时间 示例:2024-06-28 15:20:33 + SettledCommissionAmt int `json:"settledCommissionAmt"` //已结算分润金额 单位:元 + OrderTime string `json:"orderTime"` //订单创建时间 示例:2024-06-28 15:20:33 + UpdateTime string `json:"updateTime"` //订单更新时间 示例:2024-06-28 15:20:33 +}