third-platform-sdk/platform/shoutu-show/api.go
2024-11-21 16:11:10 +08:00

85 lines
2.6 KiB
Go
Raw 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 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)
// GenerateWechatUrl 生成微信小程序链接
GenerateWechatUrl(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,
}
}
// 守兔演出不支持H5取链生成的H5url为小程序中间页URL
func (a *ShouTuShowApiImpl) GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) {
if req.ActivityUrl == "" || req.Sid == "" {
return nil, errors.New("请求参数activityUrl或sid不能为空")
}
activityUrl := fmt.Sprintf("%s?linkCode=%s&actId=%s", req.ActivityUrl, req.LinkCode, req.ActId)
return &GenerateLinkResponse{
H5: activityUrl,
}, nil
}
// 小程序链接
func (a *ShouTuShowApiImpl) GenerateWechatUrl(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) {
if req.ActivityUrl == "" || req.Sid == "" {
return nil, errors.New("请求参数activityUrl或sid不能为空")
}
//直接替换
newUrl := strings.ReplaceAll(req.ActivityUrl, "subChannelId=", fmt.Sprintf("subChannelId=%s", req.Sid))
return &GenerateLinkResponse{
MiniProgramUrl: 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
}