修改商城逻辑

This commit is contained in:
2025-08-28 09:14:56 +08:00
parent a1944a573e
commit 691789d5d3
28 changed files with 10842 additions and 292 deletions

View File

@@ -6,7 +6,106 @@ const logger = require('../config/logger');
const matchingService = require('../services/matchingService');
const dayjs = require('dayjs');
// 获取不合理的匹配记录(正余额用户被匹配的情况)
/**
* @swagger
* tags:
* name: MatchingAdmin
* description: 匹配订单管理员相关接口
*/
/**
* @swagger
* components:
* schemas:
* UnreasonableMatch:
* type: object
* properties:
* allocation_id:
* type: integer
* description: 分配ID
* from_user_id:
* type: integer
* description: 发送方用户ID
* to_user_id:
* type: integer
* description: 接收方用户ID
* amount:
* type: number
* description: 分配金额
* status:
* type: string
* enum: [pending, confirmed, rejected, cancelled]
* description: 分配状态
* to_username:
* type: string
* description: 接收方用户名
* to_user_balance:
* type: number
* description: 接收方用户余额
* from_username:
* type: string
* description: 发送方用户名
* from_user_balance:
* type: number
* description: 发送方用户余额
*/
/**
* @swagger
* /api/matching-admin/unreasonable-matches:
* get:
* summary: 获取不合理的匹配记录(正余额用户被匹配的情况)
* tags: [MatchingAdmin]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: 页码
* - in: query
* name: limit
* schema:
* type: integer
* default: 20
* description: 每页数量
* responses:
* 200:
* description: 成功获取不合理匹配记录
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: object
* properties:
* matches:
* type: array
* items:
* $ref: '#/components/schemas/UnreasonableMatch'
* pagination:
* type: object
* properties:
* page:
* type: integer
* limit:
* type: integer
* total:
* type: integer
* totalPages:
* type: integer
* 401:
* description: 未授权
* 403:
* description: 无管理员权限
* 500:
* description: 服务器错误
*/
router.get('/unreasonable-matches', auth, adminAuth, async (req, res) => {
try {
const page = parseInt(req.query.page) || 1;
@@ -72,7 +171,57 @@ router.get('/unreasonable-matches', auth, adminAuth, async (req, res) => {
}
});
// 修复不合理的匹配记录
/**
* @swagger
* /api/matching-admin/fix-unreasonable-match/{allocationId}:
* post:
* summary: 修复不合理的匹配记录
* tags: [MatchingAdmin]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: allocationId
* required: true
* schema:
* type: integer
* description: 分配ID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* action:
* type: string
* enum: [cancel, reassign]
* description: 修复操作类型(取消或重新分配)
* required:
* - action
* responses:
* 200:
* description: 修复成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* 400:
* description: 参数错误或无需修复
* 401:
* description: 未授权
* 403:
* description: 无管理员权限
* 404:
* description: 分配记录不存在
* 500:
* description: 服务器错误
*/
router.post('/fix-unreasonable-match/:allocationId', auth, adminAuth, async (req, res) => {
try {
const { allocationId } = req.params;
@@ -180,7 +329,54 @@ router.post('/fix-unreasonable-match/:allocationId', auth, adminAuth, async (req
}
});
// 获取匹配统计信息
/**
* @swagger
* /api/matching-admin/matching-stats:
* get:
* summary: 获取匹配统计信息
* tags: [MatchingAdmin]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: 成功获取匹配统计信息
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: object
* properties:
* currentStats:
* type: object
* properties:
* unreasonable_matches:
* type: integer
* reasonable_matches:
* type: integer
* system_matches:
* type: integer
* unreasonable_amount:
* type: number
* reasonable_amount:
* type: number
* yesterdayStats:
* type: object
* properties:
* total_outbound:
* type: number
* unique_amounts:
* type: integer
* 401:
* description: 未授权
* 403:
* description: 无管理员权限
* 500:
* description: 服务器错误
*/
router.get('/matching-stats', auth, adminAuth, async (req, res) => {
try {
@@ -224,7 +420,47 @@ router.get('/matching-stats', auth, adminAuth, async (req, res) => {
}
});
// 批量修复所有不合理匹配
/**
* @swagger
* /api/matching-admin/fix-all-unreasonable:
* post:
* summary: 批量修复所有不合理匹配
* tags: [MatchingAdmin]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: 批量修复完成
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* data:
* type: object
* properties:
* fixedCount:
* type: integer
* description: 成功修复的记录数
* errorCount:
* type: integer
* description: 修复失败的记录数
* errors:
* type: array
* items:
* type: string
* description: 错误信息列表最多10条
* 401:
* description: 未授权
* 403:
* description: 无管理员权限
* 500:
* description: 服务器错误
*/
router.post('/fix-all-unreasonable', auth, adminAuth, async (req, res) => {
try {
let fixedCount = 0;
@@ -312,7 +548,42 @@ router.post('/fix-all-unreasonable', auth, adminAuth, async (req, res) => {
}
});
// 确认分配
/**
* @swagger
* /api/matching-admin/confirm-allocation/{allocationId}:
* post:
* summary: 管理员确认分配
* tags: [MatchingAdmin]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: allocationId
* required: true
* schema:
* type: integer
* description: 分配ID
* responses:
* 200:
* description: 分配确认成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* 401:
* description: 未授权
* 403:
* description: 无管理员权限
* 404:
* description: 分配不存在或状态不是待处理
* 500:
* description: 服务器错误
*/
router.post('/confirm-allocation/:allocationId', auth, adminAuth, async (req, res) => {
try {
const { allocationId } = req.params;
@@ -405,8 +676,43 @@ router.post('/confirm-allocation/:allocationId', auth, adminAuth, async (req, re
}
});
// 取消分配
router.post('/cancel-allocation/:allocationId', auth, adminAuth, async (req, res) => {
/**
* @swagger
* /api/matching-admin/cancel-allocation/{allocationId}:
* post:
* summary: 管理员取消分配
* tags: [MatchingAdmin]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: allocationId
* required: true
* schema:
* type: integer
* description: 分配ID
* responses:
* 200:
* description: 分配取消成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* 401:
* description: 未授权
* 403:
* description: 无管理员权限
* 404:
* description: 分配不存在或状态不是待处理
* 500:
* description: 服务器错误
*/
router.post('/cancel-allocation/:allocationId', auth, adminAuth, async (req, res) => {
try {
const { allocationId } = req.params;
const adminId = req.user.id;