feat: 添加订单管理功能,支持跨租户分页查询,优化订单列表展示及查询条件
This commit is contained in:
96
backend/app/http/super/dto/order_page.go
Normal file
96
backend/app/http/super/dto/order_page.go
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"quyun/v2/app/requests"
|
||||||
|
"quyun/v2/pkg/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OrderPageFilter struct {
|
||||||
|
requests.Pagination `json:",inline" query:",inline"`
|
||||||
|
requests.SortQueryFilter `json:",inline" query:",inline"`
|
||||||
|
|
||||||
|
ID *int64 `json:"id,omitempty" query:"id"`
|
||||||
|
TenantID *int64 `json:"tenant_id,omitempty" query:"tenant_id"`
|
||||||
|
UserID *int64 `json:"user_id,omitempty" query:"user_id"`
|
||||||
|
|
||||||
|
TenantCode *string `json:"tenant_code,omitempty" query:"tenant_code"`
|
||||||
|
TenantName *string `json:"tenant_name,omitempty" query:"tenant_name"`
|
||||||
|
Username *string `json:"username,omitempty" query:"username"`
|
||||||
|
|
||||||
|
ContentID *int64 `json:"content_id,omitempty" query:"content_id"`
|
||||||
|
ContentTitle *string `json:"content_title,omitempty" query:"content_title"`
|
||||||
|
|
||||||
|
Type *consts.OrderType `json:"type,omitempty" query:"type"`
|
||||||
|
Status *consts.OrderStatus `json:"status,omitempty" query:"status"`
|
||||||
|
|
||||||
|
CreatedAtFrom *time.Time `json:"created_at_from,omitempty" query:"created_at_from"`
|
||||||
|
CreatedAtTo *time.Time `json:"created_at_to,omitempty" query:"created_at_to"`
|
||||||
|
PaidAtFrom *time.Time `json:"paid_at_from,omitempty" query:"paid_at_from"`
|
||||||
|
PaidAtTo *time.Time `json:"paid_at_to,omitempty" query:"paid_at_to"`
|
||||||
|
|
||||||
|
AmountPaidMin *int64 `json:"amount_paid_min,omitempty" query:"amount_paid_min"`
|
||||||
|
AmountPaidMax *int64 `json:"amount_paid_max,omitempty" query:"amount_paid_max"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *OrderPageFilter) TenantCodeTrimmed() string {
|
||||||
|
if f == nil || f.TenantCode == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.ToLower(strings.TrimSpace(*f.TenantCode))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *OrderPageFilter) TenantNameTrimmed() string {
|
||||||
|
if f == nil || f.TenantName == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(*f.TenantName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *OrderPageFilter) UsernameTrimmed() string {
|
||||||
|
if f == nil || f.Username == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(*f.Username)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *OrderPageFilter) ContentTitleTrimmed() string {
|
||||||
|
if f == nil || f.ContentTitle == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(*f.ContentTitle)
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderTenantLite struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderBuyerLite struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuperOrderItem struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Tenant *OrderTenantLite `json:"tenant,omitempty"`
|
||||||
|
Buyer *OrderBuyerLite `json:"buyer,omitempty"`
|
||||||
|
|
||||||
|
Type consts.OrderType `json:"type"`
|
||||||
|
Status consts.OrderStatus `json:"status"`
|
||||||
|
|
||||||
|
StatusDescription string `json:"status_description,omitempty"`
|
||||||
|
Currency consts.Currency `json:"currency"`
|
||||||
|
|
||||||
|
AmountOriginal int64 `json:"amount_original"`
|
||||||
|
AmountDiscount int64 `json:"amount_discount"`
|
||||||
|
AmountPaid int64 `json:"amount_paid"`
|
||||||
|
|
||||||
|
PaidAt time.Time `json:"paid_at"`
|
||||||
|
RefundedAt time.Time `json:"refunded_at"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package super
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"quyun/v2/app/http/super/dto"
|
"quyun/v2/app/http/super/dto"
|
||||||
|
"quyun/v2/app/requests"
|
||||||
"quyun/v2/app/services"
|
"quyun/v2/app/services"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
@@ -10,6 +11,21 @@ import (
|
|||||||
// @provider
|
// @provider
|
||||||
type order struct{}
|
type order struct{}
|
||||||
|
|
||||||
|
// list
|
||||||
|
//
|
||||||
|
// @Summary 订单列表
|
||||||
|
// @Tags Super
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param filter query dto.OrderPageFilter true "Filter"
|
||||||
|
// @Success 200 {object} requests.Pager{items=dto.SuperOrderItem}
|
||||||
|
//
|
||||||
|
// @Router /super/v1/orders [get]
|
||||||
|
// @Bind filter query
|
||||||
|
func (*order) list(ctx fiber.Ctx, filter *dto.OrderPageFilter) (*requests.Pager, error) {
|
||||||
|
return services.Order.SuperOrderPage(ctx, filter)
|
||||||
|
}
|
||||||
|
|
||||||
// statistics
|
// statistics
|
||||||
//
|
//
|
||||||
// @Summary 订单统计信息
|
// @Summary 订单统计信息
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Body[dto.LoginForm]("form"),
|
Body[dto.LoginForm]("form"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: order
|
// Register routes for controller: order
|
||||||
|
r.log.Debugf("Registering route: Get /super/v1/orders -> order.list")
|
||||||
|
router.Get("/super/v1/orders"[len(r.Path()):], DataFunc1(
|
||||||
|
r.order.list,
|
||||||
|
Query[dto.OrderPageFilter]("filter"),
|
||||||
|
))
|
||||||
r.log.Debugf("Registering route: Get /super/v1/orders/statistics -> order.statistics")
|
r.log.Debugf("Registering route: Get /super/v1/orders/statistics -> order.statistics")
|
||||||
router.Get("/super/v1/orders/statistics"[len(r.Path()):], DataFunc0(
|
router.Get("/super/v1/orders/statistics"[len(r.Path()):], DataFunc0(
|
||||||
r.order.statistics,
|
r.order.statistics,
|
||||||
|
|||||||
@@ -199,6 +199,224 @@ func (s *order) AdminOrderExportCSV(
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SuperOrderPage 平台侧分页查询订单(跨租户)。
|
||||||
|
func (s *order) SuperOrderPage(ctx context.Context, filter *superdto.OrderPageFilter) (*requests.Pager, error) {
|
||||||
|
if filter == nil {
|
||||||
|
filter = &superdto.OrderPageFilter{}
|
||||||
|
}
|
||||||
|
|
||||||
|
filter.Pagination.Format()
|
||||||
|
|
||||||
|
tbl, query := models.OrderQuery.QueryContext(ctx)
|
||||||
|
conds := []gen.Condition{}
|
||||||
|
|
||||||
|
if filter.ID != nil && *filter.ID > 0 {
|
||||||
|
conds = append(conds, tbl.ID.Eq(*filter.ID))
|
||||||
|
}
|
||||||
|
if filter.TenantID != nil && *filter.TenantID > 0 {
|
||||||
|
conds = append(conds, tbl.TenantID.Eq(*filter.TenantID))
|
||||||
|
}
|
||||||
|
if filter.UserID != nil && *filter.UserID > 0 {
|
||||||
|
conds = append(conds, tbl.UserID.Eq(*filter.UserID))
|
||||||
|
}
|
||||||
|
if filter.Type != nil && *filter.Type != "" {
|
||||||
|
conds = append(conds, tbl.Type.Eq(*filter.Type))
|
||||||
|
}
|
||||||
|
if filter.Status != nil && *filter.Status != "" {
|
||||||
|
conds = append(conds, tbl.Status.Eq(*filter.Status))
|
||||||
|
}
|
||||||
|
if filter.CreatedAtFrom != nil {
|
||||||
|
conds = append(conds, tbl.CreatedAt.Gte(*filter.CreatedAtFrom))
|
||||||
|
}
|
||||||
|
if filter.CreatedAtTo != nil {
|
||||||
|
conds = append(conds, tbl.CreatedAt.Lte(*filter.CreatedAtTo))
|
||||||
|
}
|
||||||
|
if filter.PaidAtFrom != nil {
|
||||||
|
conds = append(conds, tbl.PaidAt.Gte(*filter.PaidAtFrom))
|
||||||
|
}
|
||||||
|
if filter.PaidAtTo != nil {
|
||||||
|
conds = append(conds, tbl.PaidAt.Lte(*filter.PaidAtTo))
|
||||||
|
}
|
||||||
|
if filter.AmountPaidMin != nil {
|
||||||
|
conds = append(conds, tbl.AmountPaid.Gte(*filter.AmountPaidMin))
|
||||||
|
}
|
||||||
|
if filter.AmountPaidMax != nil {
|
||||||
|
conds = append(conds, tbl.AmountPaid.Lte(*filter.AmountPaidMax))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 买家用户名关键字。
|
||||||
|
if username := filter.UsernameTrimmed(); username != "" {
|
||||||
|
uTbl, _ := models.UserQuery.QueryContext(ctx)
|
||||||
|
query = query.LeftJoin(uTbl, uTbl.ID.EqCol(tbl.UserID))
|
||||||
|
conds = append(conds, uTbl.Username.Like(database.WrapLike(username)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 租户 code/name 关键字。
|
||||||
|
tenantCode := filter.TenantCodeTrimmed()
|
||||||
|
tenantName := filter.TenantNameTrimmed()
|
||||||
|
if tenantCode != "" || tenantName != "" {
|
||||||
|
tTbl, _ := models.TenantQuery.QueryContext(ctx)
|
||||||
|
query = query.LeftJoin(tTbl, tTbl.ID.EqCol(tbl.TenantID))
|
||||||
|
if tenantCode != "" {
|
||||||
|
conds = append(conds, tTbl.Code.Like(database.WrapLike(tenantCode)))
|
||||||
|
}
|
||||||
|
if tenantName != "" {
|
||||||
|
conds = append(conds, tTbl.Name.Like(database.WrapLike(tenantName)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内容过滤(orders 与 order_items 一对多,需要 group by)。
|
||||||
|
needItemJoin := (filter.ContentID != nil && *filter.ContentID > 0) || filter.ContentTitleTrimmed() != ""
|
||||||
|
if needItemJoin {
|
||||||
|
oiTbl, _ := models.OrderItemQuery.QueryContext(ctx)
|
||||||
|
query = query.LeftJoin(oiTbl, oiTbl.OrderID.EqCol(tbl.ID))
|
||||||
|
|
||||||
|
if filter.ContentID != nil && *filter.ContentID > 0 {
|
||||||
|
conds = append(conds, oiTbl.ContentID.Eq(*filter.ContentID))
|
||||||
|
}
|
||||||
|
if title := filter.ContentTitleTrimmed(); title != "" {
|
||||||
|
cTbl, _ := models.ContentQuery.QueryContext(ctx)
|
||||||
|
query = query.LeftJoin(cTbl, cTbl.ID.EqCol(oiTbl.ContentID))
|
||||||
|
conds = append(conds, cTbl.Title.Like(database.WrapLike(title)))
|
||||||
|
}
|
||||||
|
query = query.Group(tbl.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序白名单:避免把任意字符串拼进 SQL 导致注入或慢查询。
|
||||||
|
orderBys := make([]field.Expr, 0, 6)
|
||||||
|
allowedAsc := map[string]field.Expr{
|
||||||
|
"id": tbl.ID.Asc(),
|
||||||
|
"tenant_id": tbl.TenantID.Asc(),
|
||||||
|
"user_id": tbl.UserID.Asc(),
|
||||||
|
"status": tbl.Status.Asc(),
|
||||||
|
"created_at": tbl.CreatedAt.Asc(),
|
||||||
|
"paid_at": tbl.PaidAt.Asc(),
|
||||||
|
"amount_paid": tbl.AmountPaid.Asc(),
|
||||||
|
}
|
||||||
|
allowedDesc := map[string]field.Expr{
|
||||||
|
"id": tbl.ID.Desc(),
|
||||||
|
"tenant_id": tbl.TenantID.Desc(),
|
||||||
|
"user_id": tbl.UserID.Desc(),
|
||||||
|
"status": tbl.Status.Desc(),
|
||||||
|
"created_at": tbl.CreatedAt.Desc(),
|
||||||
|
"paid_at": tbl.PaidAt.Desc(),
|
||||||
|
"amount_paid": tbl.AmountPaid.Desc(),
|
||||||
|
}
|
||||||
|
for _, f := range filter.AscFields() {
|
||||||
|
f = strings.TrimSpace(f)
|
||||||
|
if f == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ob, ok := allowedAsc[f]; ok {
|
||||||
|
orderBys = append(orderBys, ob)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range filter.DescFields() {
|
||||||
|
f = strings.TrimSpace(f)
|
||||||
|
if f == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ob, ok := allowedDesc[f]; ok {
|
||||||
|
orderBys = append(orderBys, ob)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(orderBys) == 0 {
|
||||||
|
orderBys = append(orderBys, tbl.ID.Desc())
|
||||||
|
} else {
|
||||||
|
orderBys = append(orderBys, tbl.ID.Desc())
|
||||||
|
}
|
||||||
|
|
||||||
|
orders, total, err := query.Where(conds...).Order(orderBys...).FindByPage(int(filter.Offset()), int(filter.Limit))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tenantIDs := make([]int64, 0, len(orders))
|
||||||
|
userIDs := make([]int64, 0, len(orders))
|
||||||
|
for _, o := range orders {
|
||||||
|
if o == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if o.TenantID > 0 {
|
||||||
|
tenantIDs = append(tenantIDs, o.TenantID)
|
||||||
|
}
|
||||||
|
if o.UserID > 0 {
|
||||||
|
userIDs = append(userIDs, o.UserID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tenantIDs = lo.Uniq(tenantIDs)
|
||||||
|
userIDs = lo.Uniq(userIDs)
|
||||||
|
|
||||||
|
tenantMap := make(map[int64]*models.Tenant, len(tenantIDs))
|
||||||
|
if len(tenantIDs) > 0 {
|
||||||
|
tTbl, tQuery := models.TenantQuery.QueryContext(ctx)
|
||||||
|
tenants, err := tQuery.Where(tTbl.ID.In(tenantIDs...)).Find()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, te := range tenants {
|
||||||
|
if te == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tenantMap[te.ID] = te
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
userMap := make(map[int64]*models.User, len(userIDs))
|
||||||
|
if len(userIDs) > 0 {
|
||||||
|
uTbl, uQuery := models.UserQuery.QueryContext(ctx)
|
||||||
|
users, err := uQuery.Where(uTbl.ID.In(userIDs...)).Find()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, u := range users {
|
||||||
|
if u == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
userMap[u.ID] = u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
items := lo.Map(orders, func(o *models.Order, _ int) *superdto.SuperOrderItem {
|
||||||
|
if o == nil {
|
||||||
|
return &superdto.SuperOrderItem{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var tenantLite *superdto.OrderTenantLite
|
||||||
|
if te := tenantMap[o.TenantID]; te != nil {
|
||||||
|
tenantLite = &superdto.OrderTenantLite{ID: te.ID, Code: te.Code, Name: te.Name}
|
||||||
|
}
|
||||||
|
|
||||||
|
var buyerLite *superdto.OrderBuyerLite
|
||||||
|
if u := userMap[o.UserID]; u != nil {
|
||||||
|
buyerLite = &superdto.OrderBuyerLite{ID: u.ID, Username: u.Username}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &superdto.SuperOrderItem{
|
||||||
|
ID: o.ID,
|
||||||
|
Tenant: tenantLite,
|
||||||
|
Buyer: buyerLite,
|
||||||
|
Type: o.Type,
|
||||||
|
Status: o.Status,
|
||||||
|
StatusDescription: o.Status.Description(),
|
||||||
|
Currency: o.Currency,
|
||||||
|
AmountOriginal: o.AmountOriginal,
|
||||||
|
AmountDiscount: o.AmountDiscount,
|
||||||
|
AmountPaid: o.AmountPaid,
|
||||||
|
PaidAt: o.PaidAt,
|
||||||
|
RefundedAt: o.RefundedAt,
|
||||||
|
CreatedAt: o.CreatedAt,
|
||||||
|
UpdatedAt: o.UpdatedAt,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return &requests.Pager{
|
||||||
|
Pagination: filter.Pagination,
|
||||||
|
Total: total,
|
||||||
|
Items: items,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PurchaseContentParams 定义“租户内使用余额购买内容”的入参。
|
// PurchaseContentParams 定义“租户内使用余额购买内容”的入参。
|
||||||
type PurchaseContentParams struct {
|
type PurchaseContentParams struct {
|
||||||
// TenantID 租户 ID(多租户隔离范围)。
|
// TenantID 租户 ID(多租户隔离范围)。
|
||||||
|
|||||||
2
frontend/superadmin/dist/index.html
vendored
2
frontend/superadmin/dist/index.html
vendored
@@ -7,7 +7,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Sakai Vue</title>
|
<title>Sakai Vue</title>
|
||||||
<link href="https://fonts.cdnfonts.com/css/lato" rel="stylesheet">
|
<link href="https://fonts.cdnfonts.com/css/lato" rel="stylesheet">
|
||||||
<script type="module" crossorigin src="./assets/index-BPtkEofn.js"></script>
|
<script type="module" crossorigin src="./assets/index-CYuRitZG.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="./assets/index-DMmaUuq9.css">
|
<link rel="stylesheet" crossorigin href="./assets/index-DMmaUuq9.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ const model = ref([
|
|||||||
label: 'Super Admin',
|
label: 'Super Admin',
|
||||||
items: [
|
items: [
|
||||||
{ label: 'Tenants', icon: 'pi pi-fw pi-building', to: '/superadmin/tenants' },
|
{ label: 'Tenants', icon: 'pi pi-fw pi-building', to: '/superadmin/tenants' },
|
||||||
{ label: 'Users', icon: 'pi pi-fw pi-users', to: '/superadmin/users' }
|
{ label: 'Users', icon: 'pi pi-fw pi-users', to: '/superadmin/users' },
|
||||||
|
{ label: 'Orders', icon: 'pi pi-fw pi-shopping-cart', to: '/superadmin/orders' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -123,6 +123,11 @@ const router = createRouter({
|
|||||||
path: '/superadmin/users',
|
path: '/superadmin/users',
|
||||||
name: 'superadmin-users',
|
name: 'superadmin-users',
|
||||||
component: () => import('@/views/superadmin/Users.vue')
|
component: () => import('@/views/superadmin/Users.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/superadmin/orders',
|
||||||
|
name: 'superadmin-orders',
|
||||||
|
component: () => import('@/views/superadmin/Orders.vue')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,75 @@
|
|||||||
import { requestJson } from './apiClient';
|
import { requestJson } from './apiClient';
|
||||||
|
|
||||||
|
function normalizeItems(items) {
|
||||||
|
if (Array.isArray(items)) return items;
|
||||||
|
if (items && typeof items === 'object') return [items];
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
export const OrderService = {
|
export const OrderService = {
|
||||||
|
async listOrders({
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
id,
|
||||||
|
tenant_id,
|
||||||
|
tenant_code,
|
||||||
|
tenant_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
content_id,
|
||||||
|
content_title,
|
||||||
|
type,
|
||||||
|
status,
|
||||||
|
created_at_from,
|
||||||
|
created_at_to,
|
||||||
|
paid_at_from,
|
||||||
|
paid_at_to,
|
||||||
|
amount_paid_min,
|
||||||
|
amount_paid_max,
|
||||||
|
sortField,
|
||||||
|
sortOrder
|
||||||
|
} = {}) {
|
||||||
|
const iso = (d) => {
|
||||||
|
if (!d) return undefined;
|
||||||
|
const date = d instanceof Date ? d : new Date(d);
|
||||||
|
if (Number.isNaN(date.getTime())) return undefined;
|
||||||
|
return date.toISOString();
|
||||||
|
};
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
id,
|
||||||
|
tenant_id,
|
||||||
|
tenant_code,
|
||||||
|
tenant_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
content_id,
|
||||||
|
content_title,
|
||||||
|
type,
|
||||||
|
status,
|
||||||
|
created_at_from: iso(created_at_from),
|
||||||
|
created_at_to: iso(created_at_to),
|
||||||
|
paid_at_from: iso(paid_at_from),
|
||||||
|
paid_at_to: iso(paid_at_to),
|
||||||
|
amount_paid_min,
|
||||||
|
amount_paid_max
|
||||||
|
};
|
||||||
|
if (sortField && sortOrder) {
|
||||||
|
if (sortOrder === 1) query.asc = sortField;
|
||||||
|
if (sortOrder === -1) query.desc = sortField;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await requestJson('/super/v1/orders', { query });
|
||||||
|
return {
|
||||||
|
page: data?.page ?? page ?? 1,
|
||||||
|
limit: data?.limit ?? limit ?? 10,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
items: normalizeItems(data?.items)
|
||||||
|
};
|
||||||
|
},
|
||||||
async getOrderStatistics() {
|
async getOrderStatistics() {
|
||||||
return requestJson('/super/v1/orders/statistics');
|
return requestJson('/super/v1/orders/statistics');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
297
frontend/superadmin/src/views/superadmin/Orders.vue
Normal file
297
frontend/superadmin/src/views/superadmin/Orders.vue
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
<script setup>
|
||||||
|
import SearchField from '@/components/SearchField.vue';
|
||||||
|
import SearchPanel from '@/components/SearchPanel.vue';
|
||||||
|
import { OrderService } from '@/service/OrderService';
|
||||||
|
import { useToast } from 'primevue/usetoast';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
|
const orders = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const totalRecords = ref(0);
|
||||||
|
const page = ref(1);
|
||||||
|
const rows = ref(10);
|
||||||
|
|
||||||
|
const orderID = ref(null);
|
||||||
|
const tenantID = ref(null);
|
||||||
|
const tenantCode = ref('');
|
||||||
|
const tenantName = ref('');
|
||||||
|
const buyerUserID = ref(null);
|
||||||
|
const buyerUsername = ref('');
|
||||||
|
const contentID = ref(null);
|
||||||
|
const contentTitle = ref('');
|
||||||
|
const status = ref('');
|
||||||
|
const type = ref('');
|
||||||
|
const createdAtFrom = ref(null);
|
||||||
|
const createdAtTo = ref(null);
|
||||||
|
const paidAtFrom = ref(null);
|
||||||
|
const paidAtTo = ref(null);
|
||||||
|
const amountPaidMin = ref(null);
|
||||||
|
const amountPaidMax = ref(null);
|
||||||
|
const sortField = ref('id');
|
||||||
|
const sortOrder = ref(-1);
|
||||||
|
|
||||||
|
const statusOptions = [
|
||||||
|
{ label: '全部', value: '' },
|
||||||
|
{ label: 'created', value: 'created' },
|
||||||
|
{ label: 'paid', value: 'paid' },
|
||||||
|
{ label: 'refunding', value: 'refunding' },
|
||||||
|
{ label: 'refunded', value: 'refunded' },
|
||||||
|
{ label: 'canceled', value: 'canceled' },
|
||||||
|
{ label: 'failed', value: 'failed' }
|
||||||
|
];
|
||||||
|
|
||||||
|
const typeOptions = [
|
||||||
|
{ label: '全部', value: '' },
|
||||||
|
{ label: 'content_purchase', value: 'content_purchase' }
|
||||||
|
];
|
||||||
|
|
||||||
|
function formatDate(value) {
|
||||||
|
if (!value) return '-';
|
||||||
|
if (String(value).startsWith('0001-01-01')) return '-';
|
||||||
|
const date = new Date(value);
|
||||||
|
if (Number.isNaN(date.getTime())) return String(value);
|
||||||
|
return date.toLocaleString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatCny(amountInCents) {
|
||||||
|
const amount = Number(amountInCents) / 100;
|
||||||
|
if (!Number.isFinite(amount)) return '-';
|
||||||
|
return new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY' }).format(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOrderStatusSeverity(value) {
|
||||||
|
switch (value) {
|
||||||
|
case 'paid':
|
||||||
|
return 'success';
|
||||||
|
case 'created':
|
||||||
|
case 'refunding':
|
||||||
|
return 'warn';
|
||||||
|
case 'failed':
|
||||||
|
case 'canceled':
|
||||||
|
return 'danger';
|
||||||
|
default:
|
||||||
|
return 'secondary';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadOrders() {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const result = await OrderService.listOrders({
|
||||||
|
page: page.value,
|
||||||
|
limit: rows.value,
|
||||||
|
id: orderID.value || undefined,
|
||||||
|
tenant_id: tenantID.value || undefined,
|
||||||
|
tenant_code: tenantCode.value,
|
||||||
|
tenant_name: tenantName.value,
|
||||||
|
user_id: buyerUserID.value || undefined,
|
||||||
|
username: buyerUsername.value,
|
||||||
|
content_id: contentID.value || undefined,
|
||||||
|
content_title: contentTitle.value,
|
||||||
|
status: status.value,
|
||||||
|
type: type.value,
|
||||||
|
created_at_from: createdAtFrom.value || undefined,
|
||||||
|
created_at_to: createdAtTo.value || undefined,
|
||||||
|
paid_at_from: paidAtFrom.value || undefined,
|
||||||
|
paid_at_to: paidAtTo.value || undefined,
|
||||||
|
amount_paid_min: amountPaidMin.value || undefined,
|
||||||
|
amount_paid_max: amountPaidMax.value || undefined,
|
||||||
|
sortField: sortField.value,
|
||||||
|
sortOrder: sortOrder.value
|
||||||
|
});
|
||||||
|
orders.value = result.items;
|
||||||
|
totalRecords.value = result.total;
|
||||||
|
} catch (error) {
|
||||||
|
toast.add({ severity: 'error', summary: '加载失败', detail: error?.message || '无法加载订单列表', life: 4000 });
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearch() {
|
||||||
|
page.value = 1;
|
||||||
|
loadOrders();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onReset() {
|
||||||
|
orderID.value = null;
|
||||||
|
tenantID.value = null;
|
||||||
|
tenantCode.value = '';
|
||||||
|
tenantName.value = '';
|
||||||
|
buyerUserID.value = null;
|
||||||
|
buyerUsername.value = '';
|
||||||
|
contentID.value = null;
|
||||||
|
contentTitle.value = '';
|
||||||
|
status.value = '';
|
||||||
|
type.value = '';
|
||||||
|
createdAtFrom.value = null;
|
||||||
|
createdAtTo.value = null;
|
||||||
|
paidAtFrom.value = null;
|
||||||
|
paidAtTo.value = null;
|
||||||
|
amountPaidMin.value = null;
|
||||||
|
amountPaidMax.value = null;
|
||||||
|
sortField.value = 'id';
|
||||||
|
sortOrder.value = -1;
|
||||||
|
page.value = 1;
|
||||||
|
rows.value = 10;
|
||||||
|
loadOrders();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPage(event) {
|
||||||
|
page.value = (event.page ?? 0) + 1;
|
||||||
|
rows.value = event.rows ?? rows.value;
|
||||||
|
loadOrders();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSort(event) {
|
||||||
|
sortField.value = event.sortField ?? sortField.value;
|
||||||
|
sortOrder.value = event.sortOrder ?? sortOrder.value;
|
||||||
|
loadOrders();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadOrders();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="card">
|
||||||
|
<div class="flex items-center justify-between mb-4">
|
||||||
|
<h4 class="m-0">订单列表</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SearchPanel :loading="loading" @search="onSearch" @reset="onReset">
|
||||||
|
<SearchField label="OrderID">
|
||||||
|
<InputNumber v-model="orderID" :min="1" placeholder="精确匹配" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="TenantID">
|
||||||
|
<InputNumber v-model="tenantID" :min="1" placeholder="精确匹配" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="TenantCode">
|
||||||
|
<InputText v-model="tenantCode" placeholder="请输入" class="w-full" @keyup.enter="onSearch" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="TenantName">
|
||||||
|
<InputText v-model="tenantName" placeholder="请输入" class="w-full" @keyup.enter="onSearch" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="BuyerUserID">
|
||||||
|
<InputNumber v-model="buyerUserID" :min="1" placeholder="精确匹配" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="BuyerUsername">
|
||||||
|
<IconField>
|
||||||
|
<InputIcon>
|
||||||
|
<i class="pi pi-search" />
|
||||||
|
</InputIcon>
|
||||||
|
<InputText v-model="buyerUsername" placeholder="请输入" class="w-full" @keyup.enter="onSearch" />
|
||||||
|
</IconField>
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="ContentID">
|
||||||
|
<InputNumber v-model="contentID" :min="1" placeholder="精确匹配" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="ContentTitle">
|
||||||
|
<InputText v-model="contentTitle" placeholder="请输入" class="w-full" @keyup.enter="onSearch" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="状态">
|
||||||
|
<Select v-model="status" :options="statusOptions" optionLabel="label" optionValue="value" placeholder="请选择" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="类型">
|
||||||
|
<Select v-model="type" :options="typeOptions" optionLabel="label" optionValue="value" placeholder="请选择" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="创建时间 From">
|
||||||
|
<DatePicker v-model="createdAtFrom" showIcon showButtonBar placeholder="开始时间" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="创建时间 To">
|
||||||
|
<DatePicker v-model="createdAtTo" showIcon showButtonBar placeholder="结束时间" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="支付时间 From">
|
||||||
|
<DatePicker v-model="paidAtFrom" showIcon showButtonBar placeholder="开始时间" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="支付时间 To">
|
||||||
|
<DatePicker v-model="paidAtTo" showIcon showButtonBar placeholder="结束时间" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="实付金额 Min(分)">
|
||||||
|
<InputNumber v-model="amountPaidMin" :min="0" placeholder=">= 0" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
<SearchField label="实付金额 Max(分)">
|
||||||
|
<InputNumber v-model="amountPaidMax" :min="0" placeholder=">= 0" class="w-full" />
|
||||||
|
</SearchField>
|
||||||
|
</SearchPanel>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
:value="orders"
|
||||||
|
dataKey="id"
|
||||||
|
:loading="loading"
|
||||||
|
lazy
|
||||||
|
:paginator="true"
|
||||||
|
:rows="rows"
|
||||||
|
:totalRecords="totalRecords"
|
||||||
|
:first="(page - 1) * rows"
|
||||||
|
:rowsPerPageOptions="[10, 20, 50, 100]"
|
||||||
|
sortMode="single"
|
||||||
|
:sortField="sortField"
|
||||||
|
:sortOrder="sortOrder"
|
||||||
|
@page="onPage"
|
||||||
|
@sort="onSort"
|
||||||
|
currentPageReportTemplate="显示第 {first} - {last} 条,共 {totalRecords} 条"
|
||||||
|
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||||
|
scrollable
|
||||||
|
scrollHeight="flex"
|
||||||
|
responsiveLayout="scroll"
|
||||||
|
>
|
||||||
|
<Column field="id" header="ID" sortable style="min-width: 7rem" />
|
||||||
|
<Column header="租户" style="min-width: 16rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="font-medium">{{ data?.tenant?.name ?? '-' }}</span>
|
||||||
|
<span class="text-muted-color">{{ data?.tenant?.code ?? '-' }} / {{ data?.tenant?.id ?? '-' }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column header="买家" style="min-width: 14rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="font-medium">{{ data?.buyer?.username ?? '-' }}</span>
|
||||||
|
<span class="text-muted-color">ID: {{ data?.buyer?.id ?? '-' }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column field="type" header="类型" style="min-width: 12rem" />
|
||||||
|
<Column field="status" header="状态" sortable style="min-width: 12rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
<Tag :value="data?.status_description || data?.status || '-'" :severity="getOrderStatusSeverity(data?.status)" />
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column field="amount_paid" header="实付" sortable style="min-width: 10rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
{{ formatCny(data.amount_paid) }}
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column field="amount_original" header="原价" style="min-width: 10rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
{{ formatCny(data.amount_original) }}
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column field="amount_discount" header="优惠" style="min-width: 10rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
{{ formatCny(data.amount_discount) }}
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column field="created_at" header="创建时间" sortable style="min-width: 14rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
{{ formatDate(data.created_at) }}
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column field="paid_at" header="支付时间" sortable style="min-width: 14rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
{{ formatDate(data.paid_at) }}
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
<Column field="refunded_at" header="退款完成" style="min-width: 14rem">
|
||||||
|
<template #body="{ data }">
|
||||||
|
{{ formatDate(data.refunded_at) }}
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
</DataTable>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
Reference in New Issue
Block a user