商城后端模板

This commit is contained in:
dzl
2025-09-24 10:02:03 +08:00
commit 658ff89c6a
93 changed files with 55153 additions and 0 deletions

81
docs/README.md Normal file
View File

@@ -0,0 +1,81 @@
# API 文档结构说明
本项目已将 Swagger API 文档从路由文件中分离出来,采用模块化的文档管理方式。
## 文件夹结构
```
docs/
├── README.md # 本说明文件
├── schemas/ # 数据模型定义
│ ├── product.js # 商品相关数据模型
│ ├── order.js # 订单相关数据模型
│ ├── user.js # 用户相关数据模型
│ ├── cart.js # 购物车相关数据模型
│ └── announcement.js # 通知公告相关数据模型
└── apis/ # API 接口定义
├── products.js # 商品相关 API
├── orders.js # 订单相关 API
└── announcements.js # 通知公告相关 API
```
## 优势
1. **模块化管理**: 按功能模块分离文档,便于维护和查找
2. **代码分离**: 路由文件专注于业务逻辑,文档定义独立管理
3. **复用性**: Schema 定义可以在多个 API 中复用
4. **可维护性**: 文档修改不会影响业务代码,降低出错风险
## 使用方法
### 添加新的 Schema
`schemas/` 文件夹中创建新的 `.js` 文件,使用 `@swagger` 注释定义数据模型:
```javascript
/**
* @swagger
* components:
* schemas:
* YourModel:
* type: object
* properties:
* id:
* type: integer
* description: ID
*/
```
### 添加新的 API 文档
`apis/` 文件夹中创建新的 `.js` 文件,使用 `@swagger` 注释定义 API 接口:
```javascript
/**
* @swagger
* tags:
* name: YourModule
* description: 模块描述
*/
/**
* @swagger
* /your-endpoint:
* get:
* summary: 接口描述
* tags: [YourModule]
* responses:
* 200:
* description: 成功响应
*/
```
## 配置
Swagger 配置文件 `swagger.js` 已更新扫描路径:
```javascript
apis: ['./docs/schemas/*.js', './docs/apis/*.js', './routes/*.js', './admin/routes/*.js']
```
这样既保持了对现有路由文件中文档的兼容性,又支持新的模块化文档结构。

736
docs/apis/announcements.js Normal file
View File

