diff --git a/backend/app/http/posts.go b/backend/app/http/posts.go index 17e4fe6..44bffbd 100644 --- a/backend/app/http/posts.go +++ b/backend/app/http/posts.go @@ -267,6 +267,15 @@ func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *Li // @Bind id path // @Bind user local func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPIPayParams, error) { + bought, err := models.Users.HasBought(ctx.Context(), user.ID, id) + if err != nil { + return nil, errors.New("查询购买失败") + } + + if bought { + return nil, errors.New("已经购买过了") + } + post, err := models.Posts.GetByID(ctx.Context(), id) if err != nil { return nil, errors.Wrapf(err, " failed to get post: %d", id)