修改商城逻辑
This commit is contained in:
@@ -4,7 +4,126 @@ const { getDB } = require('../database');
|
||||
const matchingService = require('../services/matchingService');
|
||||
const { auth } = require('../middleware/auth');
|
||||
|
||||
// 创建匹配订单
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Matching
|
||||
* description: 匹配订单相关接口
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* components:
|
||||
* schemas:
|
||||
* MatchingOrder:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* description: 匹配订单ID
|
||||
* initiator_id:
|
||||
* type: integer
|
||||
* description: 发起人ID
|
||||
* matching_type:
|
||||
* type: string
|
||||
* enum: [small, large]
|
||||
* description: 匹配类型(小额或大额)
|
||||
* amount:
|
||||
* type: number
|
||||
* description: 匹配总金额
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [pending, matching, completed, failed]
|
||||
* description: 订单状态
|
||||
* created_at:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 创建时间
|
||||
* Allocation:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* description: 分配ID
|
||||
* from_user_id:
|
||||
* type: integer
|
||||
* description: 发送方用户ID
|
||||
* to_user_id:
|
||||
* type: integer
|
||||
* description: 接收方用户ID
|
||||
* amount:
|
||||
* type: number
|
||||
* description: 分配金额
|
||||
* cycle_number:
|
||||
* type: integer
|
||||
* description: 轮次编号
|
||||
* status:
|
||||
* type: string
|
||||
* enum: [pending, confirmed, rejected, cancelled]
|
||||
* description: 分配状态
|
||||
* created_at:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: 创建时间
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/create:
|
||||
* post:
|
||||
* summary: 创建匹配订单
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* matchingType:
|
||||
* type: string
|
||||
* enum: [small, large]
|
||||
* default: small
|
||||
* description: 匹配类型(小额或大额)
|
||||
* customAmount:
|
||||
* type: number
|
||||
* description: 大额匹配时的自定义金额(5000-50000之间)
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 匹配订单创建成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* matchingOrderId:
|
||||
* type: integer
|
||||
* amounts:
|
||||
* type: array
|
||||
* items:
|
||||
* type: number
|
||||
* matchingType:
|
||||
* type: string
|
||||
* totalAmount:
|
||||
* type: number
|
||||
* 400:
|
||||
* description: 参数错误或用户未满足匹配条件
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 404:
|
||||
* description: 用户不存在
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.post('/create', auth, async (req, res) => {
|
||||
try {
|
||||
console.log('匹配订单创建请求 - 用户ID:', req.user.id);
|
||||
@@ -89,7 +208,46 @@ router.post('/create', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 获取用户的匹配订单列表
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/my-orders:
|
||||
* get:
|
||||
* summary: 获取用户的匹配订单列表
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: page
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 1
|
||||
* description: 页码
|
||||
* - in: query
|
||||
* name: limit
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 10
|
||||
* description: 每页数量
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取匹配订单列表
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/MatchingOrder'
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.get('/my-orders', auth, async (req, res) => {
|
||||
try {
|
||||
const userId = req.user.id;
|
||||
@@ -109,7 +267,33 @@ router.get('/my-orders', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 获取用户待处理的分配
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/pending-allocations:
|
||||
* get:
|
||||
* summary: 获取用户待处理的分配
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取待处理分配
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Allocation'
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.get('/pending-allocations', auth, async (req, res) => {
|
||||
try {
|
||||
const userId = req.user.id;
|
||||
@@ -127,7 +311,42 @@ router.get('/pending-allocations', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 获取分配详情
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/allocation/{id}:
|
||||
* get:
|
||||
* summary: 获取分配详情
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 分配ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取分配详情
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* $ref: '#/components/schemas/Allocation'
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 403:
|
||||
* description: 无权限访问
|
||||
* 404:
|
||||
* description: 分配不存在
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.get('/allocation/:id', auth, async (req, res) => {
|
||||
try {
|
||||
const db = getDB();
|
||||
@@ -173,7 +392,63 @@ router.get('/allocation/:id', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 确认分配(创建转账)
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/confirm-allocation/{allocationId}:
|
||||
* post:
|
||||
* summary: 确认分配(创建转账)
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: allocationId
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 分配ID
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* transferAmount:
|
||||
* type: number
|
||||
* description: 转账金额
|
||||
* description:
|
||||
* type: string
|
||||
* description: 转账描述
|
||||
* voucher:
|
||||
* type: string
|
||||
* description: 转账凭证(图片URL)
|
||||
* required:
|
||||
* - voucher
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 转账凭证提交成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* transferId:
|
||||
* type: integer
|
||||
* 400:
|
||||
* description: 参数错误
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.post('/confirm-allocation/:allocationId', auth, async (req, res) => {
|
||||
try {
|
||||
const { allocationId } = req.params;
|
||||
@@ -209,7 +484,49 @@ router.post('/confirm-allocation/:allocationId', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 拒绝分配
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/reject-allocation/{allocationId}:
|
||||
* post:
|
||||
* summary: 拒绝分配
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: allocationId
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 分配ID
|
||||
* requestBody:
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* reason:
|
||||
* type: string
|
||||
* description: 拒绝原因
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 拒绝分配成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* message:
|
||||
* type: string
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 404:
|
||||
* description: 分配不存在或无权限
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.post('/reject-allocation/:allocationId', auth, async (req, res) => {
|
||||
try {
|
||||
const { allocationId } = req.params;
|
||||
@@ -264,7 +581,53 @@ router.post('/reject-allocation/:allocationId', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 获取匹配订单详情
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/order/{orderId}:
|
||||
* get:
|
||||
* summary: 获取匹配订单详情
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: orderId
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 订单ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取订单详情
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* order:
|
||||
* $ref: '#/components/schemas/MatchingOrder'
|
||||
* allocations:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Allocation'
|
||||
* records:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 403:
|
||||
* description: 无权限查看
|
||||
* 404:
|
||||
* description: 订单不存在
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.get('/order/:orderId', auth, async (req, res) => {
|
||||
try {
|
||||
const { orderId } = req.params;
|
||||
@@ -339,7 +702,43 @@ router.get('/order/:orderId', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 获取匹配统计信息
|
||||
/**
|
||||
* @swagger
|
||||
* /api/matching/stats:
|
||||
* get:
|
||||
* summary: 获取匹配统计信息
|
||||
* tags: [Matching]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取统计信息
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* userStats:
|
||||
* type: object
|
||||
* properties:
|
||||
* initiated_orders:
|
||||
* type: integer
|
||||
* participated_allocations:
|
||||
* type: integer
|
||||
* total_initiated_amount:
|
||||
* type: number
|
||||
* total_participated_amount:
|
||||
* type: number
|
||||
* 401:
|
||||
* description: 未授权
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.get('/stats', auth, async (req, res) => {
|
||||
try {
|
||||
const userId = req.user.id;
|
||||
|
||||
Reference in New Issue
Block a user