feat: 添加作品购买人列表功能
Some checks failed
build quyun / Build (push) Failing after 1m26s

This commit is contained in:
2025-12-20 23:09:01 +08:00
parent e2be734b82
commit 65d40fa631
8 changed files with 223 additions and 7 deletions

View File

@@ -195,6 +195,21 @@ func (ctl *posts) Show(ctx fiber.Ctx, post *models.Post) (*PostItem, error) {
}, nil
}
// Buyers
//
// @Summary 作品购买人列表
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Param pagination query requests.Pagination false "分页参数"
// @Success 200 {object} requests.Pager{items=dto.PostBuyerItem} "成功"
// @Router /admin/v1/posts/:id/buyers [get]
// @Bind post path key(id) model(id)
// @Bind pagination query
func (ctl *posts) Buyers(ctx fiber.Ctx, post *models.Post, pagination *requests.Pagination) (*requests.Pager, error) {
return services.Posts.Buyers(ctx, post.ID, pagination)
}
// SendTo
//
// @Summary 赠送作品给用户

View File

@@ -114,6 +114,15 @@ func (r *Routes) Register(router fiber.Router) {
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
},
))
r.log.Debugf("Registering route: Get /admin/v1/posts/:id/buyers -> posts.Buyers")
router.Get("/admin/v1/posts/:id/buyers"[len(r.Path()):], DataFunc2(
r.posts.Buyers,
func(ctx fiber.Ctx) (*models.Post, error) {
v := fiber.Params[int](ctx, "id")
return models.PostQuery.WithContext(ctx).Where(field.NewUnsafeFieldRaw("id = ?", v)).First()
},
Query[requests.Pagination]("pagination"),
))
r.log.Debugf("Registering route: Post /admin/v1/posts -> posts.Create")
router.Post("/admin/v1/posts"[len(r.Path()):], Func1(
r.posts.Create,

View File

@@ -0,0 +1,17 @@
package dto
import "time"
type PostBuyerItem struct {
UserID int64 `json:"user_id"` // 用户 ID购买人唯一标识用于管理端关联用户详情/后续操作)
Username string `json:"username"` // 用户名(购买人展示名称;可能为空或默认值,前端需兼容)
Avatar string `json:"avatar"` // 用户头像 URL用于列表展示可能为空前端需提供占位图/降级展示)
Phone string `json:"phone"` // 用户手机号(管理端可见;用于客服联系/核对身份,可能为空)
BoughtAt time.Time `json:"bought_at"` // 购买时间(以 user_posts.created_at 为准;用于排序/审计)
Price int64 `json:"price"` // 购买价格(单位:分;-1 表示管理员赠送/免费,非负为实际支付金额)
}