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

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

412
go-backend/docs/orders.yaml Normal file
View File

@@ -0,0 +1,412 @@
openapi: 3.0.0
info:
title: 订单管理API
description: 订单管理相关接口文档
version: 1.0.0
paths:
/api/orders:
get:
summary: 获取订单列表
description: 获取系统中的订单列表,支持分页(需要认证)
security:
- bearerAuth: []
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: 创建一个新的订单(需要认证)
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/OrderCreate'
responses:
'200':
description: 成功创建订单
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'400':
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'
/api/orders/{id}:
get:
summary: 获取订单详情
description: 根据订单ID获取订单详细信息需要认证
security:
- bearerAuth: []
parameters:
- name: id
in: path
description: 订单ID
required: true
schema:
type: integer
responses:
'200':
description: 成功返回订单信息
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: 订单未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
summary: 更新订单信息
description: 根据订单ID更新订单信息需要认证
security:
- bearerAuth: []
parameters:
- name: 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'
'400':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: 订单未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
summary: 删除订单
description: 根据订单ID删除订单需要认证
security:
- bearerAuth: []
parameters:
- name: id
in: path
description: 订单ID
required: true
schema:
type: integer
responses:
'200':
description: 成功删除订单
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
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:
error:
type: string
description: 错误信息
required:
- error
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT

View File

@@ -0,0 +1,355 @@
openapi: 3.0.0
info:
title: 支付管理API
description: 支付管理相关接口文档
version: 1.0.0
paths:
/api/payments:
get:
summary: 获取支付列表
description: 获取系统中的支付列表,支持分页(需要认证)
security:
- bearerAuth: []
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: 创建一个新的支付(需要认证)
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PaymentCreate'
responses:
'200':
description: 成功创建支付
content:
application/json:
schema:
$ref: '#/components/schemas/Payment'
'400':
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'
/api/payments/{id}:
get:
summary: 获取支付详情
description: 根据支付ID获取支付详细信息需要认证
security:
- bearerAuth: []
parameters:
- name: id
in: path
description: 支付ID
required: true
schema:
type: integer
responses:
'200':
description: 成功返回支付信息
content:
application/json:
schema:
$ref: '#/components/schemas/Payment'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: 支付未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
summary: 更新支付信息
description: 根据支付ID更新支付信息需要认证
security:
- bearerAuth: []
parameters:
- name: 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'
'400':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: 支付未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
summary: 删除支付
description: 根据支付ID删除支付需要认证
security:
- bearerAuth: []
parameters:
- name: id
in: path
description: 支付ID
required: true
schema:
type: integer
responses:
'200':
description: 成功删除支付
content:
application/json:
schema:
$ref: '#/components/schemas/Payment'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
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
amount:
type: number
format: float
description: 支付金额
payment_type:
type: string
enum: [advance, final]
description: 支付类型
payment_method:
type: string
enum: [alipay, wechat, bank]
description: 支付方式
status:
type: string
enum: [pending, paid, failed, refunded]
description: 支付状态
transaction_id:
type: string
description: 第三方交易ID
paid_at:
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
- payment_no
- order_id
- amount
- payment_type
- payment_method
- status
- created_at
- updated_at
PaymentCreate:
type: object
properties:
order_id:
type: integer
description: 关联订单ID
amount:
type: number
format: float
description: 支付金额
payment_type:
type: string
enum: [advance, final]
description: 支付类型
payment_method:
type: string
enum: [alipay, wechat, bank]
description: 支付方式
status:
type: string
enum: [pending, paid, failed, refunded]
description: 支付状态
transaction_id:
type: string
description: 第三方交易ID
paid_at:
type: string
format: date-time
description: 支付时间
remark:
type: string
description: 备注
required:
- order_id
- amount
- payment_type
- payment_method
PaymentUpdate:
type: object
properties:
order_id:
type: integer
description: 关联订单ID
amount:
type: number
format: float
description: 支付金额
payment_type:
type: string
enum: [advance, final]
description: 支付类型
payment_method:
type: string
enum: [alipay, wechat, bank]
description: 支付方式
status:
type: string
enum: [pending, paid, failed, refunded]
description: 支付状态
transaction_id:
type: string
description: 第三方交易ID
paid_at:
type: string
format: date-time
description: 支付时间
remark:
type: string
description: 备注
Error:
type: object
properties:
error:
type: string
description: 错误信息
required:
- error
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT

280
go-backend/docs/users.yaml Normal file
View File

@@ -0,0 +1,280 @@
openapi: 3.0.0
info:
title: 用户管理API
description: 用户管理相关接口文档
version: 1.0.0
paths:
/api/login:
post:
summary: 用户登录
description: 用户登录并获取JWT令牌
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
username:
type: string
description: 用户名
password:
type: string
description: 密码
required:
- username
- password
responses:
'200':
description: 登录成功,返回访问令牌
content:
application/json:
schema:
type: object
properties:
access_token:
type: string
description: JWT访问令牌
token_type:
type: string
description: 令牌类型
'400':
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'
/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'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/users/{id}:
get:
summary: 获取用户详情
description: 根据用户ID获取用户详细信息
parameters:
- name: 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'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
summary: 更新用户信息
description: 根据用户ID更新用户信息需要认证
security:
- bearerAuth: []
parameters:
- name: 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'
'400':
description: 请求参数验证失败
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: 用户未找到
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: 服务器内部错误
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
summary: 删除用户
description: 根据用户ID删除用户需要认证
security:
- bearerAuth: []
parameters:
- name: id
in: path
description: 用户ID
required: true
schema:
type: integer
responses:
'200':
description: 成功删除用户
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'401':
description: 未授权
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
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:
error:
type: string
description: 错误信息
required:
- error
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT