You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pyx_gitkeshe/library_system/文档.md

171 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

书籍租赁系统
前端对接后端接口文档(无 JWT · 纯 Session
---
### 一、通用信息
| 项 | 值 |
| ---------------- | ----------------------------------------- |
| 基地址 | `http://localhost:8877` |
| 认证方式 | CookieSession |
| 统一返回 | `{ code: 200/1, message: "", data: ... }` |
| 白名单(免登录) | `POST /user/login` `POST /user/register` |
---
### 二、用户模块
#### 1. 注册
```
POST /user/register
Content-Type: application/x-www-form-urlencoded
username=xxx&password=xxx
```
成功 → `{ code:200, message:"操作成功" }`
#### 2. 登录
```
POST /user/login
Content-Type: application/x-www-form-urlencoded
username=xxx&password=xxx
```
成功 → `{ code:200, message:"登陆成功!" }`
失败 → `{ code:1, message:"账号或密码错误!" }`
#### 3. 获取当前用户信息
```
GET /user/getinfo
```
返回
```json
{
"username": "张三",
"pic": "http://xxx/avatar.png"
}
```
#### 4. 充值
```
POST /user/recharge
Content-Type: application/x-www-form-urlencoded
money=50
```
返回
```json
{ code:200, message:"成功充值50.0元" }
```
#### 5. 余额 + VIP
```
POST /user/findmoney
```
返回
```json
{ code:200, message:"余额为100.0元 当前VIP等级为2" }
```
#### 6. 借书记录
```
GET /user/findone
```
- 普通用户:单条对象
- 管理员:数组
---
### 三、书籍模块
#### 1. 新增书籍(管理员)
```
POST /api/add
Content-Type: application/json
{
"title":"三体",
"content":"科幻小说",
"url":"http://...jpg",
"state":"草稿",
"money":5.00,
"number":10
}
```
成功 → 返回完整书籍对象
#### 2. 查询全部书籍
```
GET /api/select
```
返回数组
#### 3. 书名查单本
```
GET /api/selectone?title=三体
```
返回单条对象
#### 4. 删除书籍(管理员)
```
POST /user/delete
Content-Type: application/x-www-form-urlencoded
title=三体
```
返回
```json
{ code:200, message:"该书本已删除!" }
```
#### 5. 当前用户已借书籍
```
GET /user/borrow/books
```
返回书籍数组
---
### 四、租借模块
#### 1. 借书
```
POST /borrow/borrowbook
Content-Type: application/x-www-form-urlencoded
title=三体
```
- 余额不足 → `{ code:1, message:"余额不足!" }`
- 成功 → `{ code:200, data:{...} }`
#### 2. 还书
```
POST /borrow/returnbook
Content-Type: application/x-www-form-urlencoded
title=三体
```
返回
```json
{ code:200, data:{..., return_time:"2025-07-25T16:35:00"} }
```
---
### 五、排行模块
#### 1. 本周热租榜
```
GET /api/rank/weekly
```
返回
```json
[
{ "title":"三体", "url":"...", "money":5, "number":12 },
...
]
```
#### 2. 本月热租榜
```
GET /api/rank/monthly
```
结构同上