2025-12-06 10:38:48 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2025-12-09 16:10:45 +08:00
|
|
|
"cid/model/dto"
|
|
|
|
|
"cid/service"
|
2025-12-06 15:24:30 +08:00
|
|
|
|
2025-12-06 10:38:48 +08:00
|
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-08 16:56:38 +08:00
|
|
|
var CID = new(cid)
|
2025-12-06 10:38:48 +08:00
|
|
|
|
2025-12-06 15:24:30 +08:00
|
|
|
type cid struct{}
|
2025-12-06 10:38:48 +08:00
|
|
|
|
|
|
|
|
// GenerateCID 生成CID广告
|
2025-12-06 15:24:30 +08:00
|
|
|
func (c *cid) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
2025-12-06 10:38:48 +08:00
|
|
|
if req == nil {
|
|
|
|
|
return nil, gerror.New("请求参数不能为空")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if req.RequestType == "" {
|
|
|
|
|
req.RequestType = "default" // 默认请求类型
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := service.CID.GenerateCID(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCIDHistory 获取CID历史记录
|
2025-12-06 15:24:30 +08:00
|
|
|
func (c *cid) GetCIDHistory(ctx context.Context, req *dto.GetCIDHistoryReq) (res *dto.GetCIDHistoryRes, err error) {
|
2025-12-06 10:38:48 +08:00
|
|
|
if req == nil {
|
|
|
|
|
return nil, gerror.New("请求参数不能为空")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询历史记录
|
|
|
|
|
history, err := service.CID.GetCIDHistory(ctx, 1, req.Page, req.Size) // 临时使用固定用户ID
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return history, nil
|
|
|
|
|
}
|