feat: add refund
This commit is contained in:
@@ -3,6 +3,7 @@ package admin
|
||||
import (
|
||||
"quyun/app/models"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/fields"
|
||||
"quyun/providers/wepay"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
@@ -37,5 +38,32 @@ func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.JSON(order)
|
||||
post, err := models.Posts.GetByID(ctx.Context(), order.PostID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
refundTotal := order.Price * int64(order.Discount) / 100
|
||||
resp, err := ctl.wepay.Refund(ctx.Context(), func(bm *wepay.BodyMap) {
|
||||
bm.
|
||||
OutRefundNo(order.OrderNo).
|
||||
OutTradeNo(order.OrderNo).
|
||||
TransactionID(order.TransactionID).
|
||||
CNYRefundAmount(refundTotal, refundTotal).
|
||||
RefundReason("管理员退款").
|
||||
RefundGoodsInfo(post.Title)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
meta := order.Meta.Data
|
||||
meta.RefundResp = resp
|
||||
order.Meta = fields.ToJson(meta)
|
||||
order.RefundTransactionID = resp.RefundId
|
||||
|
||||
if err := models.Orders.Update(ctx.Context(), order); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user