增加微信支付,商城逻辑,公告

This commit is contained in:
2025-09-05 16:48:53 +08:00
parent e5ace37c68
commit 8530e97ab6
38 changed files with 6430 additions and 1688 deletions

View File

@@ -11,10 +11,12 @@ docs/
│ ├── product.js # 商品相关数据模型
│ ├── order.js # 订单相关数据模型
│ ├── user.js # 用户相关数据模型
── cart.js # 购物车相关数据模型
── cart.js # 购物车相关数据模型
│ └── announcement.js # 通知公告相关数据模型
└── apis/ # API 接口定义
├── products.js # 商品相关 API
── orders.js # 订单相关 API
── orders.js # 订单相关 API
└── announcements.js # 通知公告相关 API
```
## 优势

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: 服务器错误
*/

View File

@@ -7,149 +7,12 @@
/**
* @swagger
* /orders/create-from-cart:
* post:
* summary: 从购物车创建预订单
* tags: [Orders]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - cartIds
* properties:
* cartIds:
* type: array
* items:
* type: integer
* description: 购物车商品ID数组
* responses:
* 200:
* description: 成功创建预订单
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* $ref: '#/components/schemas/PreOrder'
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
*/
/**
* @swagger
* /orders/pre-order/{id}:
* /api/orders:
* get:
* summary: 获取订单详情
* tags: [Orders]
* 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:
* preOrder:
* $ref: '#/components/schemas/PreOrder'
* items:
* type: array
* items:
* type: object
* properties:
* product_id:
* type: integer
* product_name:
* type: string
* quantity:
* type: integer
* points_price:
* type: integer
* rongdou_price:
* type: number
* image_url:
* type: string
* 404:
* description: 预订单不存在
*/
/**
* @swagger
* /orders/confirm:
* post:
* summary: 确认下单
* tags: [Orders]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - preOrderId
* - shippingAddress
* properties:
* preOrderId:
* type: integer
* description: 预订单ID
* shippingAddress:
* type: string
* description: 收货地址
* responses:
* 200:
* description: 订单确认成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* data:
* type: object
* properties:
* orderId:
* type: integer
* orderNumber:
* type: string
* 400:
* description: 请求参数错误或余额不足
* 404:
* description: 预订单不存在
*/
/**
* @swagger
* /orders:
* get:
* summary: 获取用户订单列表
* summary: 获取订单列表
* tags: [Orders]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: page
@@ -164,11 +27,37 @@
* 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
* enum: [pending, confirmed, shipped, delivered, cancelled]
* description: 订单状态筛选
* description: 订单状态
* - in: query
* name: startDate
* schema:
* type: string
* format: date
* description: 开始日期
* - in: query
* name: endDate
* schema:
* type: string
* format: date
* description: 结束日期
* responses:
* 200:
* description: 成功获取订单列表
@@ -197,14 +86,162 @@
* type: integer
* pages:
* type: integer
* 401:
* description: 未授权
* 500:
* description: 服务器错误
*/
/**
* @swagger
* /orders/{id}:
* get:
* summary: 获取订单详情
* /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
@@ -227,10 +264,10 @@
* properties:
* order:
* $ref: '#/components/schemas/Order'
* items:
* type: array
* items:
* $ref: '#/components/schemas/OrderItem'
* 401:
* description: 未授权
* 404:
* 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: "公告不存在"
*/