This commit is contained in:
浅念
2026-08-27 16:11:49 +08:00
commit 2d8ef3d7bb
104 changed files with 20196 additions and 0 deletions
@@ -0,0 +1,83 @@
-- CreateTable
CREATE TABLE `customers` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`customer_id` VARCHAR(64) NOT NULL,
`name` VARCHAR(128) NULL,
`country` VARCHAR(64) NULL,
`email` VARCHAR(128) NULL,
`company` VARCHAR(255) NULL,
`register_time` DATETIME(3) NULL,
`avatar_url` VARCHAR(512) NULL,
`buyer_tags` VARCHAR(255) NULL,
`buyer_features` VARCHAR(255) NULL,
`behavior_product_views` INTEGER NULL,
`behavior_valid_inquiries` INTEGER NULL,
`behavior_valid_rfq` INTEGER NULL,
`behavior_login_days` INTEGER NULL,
`behavior_spam_inquiries` INTEGER NULL,
`behavior_top_industry` VARCHAR(255) NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
UNIQUE INDEX `customers_customer_id_key`(`customer_id`),
INDEX `customers_country_idx`(`country`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `inquiries` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`inquiry_id` VARCHAR(32) NOT NULL,
`customer_id` VARCHAR(64) NULL,
`manager` VARCHAR(128) NULL,
`create_time` DATETIME(3) NOT NULL,
`update_time` DATETIME(3) NOT NULL,
`status` VARCHAR(64) NULL,
`msg_preview` VARCHAR(512) NULL,
`is_flagged` BOOLEAN NOT NULL DEFAULT false,
`messages_count` INTEGER NOT NULL DEFAULT 0,
`last_send_time` DATETIME(3) NULL,
`has_failed_batches` BOOLEAN NOT NULL DEFAULT false,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
UNIQUE INDEX `inquiries_inquiry_id_key`(`inquiry_id`),
INDEX `inquiries_customer_id_idx`(`customer_id`),
INDEX `inquiries_manager_idx`(`manager`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `chat_messages` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`message_id` VARCHAR(64) NOT NULL,
`inquiry_id` VARCHAR(32) NOT NULL,
`sender` VARCHAR(128) NULL,
`direction` ENUM('incoming', 'outgoing', 'system') NOT NULL,
`send_time` DATETIME(3) NOT NULL,
`content` MEDIUMTEXT NOT NULL,
`translation` TEXT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `chat_messages_message_id_key`(`message_id`),
INDEX `chat_messages_inquiry_id_send_time_message_id_idx`(`inquiry_id`, `send_time`, `message_id`),
INDEX `chat_messages_inquiry_id_idx`(`inquiry_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `users` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(191) NOT NULL,
`password_hash` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `users_username_key`(`username`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `inquiries` ADD CONSTRAINT `inquiries_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`customer_id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `chat_messages` ADD CONSTRAINT `chat_messages_inquiry_id_fkey` FOREIGN KEY (`inquiry_id`) REFERENCES `inquiries`(`inquiry_id`) ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -0,0 +1,2 @@
-- AlterTable: 客户行为新增「被加为黑名单数」(对应 alibaba 详情页可见字段)
ALTER TABLE `customers` ADD COLUMN `behavior_blacklist` INTEGER NULL;
@@ -0,0 +1,2 @@
-- AlterTable: 客户「最近询盘产品」图片 URL 列表(JSON 字符串)
ALTER TABLE `customers` ADD COLUMN `recent_products_images` TEXT NULL;
@@ -0,0 +1,3 @@
-- AlterTable: 询盘新增「该会话所有询盘号+创建时间」(allInquiries,JSON 字符串)
-- 用于「一会话多询盘」合并:同 secTradeId 只存 1 条,all_inquiries 记录该会话全部询盘。
ALTER TABLE `inquiries` ADD COLUMN `all_inquiries` TEXT NULL;
@@ -0,0 +1,2 @@
-- AlterTable: 客户手机号(alibaba 详情展开后可见的「手机」字段,部分客户有)
ALTER TABLE `customers` ADD COLUMN `phone` VARCHAR(64) NULL;
@@ -0,0 +1,4 @@
-- 店内行为:询盘产品名 + 数量 + 浏览产品(图/链接/ID)
ALTER TABLE `customers` ADD COLUMN `store_inquiry_product` VARCHAR(512) NULL;
ALTER TABLE `customers` ADD COLUMN `store_inquiry_qty` VARCHAR(32) NULL;
ALTER TABLE `customers` ADD COLUMN `store_visit_products` TEXT NULL;
@@ -0,0 +1,5 @@
-- 客户基本信息扩展(折叠面板展开后的字段):座机/商业类型/销售平台/公司官网
ALTER TABLE `customers` ADD COLUMN `landline` VARCHAR(32) NULL;
ALTER TABLE `customers` ADD COLUMN `business_type` VARCHAR(128) NULL;
ALTER TABLE `customers` ADD COLUMN `sales_platform` VARCHAR(255) NULL;
ALTER TABLE `customers` ADD COLUMN `website` VARCHAR(512) NULL;
@@ -0,0 +1,3 @@
-- 加宽 customer_id(原 VarChar(64) 放不下 sec_ 兜底的 secTradeId 会话标识)
ALTER TABLE `customers` MODIFY COLUMN `customer_id` VARCHAR(256) NOT NULL;
ALTER TABLE `inquiries` MODIFY COLUMN `customer_id` VARCHAR(256);
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "mysql"
+99
View File
@@ -0,0 +1,99 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
enum Direction {
incoming
outgoing
system
}
model Customer {
id BigInt @id @default(autoincrement())
customerId String @unique @map("customer_id") @db.VarChar(256)
name String? @db.VarChar(128)
country String? @db.VarChar(64)
email String? @db.VarChar(128)
phone String? @db.VarChar(64)
company String? @db.VarChar(255)
registerTime DateTime? @map("register_time")
avatarUrl String? @map("avatar_url") @db.VarChar(512)
buyerTags String? @map("buyer_tags") @db.VarChar(255)
buyerFeatures String? @map("buyer_features") @db.VarChar(255)
bProductViews Int? @map("behavior_product_views")
bValidInquiries Int? @map("behavior_valid_inquiries")
bValidRfq Int? @map("behavior_valid_rfq")
bLoginDays Int? @map("behavior_login_days")
bSpamInquiries Int? @map("behavior_spam_inquiries")
bBlacklist Int? @map("behavior_blacklist")
bTopIndustry String? @map("behavior_top_industry") @db.VarChar(255)
recentProductsImages String? @map("recent_products_images") @db.Text
storeInquiryProduct String? @map("store_inquiry_product") @db.VarChar(512)
storeInquiryQty String? @map("store_inquiry_qty") @db.VarChar(32)
storeVisitProducts String? @map("store_visit_products") @db.Text
landline String? @map("landline") @db.VarChar(32)
businessType String? @map("business_type") @db.VarChar(128)
salesPlatform String? @map("sales_platform") @db.VarChar(255)
website String? @map("website") @db.VarChar(512)
inquiries Inquiry[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([country])
@@map("customers")
}
model Inquiry {
id BigInt @id @default(autoincrement())
inquiryId String @unique @map("inquiry_id") @db.VarChar(32)
customerId String? @map("customer_id") @db.VarChar(256)
manager String? @db.VarChar(128)
createTime DateTime @map("create_time")
updateTime DateTime @map("update_time")
status String? @db.VarChar(64)
msgPreview String? @map("msg_preview") @db.VarChar(512)
allInquiries String? @map("all_inquiries") @db.Text
isFlagged Boolean @default(false) @map("is_flagged")
messagesCount Int @default(0) @map("messages_count")
lastSendTime DateTime? @map("last_send_time")
hasFailedBatches Boolean @default(false) @map("has_failed_batches")
customer Customer? @relation(fields: [customerId], references: [customerId])
messages ChatMessage[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([customerId])
@@index([manager])
@@map("inquiries")
}
model ChatMessage {
id BigInt @id @default(autoincrement())
messageId String @unique @map("message_id") @db.VarChar(64)
inquiryId String @map("inquiry_id") @db.VarChar(32)
sender String? @db.VarChar(128)
direction Direction
sendTime DateTime @map("send_time")
content String @db.MediumText
translation String? @db.Text
inquiry Inquiry @relation(fields: [inquiryId], references: [inquiryId])
createdAt DateTime @default(now()) @map("created_at")
@@index([inquiryId, sendTime, messageId])
@@index([inquiryId])
@@map("chat_messages")
}
model User {
id BigInt @id @default(autoincrement())
username String @unique
passwordHash String @map("password_hash")
createdAt DateTime @default(now()) @map("created_at")
@@map("users")
}