feat: 修改订单创建逻辑,直接使用Post对象而非PostID
Some checks failed
build quyun / Build (push) Failing after 1m23s

This commit is contained in:
2025-12-20 00:07:56 +08:00
parent 109cd3b52d
commit 06cc059998
2 changed files with 3 additions and 8 deletions

View File

@@ -320,7 +320,7 @@ func (ctl *posts) Buy(ctx fiber.Ctx, post *models.Post, user *models.User) (*wec
}
// payPrice := post.PayPrice()
order, err := services.Orders.CreateFromUserPostID(ctx, user.ID, post.ID)
order, err := services.Orders.CreateFromUserPostID(ctx, user.ID, post)
if err != nil {
return nil, errors.Wrap(err, "订单创建失败")
}

View File

@@ -124,18 +124,13 @@ func (m *orders) GetByOrderNO(ctx context.Context, orderNo string) (*models.Orde
return models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.OrderNo.Eq(orderNo)).First()
}
func (o *orders) CreateFromUserPostID(ctx context.Context, userId, postId int64) (*models.Order, error) {
post, err := Posts.FindByID(ctx, postId)
if err != nil {
return nil, errors.Wrap(err, "failed to get post")
}
func (o *orders) CreateFromUserPostID(ctx context.Context, userId int64, post *models.Post) (*models.Order, error) {
m := &models.Order{}
m.Status = fields.OrderStatusPending
m.OrderNo = time.Now().Format("20060102150405")
m.SubOrderNo = m.OrderNo
m.UserID = userId
m.PostID = postId
m.PostID = post.ID
m.Meta = types.NewJSONType(fields.OrderMeta{})
m.Price = post.Price
m.Discount = post.Discount