feat: update
This commit is contained in:
@@ -3,7 +3,7 @@ package admin
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"quyun/app/models"
|
||||
"quyun/app/model"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/fields"
|
||||
"quyun/providers/wepay"
|
||||
@@ -28,35 +28,35 @@ type orders struct {
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *orders) List(ctx fiber.Ctx, pagination *requests.Pagination, query *OrderListQuery) (*requests.Pager, error) {
|
||||
cond := models.Orders.BuildConditionWithKey(query.OrderNumber, query.UserID)
|
||||
return models.Orders.List(ctx.Context(), pagination, cond)
|
||||
cond := model.OrdersModel.BuildConditionWithKey(query.OrderNumber, query.UserID)
|
||||
return model.OrdersModel.List(ctx.Context(), pagination, cond)
|
||||
}
|
||||
|
||||
// Refund
|
||||
// @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)
|
||||
order, err := model.OrdersModel.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
post, err := models.Posts.GetByID(ctx.Context(), order.PostID)
|
||||
post, err := model.PostsModel.GetByID(ctx.Context(), order.PostID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if order.PaymentMethod == "balance" {
|
||||
if err := models.Users.AddBalance(ctx.Context(), order.UserID, order.Meta.Data.CostBalance); err != nil {
|
||||
if err := model.UsersModel.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 {
|
||||
if err := model.UsersModel.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 {
|
||||
if err := model.OrdersModel.Update(ctx.Context(), order); err != nil {
|
||||
return errors.Wrap(err, "update order failed")
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
||||
order.RefundTransactionID = resp.RefundId
|
||||
order.Status = fields.OrderStatusRefundProcessing
|
||||
|
||||
if err := models.Orders.Update(ctx.Context(), order); err != nil {
|
||||
if err := model.OrdersModel.Update(ctx.Context(), order); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user