录入、列表和导入导出带上商户编号。生日提醒展示与录入一致的商户资料,旧阴历生日仍按农历提醒。 Co-authored-by: Cursor <cursoragent@cursor.com>
112 lines
3.7 KiB
Plaintext
112 lines
3.7 KiB
Plaintext
// CRM 新架构 —— 映射测试库 crm_dev(数据已清洗)
|
||
// 关键约定:
|
||
// - birthday / reportDate 已是 date 类型;原始脏值保留在 *_raw 备份列
|
||
// - 物理表名/列名用 @map/@@map 对齐现有库,不改动库结构
|
||
// - 废表 users / sms / customers_copy / admin_customer 不建模(视而不见)
|
||
|
||
generator client {
|
||
provider = "prisma-client-js"
|
||
}
|
||
|
||
datasource db {
|
||
provider = "mysql"
|
||
url = env("DATABASE_URL")
|
||
}
|
||
|
||
/// 客户(系统核心,~1.4 万行)
|
||
model Customer {
|
||
id Int @id @default(autoincrement())
|
||
customerName String? @default("") @map("customer_name")
|
||
customerNo String? @map("customer_no") @db.Text // 商户编号,数字与字母,区分大小写,不限位数
|
||
contacts String? // 联系人
|
||
contactsPhone String? @default("") @map("contacts_phone") // 联系人手机号
|
||
balanceUser String? @map("balance_user") // 结算人
|
||
balanceUserPhone String? @default("") @map("balance_user_phone") // 结算人手机号
|
||
phone String? // 旧公共联系电话(已停用录入/展示,保留历史数据)
|
||
detail String?
|
||
deposit String? // 押金
|
||
buy String? // 买断
|
||
birthdayType Int? @default(1) @map("birthday_type") // 1阳历 2阴历
|
||
birthdayOwner Int? @default(2) @map("birthday_owner") // 1结算人 2联系人
|
||
birthday DateTime? @db.Date // 已清洗为 date(阴历行月日为农历,年份占位)
|
||
birthdayRaw String? @map("birthday_raw") // 清洗前原始脏值备份
|
||
salesman String? // 业务员
|
||
reportDate DateTime? @map("report_date") @db.Date // 报单时间,已清洗为 date
|
||
reportDateRaw String? @map("report_date_raw") // 清洗前原始脏值备份
|
||
remark String?
|
||
createdAt DateTime? @map("created_at")
|
||
updatedAt DateTime? @map("updated_at")
|
||
deletedAt DateTime? @map("deleted_at") // 软删除
|
||
|
||
@@index([reportDate])
|
||
@@index([birthday])
|
||
@@index([customerName])
|
||
@@map("customers")
|
||
}
|
||
|
||
/// 后台账号(12 个,密码为 Laravel bcrypt,可被 Auth.js 直接校验)
|
||
model Admin {
|
||
id Int @id @default(autoincrement())
|
||
username String @unique
|
||
nickname String
|
||
face String?
|
||
password String
|
||
rememberToken String? @map("remember_token")
|
||
createdAt DateTime? @map("created_at")
|
||
updatedAt DateTime? @map("updated_at")
|
||
deletedAt DateTime? @map("deleted_at")
|
||
|
||
@@map("admins")
|
||
}
|
||
|
||
/// 角色(超级管理员 / 业务员)
|
||
model Role {
|
||
id Int @id @default(autoincrement())
|
||
name String
|
||
title String?
|
||
remark String?
|
||
guardName String? @map("guard_name")
|
||
createdAt DateTime? @map("created_at")
|
||
updatedAt DateTime? @map("updated_at")
|
||
|
||
@@map("roles")
|
||
}
|
||
|
||
/// 权限(同时是后台菜单树:pid/sort/isMenu/icon)
|
||
model Permission {
|
||
id Int @id @default(autoincrement())
|
||
pid Int? @default(0)
|
||
name String
|
||
param String?
|
||
title String?
|
||
icon String?
|
||
sort Int? @default(0)
|
||
isMenu Boolean? @default(false) @map("is_menu")
|
||
guardName String? @map("guard_name")
|
||
createdAt DateTime? @map("created_at")
|
||
updatedAt DateTime? @map("updated_at")
|
||
|
||
@@map("permissions")
|
||
}
|
||
|
||
/// spatie 多态:账号-角色(本阶段照搬,映射即可)
|
||
model ModelHasRole {
|
||
roleId Int @map("role_id")
|
||
modelId Int @map("model_id")
|
||
modelType String @map("model_type")
|
||
|
||
@@id([roleId, modelId, modelType])
|
||
@@index([modelId, modelType])
|
||
@@map("model_has_roles")
|
||
}
|
||
|
||
/// 角色-权限
|
||
model RoleHasPermission {
|
||
permissionId Int @map("permission_id")
|
||
roleId Int @map("role_id")
|
||
|
||
@@id([permissionId, roleId])
|
||
@@index([roleId])
|
||
@@map("role_has_permissions")
|
||
}
|