feat: support refund

This commit is contained in:
Rogee
2025-05-06 21:16:23 +08:00
parent 533c9b70af
commit 811ed3a41f
6 changed files with 101 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ package http
import (
_ "embed"
"fmt"
"strconv"
"time"
@@ -272,13 +273,22 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
return nil, errors.Wrap(err, "订单创建失败")
}
payPrice := post.Price * int64(post.Discount) / 100
prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), func(bm *wepay.BodyMap) {
bm.
Expire(30 * time.Minute).
Description(post.Title).
OutTradeNo(order.OrderNo).
Payer(user.OpenID).
CNYAmount(post.Price * int64(post.Discount) / 100)
CNYAmount(payPrice).
Detail([]wepay.GoodsInfo{
{
GoodsName: post.Title,
UnitPrice: payPrice,
MerchantGoodsID: fmt.Sprintf("%d", post.ID),
Quantity: 1,
},
})
})
if err != nil {
log.Errorf("wepay.V3TransactionJsapi err: %v", err)