feat: 添加订单相关字段和自动生成规则,包括订单商品数量和支付状态;更新文档和迁移脚本
This commit is contained in:
@@ -608,8 +608,7 @@ function createOrder(authState, payload) {
|
||||
const collection = $app.findCollectionByNameOrId('tbl_order')
|
||||
const record = new Record(collection)
|
||||
|
||||
record.set('order_id', buildBusinessId('ORDER'))
|
||||
record.set('order_number', normalizeText(payload.order_number) || buildDisplayNumber('ORDER', authState.authRecord, authState.openid))
|
||||
// order_id / order_number are generated by PocketBase native field rules.
|
||||
record.set('order_owner', authState.openid)
|
||||
record.set('order_source', normalizeOrderSource(payload.order_source))
|
||||
record.set('order_status', normalizeOrderStatus(payload.order_status))
|
||||
|
||||
@@ -232,6 +232,74 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseNativeError'
|
||||
/pb/api/batch:
|
||||
post:
|
||||
operationId: postPocketBaseCartBatchUpdate
|
||||
tags: [购物车]
|
||||
summary: 批量更新购物车记录
|
||||
description: |
|
||||
使用 PocketBase 原生 batch 接口批量更新 `tbl_cart` 记录。
|
||||
|
||||
说明:
|
||||
- 这是 PocketBase 原生批处理接口,不是 hooks。
|
||||
- 单次请求可提交多条 `PATCH /api/collections/tbl_cart/records/{recordId}` 子请求。
|
||||
- 每条子请求仍按原生 collection rule 校验权限。
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseCartBatchRequest'
|
||||
example:
|
||||
requests:
|
||||
- method: PATCH|string
|
||||
url: /api/collections/tbl_cart/records/PocketBase记录主键|string
|
||||
headers:
|
||||
Content-Type: application/json|string
|
||||
body:
|
||||
cart_number: 购物车名称或分组号|string
|
||||
cart_product_quantity: 产品数量|integer
|
||||
cart_status: 购物车状态|string
|
||||
cart_at_price: 加入购物车时价格|number
|
||||
cart_remark: 备注|string
|
||||
- method: PATCH|string
|
||||
url: /api/collections/tbl_cart/records/PocketBase记录主键|string
|
||||
headers:
|
||||
Content-Type: application/json|string
|
||||
body:
|
||||
cart_status: 购物车状态|string
|
||||
cart_remark: 备注|string
|
||||
responses:
|
||||
'200':
|
||||
description: 批量处理成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseBatchResponse'
|
||||
'400':
|
||||
description: 批处理参数错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseNativeError'
|
||||
'401':
|
||||
description: token 无效或已过期
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseNativeError'
|
||||
'403':
|
||||
description: 无权访问其中一条或多条记录
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseNativeError'
|
||||
'500':
|
||||
description: 服务端错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseNativeError'
|
||||
components:
|
||||
schemas:
|
||||
PocketBaseNativeError:
|
||||
@@ -397,6 +465,57 @@ components:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/PocketBaseCartRecord'
|
||||
PocketBaseCartBatchItem:
|
||||
type: object
|
||||
required: [method, url, body]
|
||||
properties:
|
||||
method:
|
||||
type: string
|
||||
description: HTTP 方法
|
||||
example: PATCH|string
|
||||
url:
|
||||
type: string
|
||||
description: PocketBase 子请求路径
|
||||
example: /api/collections/tbl_cart/records/PocketBase记录主键|string
|
||||
headers:
|
||||
type: object
|
||||
description: 子请求头
|
||||
additionalProperties:
|
||||
type: string
|
||||
example:
|
||||
Content-Type: application/json|string
|
||||
body:
|
||||
$ref: '#/components/schemas/PocketBaseCartUpdateRequest'
|
||||
PocketBaseCartBatchRequest:
|
||||
type: object
|
||||
required: [requests]
|
||||
properties:
|
||||
requests:
|
||||
type: array
|
||||
description: 批量子请求列表
|
||||
items:
|
||||
$ref: '#/components/schemas/PocketBaseCartBatchItem'
|
||||
PocketBaseBatchResponseItem:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: [integer, string]
|
||||
description: 子请求响应状态码
|
||||
example: 子请求状态码|integer
|
||||
body:
|
||||
type: object
|
||||
description: 子请求响应体
|
||||
additionalProperties: true
|
||||
example:
|
||||
字段名|string: 字段值|string
|
||||
PocketBaseBatchResponse:
|
||||
type: object
|
||||
properties:
|
||||
items:
|
||||
type: array
|
||||
description: 批处理结果列表
|
||||
items:
|
||||
$ref: '#/components/schemas/PocketBaseBatchResponseItem'
|
||||
PocketBaseProductListExpand:
|
||||
type: object
|
||||
description: tbl_product_list 关联展开后的记录对象(示例字段)
|
||||
|
||||
@@ -82,6 +82,9 @@ paths:
|
||||
operationId: postPocketBaseOrderRecord
|
||||
tags: [订单]
|
||||
summary: 创建订单记录
|
||||
description: |
|
||||
`order_id` 与 `order_number` 由 PocketBase 原生字段自动生成。
|
||||
创建请求不应传入这两个字段,响应中返回生成结果。
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
@@ -89,8 +92,6 @@ paths:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PocketBaseOrderCreateRequest'
|
||||
example:
|
||||
order_id: 订单业务ID|string
|
||||
order_number: 订单编号|string
|
||||
order_owner: 订单所有者openid|string
|
||||
order_source: 订单来源|string
|
||||
order_status: 订单状态|string
|
||||
@@ -271,10 +272,10 @@ components:
|
||||
properties:
|
||||
order_id:
|
||||
type: string
|
||||
description: 订单业务ID
|
||||
description: 订单业务ID(PocketBase 原生自动生成)
|
||||
order_number:
|
||||
type: string
|
||||
description: 订单编号
|
||||
description: 订单编号(PocketBase 原生自动生成的 18 位纯数字)
|
||||
order_create:
|
||||
type: string
|
||||
description: 订单创建时间
|
||||
@@ -299,6 +300,12 @@ components:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
description: 订单快照
|
||||
order_product_quantity:
|
||||
type: [number, integer]
|
||||
description: 订单商品总数量(可为空)
|
||||
order_pay_status:
|
||||
type: string
|
||||
description: 订单支付状态
|
||||
order_amount:
|
||||
type: [number, integer]
|
||||
description: 订单金额
|
||||
@@ -315,6 +322,8 @@ components:
|
||||
order_source_id: 来源关联业务ID|string
|
||||
order_snap:
|
||||
字段名|string: 字段值|string
|
||||
order_product_quantity: 订单商品总数量|number
|
||||
order_pay_status: 订单支付状态|string
|
||||
order_amount: 订单金额|number
|
||||
order_remark: 备注|string
|
||||
PocketBaseOrderRecord:
|
||||
@@ -323,12 +332,10 @@ components:
|
||||
- $ref: '#/components/schemas/PocketBaseOrderFields'
|
||||
PocketBaseOrderCreateRequest:
|
||||
type: object
|
||||
required: [order_id, order_number, order_owner, order_source, order_status, order_source_id, order_snap, order_amount]
|
||||
description: |
|
||||
创建订单时无需传入 `order_id`、`order_number`,由 PocketBase 原生字段自动生成。
|
||||
required: [order_owner, order_source, order_status, order_source_id, order_snap, order_amount]
|
||||
properties:
|
||||
order_id:
|
||||
type: string
|
||||
order_number:
|
||||
type: string
|
||||
order_owner:
|
||||
type: string
|
||||
order_source:
|
||||
@@ -345,6 +352,10 @@ components:
|
||||
items:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
order_product_quantity:
|
||||
type: [number, integer]
|
||||
order_pay_status:
|
||||
type: string
|
||||
order_amount:
|
||||
type: [number, integer]
|
||||
order_remark:
|
||||
@@ -370,6 +381,10 @@ components:
|
||||
items:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
order_product_quantity:
|
||||
type: [number, integer]
|
||||
order_pay_status:
|
||||
type: string
|
||||
order_amount:
|
||||
type: [number, integer]
|
||||
order_remark:
|
||||
|
||||
Reference in New Issue
Block a user