feat: update metas

This commit is contained in:
Rogee
2025-05-13 09:33:12 +08:00
parent ec8a1558b8
commit 7128dab38c
5 changed files with 62 additions and 14 deletions

View File

@@ -271,15 +271,20 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
if err != nil {
return nil, errors.Wrapf(err, " failed to get post: %d", id)
}
payPrice := post.Price * int64(post.Discount) / 100
// create order
order, err := models.Orders.Create(ctx.Context(), user.ID, post.ID)
if err != nil {
return nil, errors.Wrap(err, "订单创建失败")
}
payPrice := post.Price * int64(post.Discount) / 100
if user.Balance >= payPrice {
if err := models.Orders.SetMeta(ctx.Context(), order.ID, func(om fields.OrderMeta) fields.OrderMeta {
om.CostBalance = payPrice
return om
}); err != nil {
return nil, errors.Wrap(err, "订单创建失败")
}
if err := ctl.job.Add(&jobs.BalancePayNotify{OrderNo: order.OrderNo}); err != nil {
log.Errorf("add job error:%v", err)
@@ -289,14 +294,15 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
return &wechat.JSAPIPayParams{
AppId: "balance",
}, nil
} else {
payPrice = payPrice - user.Balance
err = models.Users.SetBalance(ctx.Context(), user.ID, 0)
if err != nil {
return nil, errors.Wrap(err, "余额支付失败")
}
}
payPrice = payPrice - user.Balance
if err := models.Orders.SetMeta(ctx.Context(), order.ID, func(om fields.OrderMeta) fields.OrderMeta {
om.CostBalance = user.Balance
return om
}); err != nil {
return nil, errors.Wrap(err, "订单创建失败")
}
prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), func(bm *wepay.BodyMap) {
bm.
Expire(30 * time.Minute).