@@ -0,0 +1,736 @@
/**
* @swagger
* tags:
* name: Announcements
* description: 通知公告管理API
*/
/**
* @swagger
* /api/announcements/{id}:
* get:
* summary: 获取单个公告详情
* tags: [Announcements]
* 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/Announcement'
* 401:
* description: 未授权
* 404:
* description: 公告不存在
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements/{id}/read:
* post:
* summary: 标记公告为已读
* tags: [Announcements]
* 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
* example: true
* message:
* type: string
* example: "已标记为已读"
* 401:
* description: 未授权
* 404:
* description: 公告不存在
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements/unread/count:
* get:
* summary: 获取用户未读公告数量
* tags: [Announcements]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: 获取未读数量成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* unread_count:
* type: integer
* example: 5
* description: 未读公告数量
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements/batch/read:
* post:
* summary: 批量标记公告为已读
* tags: [Announcements]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - announcement_ids
* properties:
* announcement_ids:
* type: array
* items:
* type: integer
* example: [1, 2, 3]
* description: 公告ID列表
* responses:
* 200:
* description: 批量标记已读成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: "批量标记已读成功"
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements:
* post:
* summary: 创建新公告
* tags: [Announcements]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - title
* - content
* properties:
* title:
* type: string
* description: 公告标题
* content:
* type: string
* description: 公告内容
* type:
* type: string
* enum: [system, maintenance, promotion, warning]
* default: system
* priority:
* type: string
* enum: [low, medium, high, urgent]
* default: medium
* status:
* type: string
* enum: [draft, published]
* default: draft
* is_pinned:
* type: boolean
* default: false
* publish_time:
* type: string
* format: date-time
* expire_time:
* type: string
* format: date-time
* responses:
* 201:
* description: 公告创建成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* data:
* type: object
* properties:
* id:
* type: integer
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements/{id}:
* put:
* summary: 更新公告
* tags: [Announcements]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: 公告ID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* title:
* type: string
* content:
* type: string
* type:
* type: string
* enum: [system, maintenance, promotion, warning]
* priority:
* type: string
* enum: [low, medium, high, urgent]
* status:
* type: string
* enum: [draft, published, archived]
* is_pinned:
* type: boolean
* publish_time:
* type: string
* format: date-time
* expire_time:
* type: string
* format: date-time
* responses:
* 200:
* description: 公告更新成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* data:
* $ref: '#/components/schemas/Announcement'
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 404:
* description: 公告不存在
* 500:
* description: 服务器错误
*
* delete:
* summary: 删除公告
* tags: [Announcements]
* 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
* message:
* type: string
* 401:
* description: 未授权
* 404:
* description: 公告不存在
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements/public/list:
* get:
* summary: 获取公开发布的公告列表(无需认证)
* tags: [Announcements]
* parameters:
* - in: query
* name: limit
* schema:
* type: integer
* default: 5
* description: 获取数量
* responses:
* 200:
* description: 成功获取公开公告列表
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: array
* items:
* $ref: '#/components/schemas/Announcement'
* 500:
* description: 服务器错误
*/
/**
* @swagger
* components:
* schemas:
* Announcement:
* type: object
* required:
* - title
* - content
* properties:
* id:
* type: integer
* description: 公告ID
* title:
* type: string
* description: 公告标题
* content:
* type: string
* description: 公告内容
* type:
* type: string
* description: 公告类型
* enum: [system, maintenance, promotion, warning]
* priority:
* type: string
* description: 优先级
* enum: [low, medium, high, urgent]
* status:
* type: string
* description: 状态
* enum: [draft, published, archived]
* is_pinned:
* type: boolean
* description: 是否置顶
* publish_time:
* type: string
* format: date-time
* description: 发布时间
* expire_time:
* type: string
* format: date-time
* description: 过期时间
* created_by:
* type: integer
* description: 创建者ID
* created_at:
* type: string
* format: date-time
* description: 创建时间
* updated_at:
* type: string
* format: date-time
* description: 更新时间
*/
/**
* @swagger
* /api/announcements:
* get:
* summary: 获取通知公告列表
* tags: [Announcements]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: 页码
* - in: query
* name: limit
* schema:
* type: integer
* default: 10
* description: 每页数量
* - in: query
* name: search
* schema:
* type: string
* description: 搜索关键词(标题或内容)
* - in: query
* name: type
* schema:
* type: string
* enum: [system, activity, maintenance, urgent]
* description: 公告类型
* - in: query
* name: priority
* schema:
* type: string
* enum: [high, medium, low]
* description: 优先级
* - in: query
* name: status
* schema:
* type: string
* enum: [draft, published, expired]
* description: 状态
* - in: query
* name: isTop
* schema:
* type: boolean
* description: 是否置顶
* - in: query
* name: sortBy
* schema:
* type: string
* enum: [created_at, updated_at, publish_time, priority]
* default: created_at
* description: 排序字段
* - in: query
* name: sortOrder
* schema:
* type: string
* enum: [ASC, DESC]
* default: DESC
* description: 排序方向
* responses:
* 200:
* description: 成功获取公告列表
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* announcements:
* type: array
* items:
* $ref: '#/components/schemas/Announcement'
* total:
* type: integer
* example: 50
* page:
* type: integer
* example: 1
* limit:
* type: integer
* example: 10
* totalPages:
* type: integer
* example: 5
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*
* post:
* summary: 创建新的通知公告
* tags: [Announcements]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - title
* - content
* - type
* - priority
* properties:
* title:
* type: string
* description: 公告标题
* example: "系统维护通知"
* content:
* type: string
* description: 公告内容
* example: "系统将于今晚进行维护预计维护时间2小时"
* type:
* type: string
* enum: [system, activity, maintenance, urgent]
* description: 公告类型
* example: "maintenance"
* priority:
* type: string
* enum: [high, medium, low]
* description: 优先级
* example: "high"
* status:
* type: string
* enum: [draft, published]
* default: draft
* description: 状态
* isTop:
* type: boolean
* default: false
* description: 是否置顶
* publishTime:
* type: string
* format: date-time
* description: 发布时间
* expireTime:
* type: string
* format: date-time
* description: 过期时间
* responses:
* 201:
* description: 公告创建成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: "公告创建成功"
* data:
* $ref: '#/components/schemas/Announcement'
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements/{id}:
* put:
* summary: 更新通知公告
* tags: [Announcements]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: 公告ID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* title:
* type: string
* description: 公告标题
* content:
* type: string
* description: 公告内容
* type:
* type: string
* enum: [system, activity, maintenance, urgent]
* description: 公告类型
* priority:
* type: string
* enum: [high, medium, low]
* description: 优先级
* status:
* type: string
* enum: [draft, published, expired]
* description: 状态
* isTop:
* type: boolean
* description: 是否置顶
* publishTime:
* type: string
* format: date-time
* description: 发布时间
* expireTime:
* type: string
* format: date-time
* description: 过期时间
* responses:
* 200:
* description: 公告更新成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: "公告更新成功"
* data:
* $ref: '#/components/schemas/Announcement'
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 404:
* description: 公告不存在
* 500:
* description: 服务器错误
*
* delete:
* summary: 删除通知公告
* tags: [Announcements]
* 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
* example: true
* message:
* type: string
* example: "公告删除成功"
* 401:
* description: 未授权
* 404:
* description: 公告不存在
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/announcements/{id}/toggle-top:
* put:
* summary: 切换公告置顶状态
* tags: [Announcements]
* 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
* example: true
* message:
* type: string
* example: "置顶状态更新成功"
* data:
* type: object
* properties:
* isTop:
* type: boolean
* example: true
* 401:
* description: 未授权
* 404:
* description: 公告不存在
* 500:
* description: 服务器错误
*/

