feat: update refund issues
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"quyun/providers/wepay"
|
"quyun/providers/wepay"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OrderListQuery struct {
|
type OrderListQuery struct {
|
||||||
@@ -45,7 +46,24 @@ func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
refundTotal := order.Price * int64(order.Discount) / 100
|
if order.PaymentMethod == "balance" {
|
||||||
|
if err := models.Users.AddBalance(ctx.Context(), order.UserID, order.Meta.Data.CostBalance); err != nil {
|
||||||
|
return errors.Wrap(err, "add balance failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := models.Users.RevokePosts(ctx.Context(), order.UserID, order.PostID); err != nil {
|
||||||
|
return errors.Wrap(err, "revoke posts failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
order.Status = fields.OrderStatusRefundSuccess
|
||||||
|
if err := models.Orders.Update(ctx.Context(), order); err != nil {
|
||||||
|
return errors.Wrap(err, "update order failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
refundTotal := order.Price*int64(order.Discount)/100 - order.Meta.Data.CostBalance
|
||||||
resp, err := ctl.wepay.Refund(ctx.Context(), func(bm *wepay.BodyMap) {
|
resp, err := ctl.wepay.Refund(ctx.Context(), func(bm *wepay.BodyMap) {
|
||||||
bm.
|
bm.
|
||||||
OutRefundNo(order.OrderNo).
|
OutRefundNo(order.OrderNo).
|
||||||
|
|||||||
@@ -492,3 +492,21 @@ func (m *usersModel) SetBalance(ctx context.Context, id int64, balance int64) er
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddBalance adds the given amount to the user's balance
|
||||||
|
func (m *usersModel) AddBalance(ctx context.Context, id int64, amount int64) error {
|
||||||
|
tbl := table.Users
|
||||||
|
stmt := tbl.
|
||||||
|
UPDATE(tbl.Balance).
|
||||||
|
SET(tbl.Balance.ADD(Int64(amount))).
|
||||||
|
WHERE(
|
||||||
|
tbl.ID.EQ(Int64(id)),
|
||||||
|
)
|
||||||
|
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||||
|
|
||||||
|
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||||
|
m.log.Errorf("error updating user balance: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user