third-platform-sdk/platform/shoutu-show/api.go

71 lines
2.1 KiB
Go
Raw Normal View History

2024-08-07 22:16:49 +08:00
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{
2024-11-21 15:50:04 +08:00
MiniProgramUrl: newUrl,
2024-08-07 22:16:49 +08:00
}, 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
}