87
docs/apis/captcha.js Normal file
View File

@@ -0,0 +1,87 @@
/**
* @swagger
* tags:
* name: Captcha
* description: 验证码API
*/
/**
* @swagger
* /captcha/generate:
* get:
* summary: 生成图形验证码
* tags: [Captcha]
* responses:
* 200:
* description: 成功生成验证码
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* captchaId:
* type: string
* description: 验证码唯一ID
* image:
* type: string
* description: Base64编码的SVG验证码图片
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /captcha/verify:
* post:
* summary: 验证用户输入的验证码
* tags: [Captcha]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - captchaId
* - captchaText
* properties:
* captchaId:
* type: string
* description: 验证码唯一ID
* captchaText:
* type: string
* description: 用户输入的验证码
* responses:
* 200:
* description: 验证码验证成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: 验证码验证成功
* 400:
* description: 验证码错误或已过期
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: false
* message:
* type: string
* example: 验证码错误
* 500:
* description: 服务器错误
*/

159
docs/apis/matching.js Normal file
View File

@@ -0,0 +1,159 @@
/**
* @swagger
* tags:
* name: Matching
* description: 匹配订单相关接口
*/
/**
* @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: 服务器错误
*/
/**
* @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: 服务器错误
*/

273
docs/apis/orders.js Normal file
View File

@@ -0,0 +1,273 @@
/**
* @swagger
* tags:
* name: Orders
* description: 订单管理API
*/
/**
* @swagger
* /api/orders:
* get:
* summary: 获取订单列表
* tags: [Orders]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: 页码
* - in: query
* name: limit
* schema:
* type: integer
* default: 10
* description: 每页数量
* - in: query
* name: search
* schema:
* type: string
* description: 搜索关键词
* - in: query
* name: orderNumber
* schema:
* type: string
* description: 订单号
* - in: query
* name: username
* schema:
* type: string
* description: 用户名
* - in: query
* name: status
* schema:
* type: string
* description: 订单状态
* - in: query
* name: startDate
* schema:
* type: string
* format: date
* description: 开始日期
* - in: query
* name: endDate
* schema:
* type: string
* format: date
* description: 结束日期
* responses:
* 200:
* description: 成功获取订单列表
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: object
* properties:
* orders:
* type: array
* items:
* $ref: '#/components/schemas/Order'
* pagination:
* type: object
* properties:
* page:
* type: integer
* limit:
* type: integer
* total:
* type: integer
* pages:
* type: integer
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/orders/confirm:
* post:
* summary: 确认下单
* tags: [Orders]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - pre_order_id
* - address
* properties:
* pre_order_id:
* type: integer
* description: 预订单ID
* address:
* type: object
* properties:
* recipient_name:
* type: string
* description: 收货人姓名
* phone:
* type: string
* description: 收货人电话
* province:
* type: string
* description: 省份
* city:
* type: string
* description: 城市
* district:
* type: string
* description: 区县
* detail_address:
* type: string
* description: 详细地址
* responses:
* 200:
* description: 确认下单成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* data:
* type: object
* properties:
* order_id:
* type: integer
* order_no:
* type: string
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 404:
* description: 预订单不存在
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/orders/pre-order/{id}:
* get:
* summary: 获取预订单详情
* tags: [Orders]
* 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:
* type: object
* properties:
* id:
* type: integer
* order_no:
* type: string
* total_amount:
* type: integer
* total_points:
* type: integer
* total_rongdou:
* type: integer
* status:
* type: string
* created_at:
* type: string
* items:
* type: array
* items:
* type: object
* properties:
* id:
* type: integer
* product_id:
* type: integer
* product_name:
* type: string
* quantity:
* type: integer
* price:
* type: integer
* points_price:
* type: integer
* rongdou_price:
* type: integer
* spec_info:
* type: object
* 401:
* description: 未授权
* 404:
* description: 预订单不存在
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/orders/{id}:
* get:
* summary: 获取单个订单详情
* tags: [Orders]
* 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:
* type: object
* properties:
* order:
* $ref: '#/components/schemas/Order'
* 401:
* description: 未授权
* 404:
* description: 订单不存在
* 500:
* description: 服务器错误
*/

