bindbox-game/internal/api/user/orders_test_app.go

28 lines
881 B
Go
Executable File

package app
import (
"fmt"
"time"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/repository/mysql/model"
)
type createTestOrderResponse struct {
OrderNo string `json:"order_no"`
}
func (h *handler) CreateTestOrder() core.HandlerFunc {
return func(ctx core.Context) {
userID := int64(ctx.SessionUserInfo().Id)
now := time.Now()
orderNo := fmt.Sprintf("T%s%03d", now.Format("20060102150405"), now.Nanosecond()/1e6)
err := h.writeDB.Orders.WithContext(ctx.RequestContext()).Omit(h.writeDB.Orders.PaidAt, h.writeDB.Orders.CancelledAt).Create(&model.Orders{UserID: userID, OrderNo: orderNo, SourceType: 1, TotalAmount: 10, DiscountAmount: 0, PointsAmount: 0, ActualAmount: 10, Status: 1, IsConsumed: 0})
if err != nil {
ctx.AbortWithError(core.Error(400, 120001, err.Error()))
return
}
ctx.Payload(&createTestOrderResponse{OrderNo: orderNo})
}
}