add database crud operation function to plugin system

This commit is contained in:
zhongqin
2026-05-19 02:20:48 +08:00
parent 493be8f7de
commit 15c6094de7
22 changed files with 2201 additions and 1002 deletions
@@ -1,49 +0,0 @@
[content_type]
name = "Cart Item"
singular = "cart_item"
plural = "cart_items"
table = "cart_items"
description = "购物车项"
implements = ["ownable", "timestampable"]
[fields.user_id]
type = "text"
required = true
label = "用户ID"
[fields.product_id]
type = "text"
required = true
label = "商品ID"
[fields.quantity]
type = "integer"
required = true
min = 1
default = 1
label = "数量"
[[indexes]]
fields = ["user_id", "product_id"]
unique = true
[list_view]
default_sort = "created_at:desc"
columns = ["user_id", "product_id", "quantity", "created_at"]
[api.list]
access = "admin"
cache = true
[api.get]
access = "admin"
cache = true
[api.create]
access = "admin"
[api.update]
access = "admin"
[api.delete]
access = "admin"
@@ -1,79 +0,0 @@
[content_type]
name = "Order"
singular = "order"
plural = "orders"
table = "orders"
description = "订单"
implements = ["ownable", "timestampable"]
[fields.order_no]
type = "text"
required = true
unique = true
max_length = 32
immutable = true
label = "订单号"
[fields.user_id]
type = "text"
required = true
immutable = true
label = "用户ID"
[fields.status]
type = "enum"
enum_values = ["pending", "paid", "shipped", "completed", "cancelled", "refunded"]
default = "pending"
label = "订单状态"
[fields.total_amount]
type = "decimal"
required = true
min = 0
label = "订单总额"
[fields.shipping_address]
type = "json"
label = "收货地址"
[fields.note]
type = "text"
max_length = 500
label = "备注"
[fields.paid_at]
type = "datetime"
label = "支付时间"
[fields.shipped_at]
type = "datetime"
label = "发货时间"
[[indexes]]
fields = ["order_no"]
unique = true
[[indexes]]
fields = ["user_id", "created_at"]
[list_view]
default_sort = "created_at:desc"
columns = ["order_no", "user_id", "status", "total_amount", "created_at"]
[api.list]
access = "admin"
cache = true
filter_auth = 'user_id = @request.auth.id'
[api.get]
access = "admin"
cache = true
[api.create]
access = "admin"
[api.update]
access = "admin"
[api.delete]
access = "admin"
@@ -1,70 +0,0 @@
[content_type]
name = "Order Item"
singular = "order_item"
plural = "order_items"
table = "order_items"
description = "订单项"
implements = ["ownable", "timestampable"]
[fields.order_id]
type = "relation"
relation_type = "many_to_one"
target = "orders"
foreign_key = "order_id"
required = true
immutable = true
label = "订单"
[fields.product_id]
type = "text"
required = true
immutable = true
label = "商品ID"
[fields.product_name]
type = "text"
required = true
max_length = 200
immutable = true
label = "商品名称"
[fields.price]
type = "decimal"
required = true
min = 0
immutable = true
label = "单价"
[fields.quantity]
type = "integer"
required = true
min = 1
immutable = true
label = "数量"
[fields.subtotal]
type = "decimal"
required = true
min = 0
immutable = true
label = "小计"
[[indexes]]
fields = ["order_id"]
[api.list]
access = "admin"
cache = true
[api.get]
access = "admin"
cache = true
[api.create]
access = "admin"
[api.update]
access = "admin"
[api.delete]
access = "admin"
@@ -1,99 +0,0 @@
[content_type]
name = "Product"
singular = "product"
plural = "products"
table = "products"
description = "商品"
implements = ["ownable", "timestampable"]
slug_field = "name"
[fields.name]
type = "text"
required = true
max_length = 200
label = "商品名称"
[fields.slug]
type = "uid"
target_field = "name"
unique = true
label = "URL 标识"
[fields.description]
type = "richtext"
label = "商品描述"
[fields.price]
type = "decimal"
required = true
min = 0
label = "价格"
[fields.compare_at_price]
type = "decimal"
min = 0
label = "划线价"
[fields.stock]
type = "integer"
required = true
min = 0
default = 0
label = "库存"
[fields.sku]
type = "text"
unique = true
max_length = 50
label = "SKU"
[fields.images]
type = "media"
accept = ["image/*"]
max_count = 10
label = "商品图片"
[fields.category]
type = "relation"
relation_type = "many_to_one"
target = "product_categories"
foreign_key = "category_id"
label = "分类"
[fields.featured]
type = "boolean"
default = false
label = "推荐商品"
[fields.weight]
type = "decimal"
min = 0
label = "重量(kg)"
[[indexes]]
fields = ["slug"]
unique = true
[[indexes]]
fields = ["status", "created_at"]
[list_view]
default_sort = "created_at:desc"
columns = ["name", "price", "stock", "status", "featured", "created_at"]
[api.list]
access = "public"
cache = true
[api.get]
access = "public"
cache = true
[api.create]
access = "admin"
[api.update]
access = "admin"
[api.delete]
access = "admin"
@@ -1,68 +0,0 @@
[content_type]
name = "Product Category"
singular = "product_category"
plural = "product_categories"
table = "product_categories"
description = "商品分类"
implements = ["ownable", "timestampable"]
slug_field = "name"
[fields.name]
type = "text"
required = true
max_length = 100
label = "分类名称"
[fields.slug]
type = "uid"
target_field = "name"
unique = true
label = "URL 标识"
[fields.description]
type = "text"
max_length = 500
label = "描述"
[fields.parent]
type = "relation"
relation_type = "many_to_one"
target = "product_categories"
foreign_key = "parent_id"
label = "父分类"
[fields.sort_order]
type = "integer"
default = 0
label = "排序"
[fields.image]
type = "media"
accept = ["image/*"]
max_count = 1
label = "分类图片"
[[indexes]]
fields = ["slug"]
unique = true
[list_view]
default_sort = "sort_order:asc,created_at:desc"
columns = ["name", "slug", "sort_order", "created_at"]
[api.list]
access = "public"
cache = true
[api.get]
access = "public"
cache = true
[api.create]
access = "admin"
[api.update]
access = "admin"
[api.delete]
access = "admin"