154
docs/apis/products.js Normal file
View File

@@ -0,0 +1,154 @@
/**
* @swagger
* tags:
* name: Products
* description: 商品管理API
*/
/**
* @swagger
* /products:
* get:
* summary: 获取商品列表
* tags: [Products]
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: 页码
* - in: query
* name: limit
* schema:
* type: integer
* default: 10
* description: 每页数量
* - in: query
* name: search
* schema:
* type: string
* description: 搜索关键词
* - in: query
* name: category
* schema:
* type: string
* description: 商品分类
* - in: query
* name: status
* schema:
* type: string
* enum: [active, inactive]
* description: 商品状态
* responses:
* 200:
* description: 成功获取商品列表
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: object
* properties:
* products:
* type: array
* items:
* $ref: '#/components/schemas/Product'
* pagination:
* type: object
* properties:
* page:
* type: integer
* limit:
* type: integer
* total:
* type: integer
* pages:
* type: integer
*/
/**
* @swagger
* /products/categories:
* get:
* summary: 获取商品分类列表
* tags: [Products]
* responses:
* 200:
* description: 成功获取分类列表
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: array
* items:
* type: string
*/
/**
* @swagger
* /products/hot:
* get:
* summary: 获取热门商品
* tags: [Products]
* parameters:
* - 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: object
* properties:
* products:
* type: array
* items:
* $ref: '#/components/schemas/Product'
*/
/**
* @swagger
* /products/{id}:
* get:
* summary: 获取商品详情
* tags: [Products]
* 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/Product'
* 404:
* description: 商品不存在
*/

388
docs/apis/transfers.js Normal file
View File

