后台商品管理
This commit is contained in:
@@ -42,6 +42,7 @@ npm run dev
|
||||
- 后台仪表盘已接入真实统计数据,页面为 `http://localhost:5173/admin/dashboard`。
|
||||
- 用户管理后台已接入,页面为 `http://localhost:5173/admin/users`,支持冻结和解冻用户。
|
||||
- 订单管理后台已接入,页面为 `http://localhost:5173/admin/orders`,支持查看全量订单和交接记录。
|
||||
- 商品管理后台已接入,页面为 `http://localhost:5173/admin/listings`,支持查看全量商品和状态筛选。
|
||||
- 商品审核后台已接入,页面为 `http://localhost:5173/admin/listings/review`。
|
||||
- 审计日志后台已接入,页面为 `http://localhost:5173/admin/audit-logs`,支持查看高风险操作明细。
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ type ListingDTO struct {
|
||||
ID uint64 `json:"id"`
|
||||
AccountID uint64 `json:"account_id"`
|
||||
OwnerID uint64 `json:"owner_id"`
|
||||
OwnerPhone string `json:"owner_phone,omitempty"`
|
||||
OwnerNickname string `json:"owner_nickname,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
GameName string `json:"game_name"`
|
||||
@@ -47,3 +49,10 @@ type UpdateRequest = CreateRequest
|
||||
type ReviewRequest struct {
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
type AdminListQuery struct {
|
||||
OwnerID uint64
|
||||
Status string
|
||||
ReviewStatus string
|
||||
Limit int
|
||||
}
|
||||
|
||||
@@ -88,6 +88,19 @@ func (h *Handler) ListPendingReview(c *gin.Context) {
|
||||
response.OK(c, gin.H{"items": items})
|
||||
}
|
||||
|
||||
func (h *Handler) ListAdmin(c *gin.Context) {
|
||||
query, ok := parseAdminListQuery(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
items, err := h.service.ListAdmin(query)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"items": items})
|
||||
}
|
||||
|
||||
func (h *Handler) Approve(c *gin.Context) {
|
||||
id, ok := parseID(c)
|
||||
if !ok {
|
||||
@@ -208,6 +221,29 @@ func parseID(c *gin.Context) (uint64, bool) {
|
||||
return id, true
|
||||
}
|
||||
|
||||
func parseAdminListQuery(c *gin.Context) (AdminListQuery, bool) {
|
||||
var query AdminListQuery
|
||||
if raw := c.Query("owner_id"); raw != "" {
|
||||
value, err := strconv.ParseUint(raw, 10, 64)
|
||||
if err != nil || value == 0 {
|
||||
response.BadRequest(c, "号主 ID 不正确")
|
||||
return query, false
|
||||
}
|
||||
query.OwnerID = value
|
||||
}
|
||||
if raw := c.Query("limit"); raw != "" {
|
||||
value, err := strconv.Atoi(raw)
|
||||
if err != nil || value <= 0 {
|
||||
response.BadRequest(c, "查询条数不正确")
|
||||
return query, false
|
||||
}
|
||||
query.Limit = value
|
||||
}
|
||||
query.Status = c.Query("status")
|
||||
query.ReviewStatus = c.Query("review_status")
|
||||
return query, true
|
||||
}
|
||||
|
||||
func writeListingError(c *gin.Context, err error) {
|
||||
switch {
|
||||
case errors.Is(err, ErrDependencyUnavailable):
|
||||
|
||||
@@ -137,6 +137,31 @@ func (r *Repository) ListPendingReview() ([]ListingDTO, error) {
|
||||
return rowsToDTO(rows), nil
|
||||
}
|
||||
|
||||
func (r *Repository) ListAdmin(query AdminListQuery) ([]ListingDTO, error) {
|
||||
limit := query.Limit
|
||||
if limit <= 0 || limit > 500 {
|
||||
limit = 200
|
||||
}
|
||||
|
||||
db := r.baseQuery()
|
||||
if query.OwnerID > 0 {
|
||||
db = db.Where("l.owner_id = ?", query.OwnerID)
|
||||
}
|
||||
if query.Status != "" {
|
||||
db = db.Where("l.status = ?", query.Status)
|
||||
}
|
||||
if query.ReviewStatus != "" {
|
||||
db = db.Where("l.review_status = ?", query.ReviewStatus)
|
||||
}
|
||||
|
||||
var rows []listingRow
|
||||
err := db.Order("l.id DESC").Limit(limit).Scan(&rows).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rowsToDTO(rows), nil
|
||||
}
|
||||
|
||||
func (r *Repository) Approve(listingID uint64) (*ListingDTO, error) {
|
||||
var dto *ListingDTO
|
||||
err := r.db.Transaction(func(tx *gorm.DB) error {
|
||||
@@ -291,8 +316,10 @@ func (r *Repository) findDTO(where string, args ...any) (*ListingDTO, error) {
|
||||
|
||||
func (r *Repository) baseQuery() *gorm.DB {
|
||||
return r.db.Table("rental_listings AS l").
|
||||
Select("l.*, a.title, a.description, a.game_name, a.server_region, a.login_platform, a.rank_level, a.haf_coin_amount").
|
||||
Joins("JOIN game_accounts AS a ON a.id = l.account_id")
|
||||
Select(`l.*, a.title, a.description, a.game_name, a.server_region, a.login_platform, a.rank_level,
|
||||
a.haf_coin_amount, COALESCE(u.phone, '') AS owner_phone, COALESCE(u.nickname, '') AS owner_nickname`).
|
||||
Joins("JOIN game_accounts AS a ON a.id = l.account_id").
|
||||
Joins("LEFT JOIN users AS u ON u.id = l.owner_id")
|
||||
}
|
||||
|
||||
func (r *Repository) findForReviewUpdate(tx *gorm.DB, listingID uint64) (*model.RentalListing, *model.GameAccount, error) {
|
||||
@@ -310,6 +337,8 @@ func (r *Repository) findForReviewUpdate(tx *gorm.DB, listingID uint64) (*model.
|
||||
type listingRow struct {
|
||||
model.RentalListing
|
||||
Title string
|
||||
OwnerPhone string
|
||||
OwnerNickname string
|
||||
Description string
|
||||
GameName string
|
||||
ServerRegion string
|
||||
@@ -331,6 +360,8 @@ func (row listingRow) toDTO() ListingDTO {
|
||||
ID: row.ID,
|
||||
AccountID: row.AccountID,
|
||||
OwnerID: row.OwnerID,
|
||||
OwnerPhone: row.OwnerPhone,
|
||||
OwnerNickname: row.OwnerNickname,
|
||||
Title: row.Title,
|
||||
Description: row.Description,
|
||||
GameName: row.GameName,
|
||||
|
||||
@@ -52,6 +52,13 @@ func (s *Service) ListPendingReview() ([]ListingDTO, error) {
|
||||
return s.repo.ListPendingReview()
|
||||
}
|
||||
|
||||
func (s *Service) ListAdmin(query AdminListQuery) ([]ListingDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ListAdmin(query)
|
||||
}
|
||||
|
||||
func (s *Service) Approve(id uint64) (*ListingDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
|
||||
@@ -197,6 +197,7 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
adminRoutes.GET("/orders", orderHandler.AdminList)
|
||||
adminRoutes.GET("/orders/:id", orderHandler.AdminDetail)
|
||||
adminRoutes.GET("/orders/:id/handoff-records", orderHandler.AdminHandoffRecords)
|
||||
adminRoutes.GET("/listings", listingHandler.ListAdmin)
|
||||
adminRoutes.GET("/listings/pending", listingHandler.ListPendingReview)
|
||||
adminRoutes.POST("/listings/:id/approve", listingHandler.Approve)
|
||||
adminRoutes.POST("/listings/:id/reject", listingHandler.Reject)
|
||||
|
||||
+2
-1
@@ -57,6 +57,7 @@ API 规划以 [项目计划](project-plan.md) 第 10 章为准。
|
||||
- `GET /api/admin/orders`
|
||||
- `GET /api/admin/orders/{id}`
|
||||
- `GET /api/admin/orders/{id}/handoff-records`
|
||||
- `GET /api/admin/listings`
|
||||
- `GET /api/admin/listings/pending`
|
||||
- `POST /api/admin/listings/{id}/approve`
|
||||
- `POST /api/admin/listings/{id}/reject`
|
||||
@@ -67,4 +68,4 @@ API 规划以 [项目计划](project-plan.md) 第 10 章为准。
|
||||
- `PUT /api/admin/system-configs/{key}`
|
||||
- `GET /api/admin/audit-logs`
|
||||
|
||||
说明:`GET /api/admin/wallet/ledger` 支持按 `user_id`、`order_id`、`biz_type` 和 `limit` 查询最近资金流水。`GET /api/admin/audit-logs` 支持按 `actor_id`、`action`、`biz_type` 和 `limit` 查询最近审计日志。`/api/admin/*` 当前已使用独立后台登录,后续接入 RBAC 和 Casbin 权限后再按角色收紧访问控制。
|
||||
说明:`GET /api/admin/listings` 支持按 `owner_id`、`status`、`review_status` 和 `limit` 查询商品。`GET /api/admin/wallet/ledger` 支持按 `user_id`、`order_id`、`biz_type` 和 `limit` 查询最近资金流水。`GET /api/admin/audit-logs` 支持按 `actor_id`、`action`、`biz_type` 和 `limit` 查询最近审计日志。`/api/admin/*` 当前已使用独立后台登录,后续接入 RBAC 和 Casbin 权限后再按角色收紧访问控制。
|
||||
|
||||
@@ -129,6 +129,13 @@
|
||||
- 订单详情页 `/admin/orders/:id` 展示订单状态、双方用户、租期、交接记录和账号资产快照。
|
||||
- 当前后台订单管理先做只读能力,后续再补后台关闭订单、标记异常和客服介入操作。
|
||||
|
||||
## 开发态商品管理
|
||||
|
||||
- 商品管理接口为 `/api/admin/listings`,前端页面为 `/admin/listings`。
|
||||
- 后台可查看全量商品、号主、账号 ID、区服、平台、段位、哈夫币、时租、押金、商品状态和审核状态。
|
||||
- 当前支持按号主 ID、商品状态、审核状态和查询条数筛选。
|
||||
- 商品管理先做只读能力,强制下架、标记异常和后台改价等高风险操作后续接 RBAC 和审计后再做。
|
||||
|
||||
## 开发态审计日志
|
||||
|
||||
- 审计日志接口为 `/api/admin/audit-logs`,前端页面为 `/admin/audit-logs`。
|
||||
|
||||
@@ -4,6 +4,8 @@ export interface Listing {
|
||||
id: number
|
||||
account_id: number
|
||||
owner_id: number
|
||||
owner_phone?: string
|
||||
owner_nickname?: string
|
||||
title: string
|
||||
description: string
|
||||
game_name: string
|
||||
@@ -81,6 +83,19 @@ export async function fetchPendingReviewListings() {
|
||||
return data.data.items
|
||||
}
|
||||
|
||||
export interface AdminListingQuery {
|
||||
owner_id?: string
|
||||
status?: string
|
||||
review_status?: string
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export async function fetchAdminListings(query: AdminListingQuery = {}) {
|
||||
const params = Object.fromEntries(Object.entries(query).filter(([, value]) => value !== '' && value !== undefined))
|
||||
const { data } = await apiClient.get<ApiResponse<{ items: Listing[] }>>('/admin/listings', { params })
|
||||
return data.data.items
|
||||
}
|
||||
|
||||
export async function approveListing(id: number) {
|
||||
const { data } = await apiClient.post<ApiResponse<Listing>>(`/admin/listings/${id}/approve`)
|
||||
return data.data
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { DataLine, Document, DocumentChecked, Operation, ScaleToOriginal, SwitchButton, Tickets, User, Wallet } from '@element-plus/icons-vue'
|
||||
import { DataLine, Document, DocumentChecked, Operation, ScaleToOriginal, Shop, SwitchButton, Tickets, User, Wallet } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
@@ -14,6 +14,7 @@ const navItems = [
|
||||
{ label: '仪表盘', to: '/admin/dashboard', icon: DataLine },
|
||||
{ label: '用户管理', to: '/admin/users', icon: User },
|
||||
{ label: '订单管理', to: '/admin/orders', icon: Tickets },
|
||||
{ label: '商品管理', to: '/admin/listings', icon: Shop },
|
||||
{ label: '商品审核', to: '/admin/listings/review', icon: DocumentChecked },
|
||||
{ label: '仲裁中心', to: '/admin/disputes', icon: ScaleToOriginal },
|
||||
{ label: '资金流水', to: '/admin/wallet-ledger', icon: Wallet },
|
||||
|
||||
@@ -43,6 +43,12 @@ const router = createRouter({
|
||||
component: () => import('@/views/admin/AdminOrderDetailView.vue'),
|
||||
meta: { layout: 'admin', requiresAdmin: true },
|
||||
},
|
||||
{
|
||||
path: '/admin/listings',
|
||||
name: 'admin-listings',
|
||||
component: () => import('@/views/admin/AdminListingsView.vue'),
|
||||
meta: { layout: 'admin', requiresAdmin: true },
|
||||
},
|
||||
{
|
||||
path: '/admin/listings/review',
|
||||
name: 'admin-listing-review',
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
<script setup lang="ts">
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
|
||||
import { fetchAdminListings, type Listing } from '@/api/listings'
|
||||
|
||||
const loading = ref(false)
|
||||
const listings = ref<Listing[]>([])
|
||||
const filters = reactive({
|
||||
owner_id: '',
|
||||
status: '',
|
||||
review_status: '',
|
||||
limit: 200,
|
||||
})
|
||||
|
||||
const publishedCount = computed(() => listings.value.filter((item) => item.status === 'published').length)
|
||||
const rentedCount = computed(() => listings.value.filter((item) => item.status === 'rented').length)
|
||||
const pendingCount = computed(() => listings.value.filter((item) => item.review_status === 'pending').length)
|
||||
|
||||
onMounted(loadListings)
|
||||
|
||||
async function loadListings() {
|
||||
loading.value = true
|
||||
try {
|
||||
listings.value = await fetchAdminListings(filters)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
filters.owner_id = ''
|
||||
filters.status = ''
|
||||
filters.review_status = ''
|
||||
filters.limit = 200
|
||||
void loadListings()
|
||||
}
|
||||
|
||||
function money(value: number) {
|
||||
return `¥${Number(value || 0).toFixed(2)}`
|
||||
}
|
||||
|
||||
function ownerName(row: Listing) {
|
||||
return row.owner_phone || row.owner_nickname || `号主 ${row.owner_id}`
|
||||
}
|
||||
|
||||
function statusType(status: string) {
|
||||
if (status === 'published') return 'success'
|
||||
if (status === 'rented') return 'warning'
|
||||
if (status === 'offline') return 'info'
|
||||
return ''
|
||||
}
|
||||
|
||||
function reviewType(status: string) {
|
||||
if (status === 'approved') return 'success'
|
||||
if (status === 'pending') return 'warning'
|
||||
if (status === 'rejected') return 'danger'
|
||||
return 'info'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<div class="page-header-row">
|
||||
<div class="page-header">
|
||||
<p class="eyebrow">Listings</p>
|
||||
<h1>商品管理</h1>
|
||||
<p>查看全部租号商品、号主、区服平台、价格押金、上架状态和审核状态。</p>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<el-button @click="resetFilters">重置</el-button>
|
||||
<el-button type="primary" :icon="Search" :loading="loading" @click="loadListings">查询</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="metric-grid">
|
||||
<div class="metric-card">
|
||||
<span>当前结果</span>
|
||||
<strong>{{ listings.length }} 个</strong>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<span>已上架</span>
|
||||
<strong>{{ publishedCount }} 个</strong>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<span>租赁中</span>
|
||||
<strong>{{ rentedCount }} 个</strong>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<span>待审核</span>
|
||||
<strong>{{ pendingCount }} 个</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-form class="filter-panel" label-position="top">
|
||||
<el-form-item label="号主 ID">
|
||||
<el-input v-model="filters.owner_id" clearable placeholder="按号主筛选" />
|
||||
</el-form-item>
|
||||
<el-form-item label="商品状态">
|
||||
<el-select v-model="filters.status" clearable placeholder="全部状态" class="full-control">
|
||||
<el-option label="草稿" value="draft" />
|
||||
<el-option label="已上架" value="published" />
|
||||
<el-option label="租赁中" value="rented" />
|
||||
<el-option label="已下架" value="offline" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="审核状态">
|
||||
<el-select v-model="filters.review_status" clearable placeholder="全部审核状态" class="full-control">
|
||||
<el-option label="未提交" value="none" />
|
||||
<el-option label="待审核" value="pending" />
|
||||
<el-option label="已通过" value="approved" />
|
||||
<el-option label="已拒绝" value="rejected" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="查询条数">
|
||||
<el-input-number v-model="filters.limit" :min="20" :max="500" :step="20" class="full-control" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-table v-loading="loading" class="table-panel" :data="listings">
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column label="商品" min-width="220">
|
||||
<template #default="{ row }">
|
||||
<strong>{{ row.title }}</strong>
|
||||
<span class="table-subtext">账号 ID: {{ row.account_id }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="号主" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<strong>{{ ownerName(row) }}</strong>
|
||||
<span class="table-subtext">ID: {{ row.owner_id }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="server_region" label="区服" width="120" />
|
||||
<el-table-column prop="login_platform" label="平台" width="120" />
|
||||
<el-table-column prop="rank_level" label="段位" width="110" />
|
||||
<el-table-column prop="haf_coin_amount" label="哈夫币" width="110" />
|
||||
<el-table-column label="时租" width="100">
|
||||
<template #default="{ row }">{{ money(row.price_hourly) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="押金" width="100">
|
||||
<template #default="{ row }">{{ money(row.deposit_amount) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品状态" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="statusType(row.status)">{{ row.status }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="审核状态" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="reviewType(row.review_status)">{{ row.review_status }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="published_at" label="上架时间" min-width="180" />
|
||||
<el-table-column prop="updated_at" label="更新时间" min-width="180" />
|
||||
<el-table-column label="操作" width="110">
|
||||
<template #default="{ row }">
|
||||
<RouterLink v-if="row.status === 'published' && row.review_status === 'approved'" :to="`/listings/${row.id}`">
|
||||
<el-button size="small">前台详情</el-button>
|
||||
</RouterLink>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</section>
|
||||
</template>
|
||||
Reference in New Issue
Block a user