提交
This commit is contained in:
@@ -4,133 +4,17 @@ 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);
|
||||
console.log('请求体:', req.body);
|
||||
const userId = req.user.id;
|
||||
const { matchingType = 'small', customAmount } = req.body;
|
||||
|
||||
const [user_type] = await getDB().query(`SELECT count(*) as total FROM users WHERE id=${userId} and user_type='directly_operated'`);
|
||||
if(user_type[0].total > 0){
|
||||
return res.status(400).json({message: '平台暂不支持直营用户获得融豆'})
|
||||
}
|
||||
// 验证匹配类型
|
||||
if (!['small', 'large'].includes(matchingType)) {
|
||||
return res.status(400).json({ message: '无效的匹配类型' });
|
||||
@@ -141,8 +25,8 @@ router.post('/create', auth, async (req, res) => {
|
||||
if (!customAmount || typeof customAmount !== 'number') {
|
||||
return res.status(400).json({ message: '大额匹配需要指定金额' });
|
||||
}
|
||||
if (customAmount < 5000 || customAmount > 50000) {
|
||||
return res.status(400).json({ message: '大额匹配金额必须在5000-50000之间' });
|
||||
if (customAmount < 3000 || customAmount > 50000) {
|
||||
return res.status(400).json({ message: '大额匹配金额必须在3000-50000之间' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,46 +92,7 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user