feat: support refund
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"quyun/app/models"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/fields"
|
||||
@@ -30,7 +32,7 @@ func (ctl *orders) List(ctx fiber.Ctx, pagination *requests.Pagination, query *O
|
||||
}
|
||||
|
||||
// Refund
|
||||
// @Router /admin/orders/{id}/refund [post]
|
||||
// @Router /admin/orders/:id/refund [post]
|
||||
// @Bind id path
|
||||
func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
||||
order, err := models.Orders.GetByID(ctx.Context(), id)
|
||||
@@ -51,7 +53,15 @@ func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
||||
TransactionID(order.TransactionID).
|
||||
CNYRefundAmount(refundTotal, refundTotal).
|
||||
RefundReason("管理员退款").
|
||||
RefundGoodsInfo(post.Title)
|
||||
RefundGoods([]wepay.RefundGoodsInfo{
|
||||
{
|
||||
MerchantGoodsID: fmt.Sprintf("%d", order.PostID),
|
||||
GoodsName: post.Title,
|
||||
RefundQuantity: 1,
|
||||
RefundAmount: refundTotal,
|
||||
UnitPrice: order.Price,
|
||||
},
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -63,6 +63,11 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
Query[OrderListQuery]("query"),
|
||||
))
|
||||
|
||||
router.Post("/admin/orders/:id/refund", Func1(
|
||||
r.orders.Refund,
|
||||
PathParam[int64]("id"),
|
||||
))
|
||||
|
||||
// 注册路由组: posts
|
||||
router.Get("/admin/posts", DataFunc2(
|
||||
r.posts.List,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user