重构后端服务架构并优化前端错误处理

This commit is contained in:
ylweng
2025-09-12 01:21:43 +08:00
parent d550a8ed51
commit 3a48a67757
53 changed files with 3925 additions and 0 deletions

396
docs/api/orders.yaml Normal file
View File

@@ -0,0 +1,396 @@
openapi: 3.0.0
info:
title: 订单管理API
description: 订单管理相关接口文档
version: 1.0.0
paths:
/api/orders/:
get:
summary: 获取订单列表
description: 获取系统中的订单列表,支持分页
parameters:
- name: skip
in: query
description: 跳过的记录数
required: false
schema:
type: integer
default: 0
- name: limit
in: query
description: 返回的记录数
required: false
schema:
type: integer
default: 100
responses:
'200':
description: 成功返回订单列表
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Order'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: 创建订单
description: 创建一个新的订单
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/OrderCreate'
responses:
'200':
description: 成功创建订单
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'422':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/orders/{order_id}:
get:
summary: 获取订单详情
description: 根据订单ID获取订单详细信息
parameters:
- name: order_id
in: path
description: 订单ID
required: true
schema:
type: integer
responses:
'200':
description: 成功返回订单信息
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'404':
description: 订单未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
summary: 更新订单信息
description: 根据订单ID更新订单信息
parameters:
- name: order_id
in: path
description: 订单ID
required: true
schema:
type: integer
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/OrderUpdate'
responses:
'200':
description: 成功更新订单信息
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'404':
description: 订单未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'422':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
summary: 删除订单
description: 根据订单ID删除订单
parameters:
- name: order_id
in: path
description: 订单ID
required: true
schema:
type: integer
responses:
'200':
description: 成功删除订单
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'404':
description: 订单未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Order:
type: object
properties:
id:
type: integer
description: 订单ID
order_no:
type: string
description: 订单号
buyer_id:
type: integer
description: 买家ID
seller_id:
type: integer
description: 卖家ID
variety_type:
type: string
description: 品种类型
weight_range:
type: string
description: 重量范围
weight_actual:
type: number
format: float
description: 实际重量
price_per_unit:
type: number
format: float
description: 单价
total_price:
type: number
format: float
description: 总价
advance_payment:
type: number
format: float
description: 预付款
final_payment:
type: number
format: float
description: 尾款
status:
type: string
enum: [pending, confirmed, processing, shipped, delivered, cancelled, completed]
description: 订单状态
delivery_address:
type: string
description: 收货地址
delivery_time:
type: string
format: date-time
description: 交付时间
remark:
type: string
description: 备注
created_at:
type: string
format: date-time
description: 创建时间
updated_at:
type: string
format: date-time
description: 更新时间
required:
- id
- order_no
- buyer_id
- seller_id
- variety_type
- weight_range
- price_per_unit
- total_price
- advance_payment
- final_payment
- status
- created_at
- updated_at
OrderCreate:
type: object
properties:
buyer_id:
type: integer
description: 买家ID
seller_id:
type: integer
description: 卖家ID
variety_type:
type: string
description: 品种类型
weight_range:
type: string
description: 重量范围
weight_actual:
type: number
format: float
description: 实际重量
price_per_unit:
type: number
format: float
description: 单价
total_price:
type: number
format: float
description: 总价
advance_payment:
type: number
format: float
description: 预付款
final_payment:
type: number
format: float
description: 尾款
status:
type: string
enum: [pending, confirmed, processing, shipped, delivered, cancelled, completed]
description: 订单状态
delivery_address:
type: string
description: 收货地址
delivery_time:
type: string
format: date-time
description: 交付时间
remark:
type: string
description: 备注
required:
- buyer_id
- seller_id
- variety_type
- weight_range
- price_per_unit
- total_price
OrderUpdate:
type: object
properties:
buyer_id:
type: integer
description: 买家ID
seller_id:
type: integer
description: 卖家ID
variety_type:
type: string
description: 品种类型
weight_range:
type: string
description: 重量范围
weight_actual:
type: number
format: float
description: 实际重量
price_per_unit:
type: number
format: float
description: 单价
total_price:
type: number
format: float
description: 总价
advance_payment:
type: number
format: float
description: 预付款
final_payment:
type: number
format: float
description: 尾款
status:
type: string
enum: [pending, confirmed, processing, shipped, delivered, cancelled, completed]
description: 订单状态
delivery_address:
type: string
description: 收货地址
delivery_time:
type: string
format: date-time
description: 交付时间
remark:
type: string
description: 备注
Error:
type: object
properties:
detail:
type: string
description: 错误信息
required:
- detail

329
docs/api/payments.yaml Normal file
View File

