156 lines
4.2 KiB
Go
156 lines
4.2 KiB
Go
package models
|
|
|
|
// 数据模型与业务常量。
|
|
// 所有常量与前端 cnc-sales-workbench.html 中的定义保持一致。
|
|
|
|
// StageNames 销售阶段:s1~s8
|
|
var StageNames = map[string]string{
|
|
"s1": "信息收集", "s2": "需求调研", "s3": "方案定制", "s4": "打样验证",
|
|
"s5": "商务谈判", "s6": "合同签订", "s7": "交付安装调试", "s8": "售后维护",
|
|
}
|
|
|
|
var (
|
|
Levels = []string{"A", "B", "C"}
|
|
Priorities = []string{"P0", "P1", "P2"}
|
|
TaskStatuses = []string{"todo", "doing", "done"}
|
|
Repeats = []string{"daily", "weekly", "monthly"}
|
|
NoteCats = []string{"报价模板", "技术沟通要点", "谈判话术", "合同注意事项", "其他"}
|
|
ContactRoles = []string{"老板", "技术", "采购", "其他"}
|
|
)
|
|
|
|
// Contains 判断切片是否包含某值
|
|
func Contains(list []string, v string) bool {
|
|
for _, x := range list {
|
|
if x == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// NormalizeStage 规范化销售阶段,非法值回退到 s1
|
|
func NormalizeStage(s string) string {
|
|
if _, ok := StageNames[s]; ok {
|
|
return s
|
|
}
|
|
return "s1"
|
|
}
|
|
|
|
// NormalizeLevel 规范化客户等级,非法值回退到 C
|
|
func NormalizeLevel(s string) string {
|
|
if Contains(Levels, s) {
|
|
return s
|
|
}
|
|
return "C"
|
|
}
|
|
|
|
// NormalizePriority 规范化任务优先级,非法值回退到 P2
|
|
func NormalizePriority(s string) string {
|
|
if Contains(Priorities, s) {
|
|
return s
|
|
}
|
|
return "P2"
|
|
}
|
|
|
|
// NormalizeStatus 规范化任务状态,非法值回退到 todo
|
|
func NormalizeStatus(s string) string {
|
|
if Contains(TaskStatuses, s) {
|
|
return s
|
|
}
|
|
return "todo"
|
|
}
|
|
|
|
// NormalizeRepeat 规范化重复规则,非法值返回 nil
|
|
func NormalizeRepeat(s string) *string {
|
|
if Contains(Repeats, s) {
|
|
return &s
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// NormalizeNoteCat 规范化资料分类,非法值回退到"其他"
|
|
func NormalizeNoteCat(s string) string {
|
|
if Contains(NoteCats, s) {
|
|
return s
|
|
}
|
|
return "其他"
|
|
}
|
|
|
|
// ---- 数据结构 ----
|
|
|
|
// User 用户
|
|
type User struct {
|
|
ID int64 `json:"id"`
|
|
Username string `json:"username"`
|
|
DisplayName string `json:"displayName"`
|
|
Role string `json:"role"`
|
|
CreatedAt string `json:"createdAt"`
|
|
}
|
|
|
|
// Contact 联系人
|
|
type Contact struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
Phone string `json:"phone"`
|
|
}
|
|
|
|
// FollowUp 跟进记录
|
|
type FollowUp struct {
|
|
ID int64 `json:"id"`
|
|
Time string `json:"time"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
// Customer 客户档案(字段与前端 normalizeCustomer 对齐)
|
|
type Customer struct {
|
|
ID string `json:"id"`
|
|
Company string `json:"company"`
|
|
Industry string `json:"industry"`
|
|
Address string `json:"address"`
|
|
Contacts []Contact `json:"contacts"`
|
|
Level string `json:"level"`
|
|
Stage string `json:"stage"`
|
|
MachineModel string `json:"machineModel"`
|
|
Budget string `json:"budget"`
|
|
WorkpieceNeeds string `json:"workpieceNeeds"`
|
|
PainPoints string `json:"painPoints"`
|
|
FollowUps []FollowUp `json:"followUps"`
|
|
NextFollowDate string `json:"nextFollowDate"`
|
|
Source string `json:"source"`
|
|
Remark string `json:"remark"`
|
|
CreatedAt string `json:"createdAt"`
|
|
UpdatedAt string `json:"updatedAt"`
|
|
}
|
|
|
|
// Task 任务
|
|
type Task struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
CustomerID *string `json:"customerId"`
|
|
CustomerName string `json:"customerName,omitempty"`
|
|
DueDate string `json:"dueDate"`
|
|
Priority string `json:"priority"`
|
|
Status string `json:"status"`
|
|
Repeat *string `json:"repeat"`
|
|
CreatedAt string `json:"createdAt"`
|
|
}
|
|
|
|
// Note 资料
|
|
type Note struct {
|
|
ID string `json:"id"`
|
|
Cat string `json:"cat"`
|
|
Title string `json:"title"`
|
|
Content string `json:"content"`
|
|
UpdatedAt string `json:"updatedAt"`
|
|
}
|
|
|
|
// Backup 全量备份(与前端数据中心 JSON 导出格式对齐)
|
|
type Backup struct {
|
|
SchemaVersion int `json:"schemaVersion"`
|
|
ExportedAt string `json:"exportedAt"`
|
|
Customers []Customer `json:"customers"`
|
|
Tasks []Task `json:"tasks"`
|
|
Notes []Note `json:"notes"`
|
|
}
|