@@ -0,0 +1,388 @@
/**
* @swagger
* components:
* schemas:
* Transfer:
* type: object
* properties:
* id:
* type: integer
* description: 转账记录ID
* user_id:
* type: integer
* description: 用户ID
* recipient_id:
* type: integer
* description: 接收方用户ID
* amount:
* type: number
* format: float
* description: 转账金额
* status:
* type: string
* enum: [pending, completed, failed, cancelled]
* description: 转账状态
* transfer_type:
* type: string
* enum: [user_to_user, user_to_system, system_to_user]
* description: 转账类型
* voucher_image:
* type: string
* description: 转账凭证图片路径
* remark:
* type: string
* description: 转账备注
* created_at:
* type: string
* format: date-time
* description: 创建时间
* updated_at:
* type: string
* format: date-time
* description: 更新时间
* Pagination:
* type: object
* properties:
* total:
* type: integer
* description: 总记录数
* page:
* type: integer
* description: 当前页码
* limit:
* type: integer
* description: 每页记录数
* total_pages:
* type: integer
* description: 总页数
*/
/**
* @swagger
* /transfers:
* get:
* summary: 获取转账列表
* tags: [Transfers]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: status
* schema:
* type: string
* description: 转账状态过滤
* - in: query
* name: transfer_type
* schema:
* type: string
* description: 转账类型过滤
* - in: query
* name: start_date
* schema:
* type: string
* format: date
* description: 开始日期过滤
* - in: query
* name: end_date
* schema:
* type: string
* format: date
* description: 结束日期过滤
* - in: query
* name: search
* schema:
* type: string
* description: 搜索关键词(用户名或真实姓名)
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: 页码
* - in: query
* name: limit
* schema:
* type: integer
* default: 10
* description: 每页数量
* - in: query
* name: sort
* schema:
* type: string
* description: 排序字段
* - in: query
* name: order
* schema:
* type: string
* enum: [asc, desc]
* description: 排序方向
* responses:
* 200:
* description: 成功获取转账列表
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: object
* properties:
* transfers:
* type: array
* items:
* $ref: '#/components/schemas/Transfer'
* pagination:
* $ref: '#/components/schemas/Pagination'
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /transfers/list:
* get:
* summary: 获取转账记录列表
* tags: [Transfers]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: status
* schema:
* type: string
* description: 转账状态过滤
* - in: query
* name: transfer_type
* schema:
* type: string
* description: 转账类型过滤
* - in: query
* name: start_date
* schema:
* type: string
* format: date
* description: 开始日期过滤
* - in: query
* name: end_date
* schema:
* type: string
* format: date
* description: 结束日期过滤
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* description: 页码
* - in: query
* name: limit
* schema:
* type: integer
* default: 10
* description: 每页数量
* - in: query
* name: sort
* schema:
* type: string
* description: 排序字段
* - in: query
* name: order
* schema:
* type: string
* enum: [asc, desc]
* description: 排序方向
* responses:
* 200:
* description: 成功获取转账记录列表
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: object
* properties:
* transfers:
* type: array
* items:
* $ref: '#/components/schemas/Transfer'
* pagination:
* $ref: '#/components/schemas/Pagination'
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /transfers/public-account:
* get:
* summary: 获取公户信息
* tags: [Transfers]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: 成功获取公户信息
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* id:
* type: integer
* description: 公户ID
* username:
* type: string
* description: 公户用户名
* example: public_account
* real_name:
* type: string
* description: 公户名称
* balance:
* type: number
* format: float
* description: 公户余额
* 401:
* description: 未授权
* 404:
* description: 公户不存在
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /transfers/create:
* post:
* summary: 创建转账记录
* tags: [Transfers]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - to_user_id
* - amount
* - transfer_type
* properties:
* to_user_id:
* type: integer
* description: 接收方用户ID
* amount:
* type: number
* format: float
* description: 转账金额
* transfer_type:
* type: string
* enum: [user_to_user, user_to_system, system_to_user]
* description: 转账类型
* remark:
* type: string
* description: 转账备注
* responses:
* 201:
* description: 转账记录创建成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: 转账记录创建成功,等待确认
* data:
* type: object
* properties:
* transfer_id:
* type: integer
* description: 转账记录ID
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /transfers/admin/create:
* post:
* summary: 管理员创建转账记录
* tags: [Transfers]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - from_user_id
* - to_user_id
* - amount
* - transfer_type
* properties:
* from_user_id:
* type: integer
* description: 发送方用户ID
* to_user_id:
* type: integer
* description: 接收方用户ID
* amount:
* type: number
* format: float
* description: 转账金额
* transfer_type:
* type: string
* enum: [user_to_user, user_to_system, system_to_user]
* description: 转账类型
* description:
* type: string
* description: 转账描述
* responses:
* 201:
* description: 转账记录创建成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: 转账记录创建成功
* data:
* type: object
* properties:
* transfer_id:
* type: integer
* description: 转账记录ID
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 403:
* description: 权限不足
* 500:
* description: 服务器错误
*/

423
docs/apis/user.js Normal file
View File