@@ -0,0 +1,329 @@
openapi: 3.0.0
info:
title: 支付管理API
description: 支付管理相关接口文档
version: 1.0.0
paths:
/api/payments/:
get:
summary: 获取支付列表
description: 获取系统中的支付列表,支持分页
parameters:
- name: skip
in: query
description: 跳过的记录数
required: false
schema:
type: integer
default: 0
- name: limit
in: query
description: 返回的记录数
required: false
schema:
type: integer
default: 100
responses:
'200':
description: 成功返回支付列表
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Payment'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: 创建支付
description: 创建一个新的支付记录
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PaymentCreate'
responses:
'200':
description: 成功创建支付
content:
application/json:
schema:
$ref: '#/components/schemas/Payment'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'422':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/payments/{payment_id}:
get:
summary: 获取支付详情
description: 根据支付ID获取支付详细信息
parameters:
- name: payment_id
in: path
description: 支付ID
required: true
schema:
type: integer
responses:
'200':
description: 成功返回支付信息
content:
application/json:
schema:
$ref: '#/components/schemas/Payment'
'404':
description: 支付未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
summary: 更新支付信息
description: 根据支付ID更新支付信息
parameters:
- name: payment_id
in: path
description: 支付ID
required: true
schema:
type: integer
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PaymentUpdate'
responses:
'200':
description: 成功更新支付信息
content:
application/json:
schema:
$ref: '#/components/schemas/Payment'
'404':
description: 支付未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'422':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
summary: 删除支付
description: 根据支付ID删除支付
parameters:
- name: payment_id
in: path
description: 支付ID
required: true
schema:
type: integer
responses:
'200':
description: 成功删除支付
content:
application/json:
schema:
$ref: '#/components/schemas/Payment'
'404':
description: 支付未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Payment:
type: object
properties:
id:
type: integer
description: 支付ID
payment_no:
type: string
description: 支付编号
order_id:
type: integer
description: 订单ID
user_id:
type: integer
description: 用户ID
amount:
type: number
format: float
description: 支付金额
payment_type:
type: string
enum: [advance, final]
description: 支付类型
payment_method:
type: string
enum: [wechat, alipay, bank]
description: 支付方式
status:
type: string
enum: [pending, success, failed, refunded]
description: 支付状态
transaction_id:
type: string
description: 交易ID
created_at:
type: string
format: date-time
description: 创建时间
updated_at:
type: string
format: date-time
description: 更新时间
required:
- id
- payment_no
- order_id
- user_id
- amount
- payment_type
- payment_method
- status
- created_at
- updated_at
PaymentCreate:
type: object
properties:
order_id:
type: integer
description: 订单ID
user_id:
type: integer
description: 用户ID
amount:
type: number
format: float
description: 支付金额
payment_type:
type: string
enum: [advance, final]
description: 支付类型
payment_method:
type: string
enum: [wechat, alipay, bank]
description: 支付方式
status:
type: string
enum: [pending, success, failed, refunded]
description: 支付状态
transaction_id:
type: string
description: 交易ID
required:
- order_id
- user_id
- amount
- payment_type
- payment_method
PaymentUpdate:
type: object
properties:
order_id:
type: integer
description: 订单ID
user_id:
type: integer
description: 用户ID
amount:
type: number
format: float
description: 支付金额
payment_type:
type: string
enum: [advance, final]
description: 支付类型
payment_method:
type: string
enum: [wechat, alipay, bank]
description: 支付方式
status:
type: string
enum: [pending, success, failed, refunded]
description: 支付状态
transaction_id:
type: string
description: 交易ID
Error:
type: object
properties:
detail:
type: string
description: 错误信息
required:
- detail

229
docs/api/users.yaml Normal file
View File

@@ -0,0 +1,229 @@
openapi: 3.0.0
info:
title: 用户管理API
description: 用户管理相关接口文档
version: 1.0.0
paths:
/api/users/:
get:
summary: 获取用户列表
description: 获取系统中的用户列表,支持分页
parameters:
- name: skip
in: query
description: 跳过的记录数
required: false
schema:
type: integer
default: 0
- name: limit
in: query
description: 返回的记录数
required: false
schema:
type: integer
default: 100
responses:
'200':
description: 成功返回用户列表
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/users/{user_id}:
get:
summary: 获取用户详情
description: 根据用户ID获取用户详细信息
parameters:
- name: user_id
in: path
description: 用户ID
required: true
schema:
type: integer
responses:
'200':
description: 成功返回用户信息
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: 用户未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
summary: 更新用户信息
description: 根据用户ID更新用户信息
parameters:
- name: user_id
in: path
description: 用户ID
required: true
schema:
type: integer
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserUpdate'
responses:
'200':
description: 成功更新用户信息
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: 用户未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'422':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
summary: 删除用户
description: 根据用户ID删除用户
parameters:
- name: user_id
in: path
description: 用户ID
required: true
schema:
type: integer
responses:
'200':
description: 成功删除用户
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: 用户未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
User:
type: object
properties:
id:
type: integer
description: 用户ID
uuid:
type: string
description: 用户UUID
username:
type: string
description: 用户名
user_type:
type: string
enum: [client, supplier, driver, staff, admin]
description: 用户类型
status:
type: string
enum: [active, inactive, locked]
description: 用户状态
created_at:
type: string
format: date-time
description: 创建时间
updated_at:
type: string
format: date-time
description: 更新时间
required:
- id
- uuid
- username
- user_type
- status
- created_at
- updated_at
UserUpdate:
type: object
properties:
username:
type: string
description: 用户名
user_type:
type: string
enum: [client, supplier, driver, staff, admin]
description: 用户类型
status:
type: string
enum: [active, inactive, locked]
description: 用户状态
Error:
type: object
properties:
detail:
type: string
description: 错误信息
required:
- detail