2 Commits b8db501cc3 ... 5f79ff54fc

Author SHA1 Message Date
  陈雪 5f79ff54fc ✨ feat(database): 添加店铺相关表结构,包括区域、材料、订单和桌子模型,并更新菜单相关模型以支持反序列化 1 day ago
  陈雪 af4e99a228 ✨ refactor(database): 更新菜单、商品、SKU、订单及区域表结构,确保字段为非空并设置默认值 1 day ago

+ 44 - 44
src-tauri/resources/table_struct.sql

@@ -2,32 +2,32 @@
 CREATE TABLE
     menu_cate (
         id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, -- 主键
-        name TEXT DEFAULT '', -- 分类名称
-        logo TEXT DEFAULT '', -- 分类Logo
+        name TEXT NOT NULL DEFAULT '', -- 分类名称
+        logo TEXT NOT NULL DEFAULT '', -- 分类Logo
         description TEXT, -- 分类描述
-        create_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 创建时间
-        update_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 更新时间
-        sort INTEGER DEFAULT 0, -- 排序
-        status INTEGER DEFAULT 1 -- 状态 (1-Active, 0-Inactive)
+        create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
+        update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
+        sort INTEGER NOT NULL DEFAULT 0, -- 排序
+        status INTEGER NOT NULL DEFAULT 1 -- 状态 (1-Active, 0-Inactive)
     );
 
 -- 创建商品表
 CREATE TABLE
     menu_commodity (
         id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, -- 主键
-        name TEXT DEFAULT '', -- 商品名称
-        cate_id INTEGER DEFAULT 0, -- 分类ID
-        goods_no TEXT DEFAULT '', -- 商品编号
-        is_single_spec INTEGER DEFAULT 1, -- 是否单规格 (1-单规格, 0-多规格)
-        logo TEXT DEFAULT '', -- 商品Logo
-        price REAL DEFAULT 0.00, -- 价格
-        line_price REAL DEFAULT 0.00, -- 商品原价
-        stock INTEGER DEFAULT 0, -- 库存
-        sort INTEGER DEFAULT 0, -- 排序
-        description TEXT DEFAULT '', -- 商品描述
-        create_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 创建时间
-        update_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 更新时间
-        status INTEGER DEFAULT 1, -- 状态 (1-Active, 0-Inactive),
+        name TEXT NOT NULL DEFAULT '', -- 商品名称
+        cate_id INTEGER NOT NULL DEFAULT 0, -- 分类ID
+        goods_no TEXT NOT NULL DEFAULT '', -- 商品编号
+        is_single_spec INTEGER NOT NULL DEFAULT 1, -- 是否单规格 (1-单规格, 0-多规格)
+        logo TEXT NOT NULL DEFAULT '', -- 商品Logo
+        price REAL NOT NULL DEFAULT 0.00, -- 价格
+        line_price REAL NOT NULL DEFAULT 0.00, -- 商品原价
+        stock INTEGER NOT NULL DEFAULT 0, -- 库存
+        sort INTEGER NOT NULL DEFAULT 0, -- 排序
+        description TEXT NOT NULL DEFAULT '', -- 商品描述
+        create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
+        update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
+        status INTEGER NOT NULL DEFAULT 1, -- 状态 (1-Active, 0-Inactive),
         FOREIGN KEY (cate_id) REFERENCES menu_cate (id)
     );
 
@@ -35,13 +35,13 @@ CREATE TABLE
 CREATE TABLE
     menu_sku (
         id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, -- 主键
-        sku_no TEXT DEFAULT '', -- SKU编号
-        logo TEXT DEFAULT '', -- SKU Logo
+        sku_no TEXT NOT NULL DEFAULT '', -- SKU编号
+        logo TEXT NOT NULL DEFAULT '', -- SKU Logo
         goods_id INTEGER NOT NULL DEFAULT 0, -- 商品ID
         stock INTEGER NOT NULL DEFAULT 0, -- 库存
         price REAL NOT NULL DEFAULT 0.00, -- 价格
         line_price REAL NOT NULL DEFAULT 0.00, -- 商品原价
-        status INTEGER DEFAULT 1, -- 状态 (1-Active, 0-Inactive),
+        status INTEGER NOT NULL DEFAULT 1, -- 状态 (1-Active, 0-Inactive),
         FOREIGN KEY (goods_id) REFERENCES menu_commodity (id)
     );
 
@@ -52,7 +52,7 @@ CREATE TABLE
         goods_id INTEGER NOT NULL DEFAULT 0, -- 商品ID
         name TEXT NOT NULL DEFAULT '', -- 规格名称
         value TEXT NOT NULL DEFAULT '', -- 规格值