@@ -0,0 +1,423 @@
/**
* @swagger
* tags:
* name: Authentication
* description: 用户认证API
*/
/**
* @swagger
* components:
* schemas:
* LoginCredentials:
* type: object
* required:
* - username
* - password
* properties:
* username:
* type: string
* description: 用户名或手机号
* password:
* type: string
* description: 密码
* RegisterRequest:
* type: object
* required:
* - username
* - phone
* - password
* - registrationCode
* - city
* - district_id
* - captchaId
* - captchaText
* - smsCode
* properties:
* username:
* type: string
* description: 用户名
* phone:
* type: string
* description: 手机号
* password:
* type: string
* description: 密码
* registrationCode:
* type: string
* description: 注册激活码
* city:
* type: string
* description: 城市
* district_id:
* type: string
* description: 区域ID
* captchaId:
* type: string
* description: 图形验证码ID
* captchaText:
* type: string
* description: 图形验证码文本
* smsCode:
* type: string
* description: 短信验证码
* role:
* type: string
* description: 用户角色
* default: user
*/
/**
* @swagger
* /users/pending-audit:
* get:
* summary: 获取待审核用户列表(管理员权限)
* tags: [Users]
* 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: object
* properties:
* users:
* type: array
* items:
* $ref: '#/components/schemas/User'
* pagination:
* type: object
* properties:
* page:
* type: integer
* limit:
* type: integer
* total:
* type: integer
* pages:
* type: integer
* 401:
* description: 未授权
* 403:
* description: 权限不足
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /auth/register:
* post:
* summary: 用户注册
* description: 需要提供有效的激活码才能注册
* tags: [Authentication]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/RegisterRequest'
* responses:
* 201:
* description: 用户注册成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* token:
* type: string
* description: JWT认证令牌
* user:
* type: object
* properties:
* id:
* type: integer
* username:
* type: string
* role:
* type: string
* 400:
* description: 请求参数错误
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /auth/login:
* post:
* summary: 用户登录
* tags: [Authentication]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/LoginCredentials'
* responses:
* 200:
* description: 登录成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* token:
* type: string
* description: JWT认证令牌
* user:
* type: object
* properties:
* id:
* type: integer
* username:
* type: string
* role:
* type: string
* avatar:
* type: string
* points:
* type: integer
* 400:
* description: 请求参数错误
* 401:
* description: 用户名或密码错误
* 403:
* description: 账户审核未通过
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /api/users/{id}/distribute:
* put:
* summary: 设置用户分发状态
* description: 更新指定用户的分发状态
* tags: [Users]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: 用户ID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - is_distribute
* properties:
* is_distribute:
* type: boolean
* description: 分发状态true为启用分发false为禁用分发
* example: true
* responses:
* 200:
* description: 分发状态更新成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: "分发状态更新成功"
* is_distribute:
* type: boolean
* description: 更新后的分发状态
* example: true
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: false
* message:
* type: string
* example: "分发状态无效"
* 404:
* description: 用户不存在
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: false
* message:
* type: string
* example: "用户不存在"
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: false
* message:
* type: string
* example: "服务器内部错误"
*/
/**
* @swagger
* components:
* schemas:
* User:
* type: object
* required:
* - username
* - password
* - real_name
* - id_card
* properties:
* id:
* type: integer
* description: 用户ID
* username:
* type: string
* description: 用户名
* role:
* type: string
* description: 用户角色
* enum: [user, admin, merchant]
* avatar:
* type: string
* description: 用户头像URL
* points:
* type: integer
* description: 用户积分
* real_name:
* type: string
* description: 真实姓名
* id_card:
* type: string
* description: 身份证号
* phone:
* type: string
* description: 手机号
* is_system_account:
* type: boolean
* description: 是否为系统账户
* is_distribute:
* type: boolean
* description: 是否为分发账户
* created_at:
* type: string
* format: date-time
* description: 创建时间
* updated_at:
* type: string
* format: date-time
* description: 更新时间
*/
/**
* @swagger
* /users:
* post:
* summary: 创建用户(管理员权限)
* tags: [Users]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - username
* - password
* - real_name
* - id_card
* properties:
* username:
* type: string
* password:
* type: string
* role:
* type: string
* enum: [user, admin, merchant]
* default: user
* is_system_account:
* type: boolean
* default: false
* real_name:
* type: string
* id_card:
* type: string
* wechat_qr:
* type: string
* alipay_qr:
* type: string
* bank_card:
* type: string
* unionpay_qr:
* type: string
* phone:
* type: string
* responses:
* 201:
* description: 用户创建成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
* user:
* $ref: '#/components/schemas/User'
* 400:
* description: 请求参数错误
* 401:
* description: 未授权
* 403:
* description: 权限不足
* 500:
* description: 服务器错误
*/

View File