-        status INTEGER DEFAULT 1, -- 状态 (1-Active, 0-Inactive),
+        status INTEGER NOT NULL DEFAULT 1, -- 状态 (1-Active, 0-Inactive),
         FOREIGN KEY (goods_id) REFERENCES menu_commodity (id)
     );
 
@@ -73,19 +73,19 @@ CREATE TABLE
         order_sn TEXT NOT NULL DEFAULT '', -- 订单号
         table_id INTEGER NOT NULL, -- 所属桌码ID
         pay_type INTEGER NOT NULL DEFAULT 0, -- 支付方式 (1-现金, 0-Paypal)
-        amount REAL DEFAULT 0.00, -- 订单金额
-        pay_amount REAL DEFAULT 0.00, -- 支付金额
-        discount REAL DEFAULT 0.00, -- 折扣金额
-        param TEXT DEFAULT '', -- 订单参数
+        amount REAL NOT NULL DEFAULT 0.00, -- 订单金额
+        pay_amount REAL NOT NULL DEFAULT 0.00, -- 支付金额
+        discount REAL NOT NULL DEFAULT 0.00, -- 折扣金额
+        param TEXT NOT NULL DEFAULT '', -- 订单参数
         service_fee REAL DEFAULT NULL, -- 服务费
-        remark TEXT DEFAULT '', -- 用户备注
+        remark TEXT NOT NULL DEFAULT '', -- 用户备注
         create_time DATETIME DEFAULT NULL, -- 创建时间
         update_time DATETIME DEFAULT NULL, -- 更新时间
-        status TEXT DEFAULT 'A', -- 订单状态
+        status TEXT NOT NULL DEFAULT 'A', -- 订单状态
         pay_time DATETIME DEFAULT NULL, -- 支付时间
-        pay_status INTEGER DEFAULT 1, -- 支付状态
-        settle_status INTEGER DEFAULT 1, -- 结算状态
-        goods TEXT DEFAULT '{}' -- 订单商品信息
+        pay_status INTEGER NOT NULL DEFAULT 1, -- 支付状态
+        settle_status INTEGER NOT NULL DEFAULT 1, -- 结算状态
+        goods TEXT NOT NULL DEFAULT '{}' -- 订单商品信息
     );
 
 -- 创建店铺材料表信息
@@ -100,10 +100,10 @@ CREATE TABLE
         shelf_life INTEGER NOT NULL DEFAULT 0, -- 保质期
         unit TEXT NOT NULL, -- 单位
         img TEXT NOT NULL, -- 材料文件/图片id
-        purchase_period INTEGER DEFAULT 0, -- 采购期数
-        create_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 创建时间
-        update_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 更新时间
-        status INTEGER DEFAULT 1 -- 状态0下架1上架
+        purchase_period INTEGER NOT NULL DEFAULT 0, -- 采购期数
+        create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
+        update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
+        status INTEGER NOT NULL DEFAULT 1 -- 状态0下架1上架
     );
 
 -- 店铺区域表
@@ -111,10 +111,10 @@ CREATE TABLE
     store_area (
         id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, -- 区域id
         name TEXT NOT NULL, -- 区域名称
-        description TEXT DEFAULT '', -- 区域描述
-        create_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 创建时间
-        update_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 更新时间
-        status INTEGER DEFAULT 1 -- 状态 (1-有效, 0-无效)
+        description TEXT NOT NULL DEFAULT '', -- 区域描述
+        create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
+        update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
+        status INTEGER NOT NULL DEFAULT 1 -- 状态 (1-有效, 0-无效)
     );
 
 -- 店铺座位表
@@ -123,10 +123,10 @@ CREATE TABLE
         id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, -- 桌子id
         area_id INTEGER NOT NULL, -- 所属区域id
         table_no TEXT NOT NULL, -- 桌号
-        capacity INTEGER DEFAULT 0, -- 座位数
-        create_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 创建时间
-        update_time DATETIME DEFAULT CURRENT_TIMESTAMP, -- 更新时间
-        status INTEGER DEFAULT 1, -- 状态 (1-有效, 0-无效)
+        capacity INTEGER NOT NULL DEFAULT 0, -- 座位数
+        create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
+        update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
+        status INTEGER NOT NULL DEFAULT 1, -- 状态 (1-有效, 0-无效)
         FOREIGN KEY (area_id) REFERENCES store_area (id)
     );
 

+ 3 - 6
src-tauri/src/models/menu_cate.rs

@@ -1,9 +1,9 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 use sea_orm::entity::prelude::*;
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
 