@@ -0,0 +1,225 @@
/**
* @swagger
* components:
* schemas:
* Announcement:
* type: object
* required:
* - title
* - content
* - type
* - priority
* properties:
* id:
* type: integer
* description: 公告ID
* example: 1
* title:
* type: string
* description: 公告标题
* example: "系统维护通知"
* content:
* type: string
* description: 公告内容
* example: "系统将于今晚进行维护预计维护时间2小时期间可能影响部分功能使用。"
* type:
* type: string
* description: 公告类型
* enum: [system, activity, maintenance, urgent]
* example: "maintenance"
* priority:
* type: string
* description: 优先级
* enum: [high, medium, low]
* example: "high"
* status:
* type: string
* description: 公告状态
* enum: [draft, published, expired]
* example: "published"
* isTop:
* type: boolean
* description: 是否置顶
* example: false
* publishTime:
* type: string
* format: date-time
* description: 发布时间
* example: "2024-01-15T10:00:00Z"
* expireTime:
* type: string
* format: date-time
* description: 过期时间
* example: "2024-01-20T10:00:00Z"
* createdBy:
* type: integer
* description: 创建者用户ID
* example: 1
* createdAt:
* type: string
* format: date-time
* description: 创建时间
* example: "2024-01-15T09:00:00Z"
* updatedAt:
* type: string
* format: date-time
* description: 更新时间
* example: "2024-01-15T09:30:00Z"
* creator:
* type: object
* description: 创建者信息
* properties:
* id:
* type: integer
* example: 1
* username:
* type: string
* example: "admin"
* email:
* type: string
* example: "admin@example.com"
*
* AnnouncementCreate:
* type: object
* required:
* - title
* - content
* - type
* - priority
* properties:
* title:
* type: string
* description: 公告标题
* example: "系统维护通知"
* content:
* type: string
* description: 公告内容
* example: "系统将于今晚进行维护预计维护时间2小时。"
* type:
* type: string
* description: 公告类型
* enum: [system, activity, maintenance, urgent]
* example: "maintenance"
* priority:
* type: string
* description: 优先级
* enum: [high, medium, low]
* example: "high"
* status:
* type: string
* description: 公告状态
* enum: [draft, published]
* default: draft
* example: "draft"
* isTop:
* type: boolean
* description: 是否置顶
* default: false
* example: false
* publishTime:
* type: string
* format: date-time
* description: 发布时间
* example: "2024-01-15T10:00:00Z"
* expireTime:
* type: string
* format: date-time
* description: 过期时间
* example: "2024-01-20T10:00:00Z"
*
* AnnouncementUpdate:
* type: object
* properties:
* title:
* type: string
* description: 公告标题
* example: "系统维护通知(更新)"
* content:
* type: string
* description: 公告内容
* example: "系统维护时间调整为明晚进行。"
* type:
* type: string
* description: 公告类型
* enum: [system, activity, maintenance, urgent]
* example: "maintenance"
* priority:
* type: string
* description: 优先级
* enum: [high, medium, low]
* example: "medium"
* status:
* type: string
* description: 公告状态
* enum: [draft, published, expired]
* example: "published"
* isTop:
* type: boolean
* description: 是否置顶
* example: true
* publishTime:
* type: string
* format: date-time
* description: 发布时间
* example: "2024-01-16T10:00:00Z"
* expireTime:
* type: string
* format: date-time
* description: 过期时间
* example: "2024-01-21T10:00:00Z"
*
* AnnouncementList:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* announcements:
* type: array
* items:
* $ref: '#/components/schemas/Announcement'
* total:
* type: integer
* description: 总记录数
* example: 50
* page:
* type: integer
* description: 当前页码
* example: 1
* limit:
* type: integer
* description: 每页数量
* example: 10
* totalPages:
* type: integer
* description: 总页数
* example: 5
*
* AnnouncementResponse:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: "操作成功"
* data:
* $ref: '#/components/schemas/Announcement'
*
* AnnouncementError:
* type: object
* properties:
* success:
* type: boolean
* example: false
* message:
* type: string
* example: "操作失败"
* error:
* type: string
* example: "公告不存在"
*/

93
docs/schemas/cart.js Normal file
View File

@@ -0,0 +1,93 @@
/**
* @swagger
* components:
* schemas:
* CartItem:
* type: object
* required:
* - user_id
* - product_id
* - quantity
* properties:
* id:
* type: integer
* description: 购物车商品ID
* user_id:
* type: integer
* description: 用户ID
* product_id:
* type: integer
* description: 商品ID
* quantity:
* type: integer
* description: 商品数量
* created_at:
* type: string
* format: date-time
* description: 创建时间
* updated_at:
* type: string
* format: date-time
* description: 更新时间
*
* CartItemWithProduct:
* type: object
* properties:
* id:
* type: integer
* description: 购物车商品ID
* product_id:
* type: integer
* description: 商品ID
* product_name:
* type: string
* description: 商品名称
* quantity:
* type: integer
* description: 商品数量
* points_price:
* type: integer
* description: 积分价格
* rongdou_price:
* type: number
* description: 融豆价格
* image_url:
* type: string
* description: 商品图片URL
* stock:
* type: integer
* description: 库存数量
* payment_methods:
* type: array
* items:
* type: string
* description: 支付方式列表
* created_at:
* type: string
* format: date-time
* description: 创建时间
*
* AddToCartRequest:
* type: object
* required:
* - product_id
* - quantity
* properties:
* product_id:
* type: integer
* description: 商品ID
* quantity:
* type: integer
* minimum: 1
* description: 商品数量
*
* UpdateCartRequest:
* type: object
* required:
* - quantity
* properties:
* quantity:
* type: integer
* minimum: 1
* description: 商品数量
*/