-#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
 #[sea_orm(table_name = "menu_cate")]
 pub struct Model {
     #[sea_orm(primary_key)]
@@ -13,16 +13,13 @@ pub struct Model {
     #[sea_orm(column_type = "Text", nullable)]
     pub logo: Option<String>,
     #[sea_orm(column_type = "Text", nullable)]
-    pub local_logo: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
     pub description: Option<String>,
     #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
     pub create_time: Option<String>,
     #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
     pub update_time: Option<String>,
     pub sort: Option<i32>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub status: Option<String>,
+    pub status: Option<i32>,
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

+ 4 - 23
src-tauri/src/models/menu_commodity.rs

@@ -1,40 +1,24 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 use sea_orm::entity::prelude::*;
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
 
-#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
 #[sea_orm(table_name = "menu_commodity")]
 pub struct Model {
     #[sea_orm(primary_key)]
     pub id: i32,
     #[sea_orm(column_type = "Text", nullable)]
-    pub r#type: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
     pub name: Option<String>,
     pub cate_id: Option<i32>,
     #[sea_orm(column_type = "Text", nullable)]
     pub goods_no: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub is_single_spec: Option<String>,
+    pub is_single_spec: Option<i32>,
     #[sea_orm(column_type = "Text", nullable)]
     pub logo: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub images: Option<String>,
     pub price: Option<Decimal>,
     pub line_price: Option<Decimal>,
     pub stock: Option<i32>,
-    pub weight: Option<Decimal>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub coupon_ids: Option<String>,
-    pub service_time: Option<i32>,
-    pub init_sale: Option<i32>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub sale_point: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub can_use_point: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub is_member_discount: Option<String>,
     pub sort: Option<i32>,
     #[sea_orm(column_type = "Text", nullable)]
     pub description: Option<String>,
@@ -42,10 +26,7 @@ pub struct Model {
     pub create_time: Option<String>,
     #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
     pub update_time: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub operator: Option<String>,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub status: Option<String>,
+    pub status: Option<i32>,
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

+ 3 - 4
src-tauri/src/models/menu_sku.rs

@@ -1,8 +1,9 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 use sea_orm::entity::prelude::*;
+use serde::{Deserialize, Serialize};
 
-#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Deserialize, Serialize)]
 #[sea_orm(table_name = "menu_sku")]
 pub struct Model {
     #[sea_orm(primary_key)]
@@ -15,9 +16,7 @@ pub struct Model {
     pub stock: i32,
     pub price: Decimal,
     pub line_price: Decimal,
-    pub weight: Option<Decimal>,
-    #[sea_orm(column_type = "Text")]
-    pub status: String,
+    pub status: Option<i32>,
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

+ 3 - 3
src-tauri/src/models/menu_sku_spec.rs

@@ -1,9 +1,9 @@
 //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
 
 use sea_orm::entity::prelude::*;
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
 
-#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
 #[sea_orm(table_name = "menu_sku_spec")]
 pub struct Model {
     #[sea_orm(primary_key, auto_increment = false)]
@@ -12,7 +12,7 @@ pub struct Model {
     pub spec_id: i32,
 }
 
-#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, Serialize)]
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
 pub enum Relation {
     #[sea_orm(
         belongs_to = "super::menu_sku::Entity",

+ 1 - 2
src-tauri/src/models/menu_spec.rs

@@ -13,8 +13,7 @@ pub struct Model {
     pub name: String,
     #[sea_orm(column_type = "Text")]
     pub value: String,
-    #[sea_orm(column_type = "Text", nullable)]
-    pub status: Option<String>,
+    pub status: Option<i32>,
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

+ 4 - 0
src-tauri/src/models/mod.rs

@@ -7,3 +7,7 @@ pub mod menu_commodity;
 pub mod menu_sku;
 pub mod menu_sku_spec;
 pub mod menu_spec;
+pub mod store_area;
+pub mod store_material;
+pub mod store_order;
+pub mod store_table;

+ 7 - 3
src-tauri/src/models/prelude.rs

@@ -2,6 +2,10 @@
 
 pub use super::menu_cate::Entity as MenuCate;
 pub use super::menu_commodity::Entity as MenuCommodity;
-// pub use super::menu_sku::Entity as MenuSku;
-// pub use super::menu_sku_spec::Entity as MenuSkuSpec;
-// pub use super::menu_spec::Entity as MenuSpec;
+pub use super::menu_sku::Entity as MenuSku;
+pub use super::menu_sku_spec::Entity as MenuSkuSpec;
+pub use super::menu_spec::Entity as MenuSpec;
+pub use super::store_area::Entity as StoreArea;
+pub use super::store_material::Entity as StoreMaterial;
+pub use super::store_order::Entity as StoreOrder;
+pub use super::store_table::Entity as StoreTable;

+ 34 - 0
src-tauri/src/models/store_area.rs

@@ -0,0 +1,34 @@
+//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
+
+use sea_orm::entity::prelude::*;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
+#[sea_orm(table_name = "store_area")]
+pub struct Model {
+    #[sea_orm(primary_key)]
+    pub id: i32,
+    #[sea_orm(column_type = "Text")]
+    pub name: String,
+    #[sea_orm(column_type = "Text", nullable)]
+    pub description: Option<String>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub create_time: Option<String>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub update_time: Option<String>,
+    pub status: Option<i32>,
+}
+
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+pub enum Relation {
+    #[sea_orm(has_many = "super::store_table::Entity")]
+    StoreTable,
+}
+
+impl Related<super::store_table::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::StoreTable.def()
+    }
+}
+
+impl ActiveModelBehavior for ActiveModel {}

+ 36 - 0
src-tauri/src/models/store_material.rs

@@ -0,0 +1,36 @@
+//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
+
+use sea_orm::entity::prelude::*;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
+#[sea_orm(table_name = "store_material")]
+pub struct Model {
+    #[sea_orm(primary_key)]
+    pub id: i32,
+    #[sea_orm(column_type = "Text")]
+    pub material_no: String,
+    #[sea_orm(column_type = "Text")]
+    pub material_type: String,
+    #[sea_orm(column_type = "Text")]
+    pub name: String,
+    #[sea_orm(column_type = "Text")]
+    pub specification: String,
+    pub inventory: i32,
+    pub shelf_life: i32,
+    #[sea_orm(column_type = "Text")]
+    pub unit: String,
+    #[sea_orm(column_type = "Text")]
+    pub img: String,
+    pub purchase_period: Option<i32>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub create_time: Option<String>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub update_time: Option<String>,
+    pub status: Option<i32>,
+}
+
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+pub enum Relation {}
+
+impl ActiveModelBehavior for ActiveModel {}

+ 40 - 0
src-tauri/src/models/store_order.rs

@@ -0,0 +1,40 @@
+//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
+
+use sea_orm::entity::prelude::*;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
+#[sea_orm(table_name = "store_order")]
+pub struct Model {
+    #[sea_orm(primary_key)]
+    pub id: i32,
+    #[sea_orm(column_type = "Text")]
+    pub order_sn: String,
+    pub table_id: i32,
+    pub pay_type: i32,
+    pub amount: Option<Decimal>,
+    pub pay_amount: Option<Decimal>,
+    pub discount: Option<Decimal>,
+    #[sea_orm(column_type = "Text", nullable)]
+    pub param: Option<String>,
+    pub service_fee: Option<Decimal>,
+    #[sea_orm(column_type = "Text", nullable)]
+    pub remark: Option<String>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub create_time: Option<String>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub update_time: Option<String>,
+    #[sea_orm(column_type = "Text", nullable)]
+    pub status: Option<String>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub pay_time: Option<String>,
+    pub pay_status: Option<i32>,
+    pub settle_status: Option<i32>,
+    #[sea_orm(column_type = "Text", nullable)]
+    pub goods: Option<String>,
+}
+
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+pub enum Relation {}
+
+impl ActiveModelBehavior for ActiveModel {}

+ 40 - 0
src-tauri/src/models/store_table.rs

@@ -0,0 +1,40 @@
+//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
+
+use sea_orm::entity::prelude::*;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
+#[sea_orm(table_name = "store_table")]
+pub struct Model {
+    #[sea_orm(primary_key)]
+    pub id: i32,
+    pub area_id: i32,
+    #[sea_orm(column_type = "Text")]
+    pub table_no: String,
+    pub capacity: Option<i32>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub create_time: Option<String>,
+    #[sea_orm(column_type = "custom(\"DATETIME\")", nullable)]
+    pub update_time: Option<String>,
+    pub status: Option<i32>,
+}
+
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+pub enum Relation {
+    #[sea_orm(
+        belongs_to = "super::store_area::Entity",
+        from = "Column::AreaId",
+        to = "super::store_area::Column::Id",
+        on_update = "NoAction",
+        on_delete = "NoAction"
+    )]
+    StoreArea,
+}
+
+impl Related<super::store_area::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::StoreArea.def()
+    }
+}
+
+impl ActiveModelBehavior for ActiveModel {}