102
docs/schemas/order.js Normal file
View File

@@ -0,0 +1,102 @@
/**
* @swagger
* components:
* schemas:
* Order:
* type: object
* required:
* - user_id
* - total_amount
* - status
* properties:
* id:
* type: integer
* description: 订单ID
* order_number:
* type: string
* description: 订单号
* user_id:
* type: integer
* description: 用户ID
* total_amount:
* type: number
* description: 订单总金额
* total_points:
* type: integer
* description: 订单总积分
* total_rongdou:
* type: number
* description: 订单总融豆
* status:
* type: string
* description: 订单状态
* enum: [pending, confirmed, shipped, delivered, cancelled]
* payment_status:
* type: string
* description: 支付状态
* enum: [pending, paid, failed, refunded]
* shipping_address:
* type: string
* description: 收货地址
* created_at:
* type: string
* format: date-time
* description: 创建时间
* updated_at:
* type: string
* format: date-time
* description: 更新时间
*
* OrderItem:
* type: object
* properties:
* id:
* type: integer
* description: 订单商品ID
* order_id:
* type: integer
* description: 订单ID
* product_id:
* type: integer
* description: 商品ID
* quantity:
* type: integer
* description: 商品数量
* price:
* type: number
* description: 商品价格
* points_price:
* type: integer
* description: 积分价格
* rongdou_price:
* type: number
* description: 融豆价格
* created_at:
* type: string
* format: date-time
* description: 创建时间
*
* PreOrder:
* type: object
* properties:
* preOrderId:
* type: integer
* description: 预订单ID
* orderNumber:
* type: string
* description: 订单号
* totalAmount:
* type: number
* description: 总金额
* totalPoints:
* type: integer
* description: 所需积分总数
* totalRongdou:
* type: number
* description: 所需融豆总数
* paymentMethods:
* type: array
* items:
* type: string
* description: 去重后的支付方式列表
*/

53
docs/schemas/product.js Normal file
View File

@@ -0,0 +1,53 @@
/**
* @swagger
* components:
* schemas:
* Product:
* type: object
* required:
* - name
* - points_price
* - stock
* properties:
* id:
* type: integer
* description: 商品ID
* name:
* type: string
* description: 商品名称
* category:
* type: string
* description: 商品分类
* points_price:
* type: integer
* description: 积分价格
* rongdou_price:
* type: number
* description: 融豆价格
* stock:
* type: integer
* description: 库存数量
* image_url:
* type: string
* description: 商品图片URL
* description:
* type: string
* description: 商品描述
* status:
* type: string
* description: 商品状态
* enum: [active, inactive]
* payment_methods:
* type: array
* items:
* type: string
* description: 支付方式列表
* created_at:
* type: string
* format: date-time
* description: 创建时间
* updated_at:
* type: string
* format: date-time
* description: 更新时间
*/

104
docs/schemas/user.js Normal file
View File

@@ -0,0 +1,104 @@
/**
* @swagger
* components:
* schemas:
* User:
* type: object
* required:
* - username
* - email
* properties:
* id:
* type: integer
* description: 用户ID
* username:
* type: string
* description: 用户名
* email:
* type: string
* format: email
* description: 邮箱地址
* phone:
* type: string
* description: 手机号码
* points:
* type: integer
* description: 积分余额
* rongdou:
* type: number
* description: 融豆余额
* avatar:
* type: string
* description: 头像URL
* status:
* type: string
* description: 用户状态
* enum: [active, inactive, banned]
* created_at:
* type: string
* format: date-time
* description: 创建时间
* updated_at:
* type: string
* format: date-time
* description: 更新时间
*
* UserProfile:
* type: object
* properties:
* id:
* type: integer
* description: 用户ID
* username:
* type: string
* description: 用户名
* email:
* type: string
* description: 邮箱地址
* phone:
* type: string
* description: 手机号码
* points:
* type: integer
* description: 积分余额
* rongdou:
* type: number
* description: 融豆余额
* avatar:
* type: string
* description: 头像URL
*
* LoginRequest:
* type: object
* required:
* - username
* - password
* properties:
* username:
* type: string
* description: 用户名或邮箱
* password:
* type: string
* description: 密码
*
* RegisterRequest:
* type: object
* required:
* - username
* - email
* - password
* properties:
* username:
* type: string
* description: 用户名
* email:
* type: string
* format: email
* description: 邮箱地址
* password:
* type: string
* description: 密码
* phone:
* type: string
* description: 手机号码
*/