zhangqian
2023-10-17 b45b8ce8051e2ad9c80aafa42d1a5892f6a36bce
初始化一些表shuju
3个文件已修改
71 ■■■■■ 已修改文件
model/clientStatus.go 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/salesSources.go 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/clientStatus.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -91,3 +92,37 @@
    var db = slf.build()
    return db.Updates(values).Error
}
func (slf *ClientStatusSearch) CreateBatch(records []*ClientStatus) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *ClientStatusSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*ClientStatus{
        {1, "初期沟通"},
        {2, "需求分析"},
        {3, "方案报价"},
        {4, "商务谈判"},
        {5, "成功结案"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/index.go
@@ -124,6 +124,8 @@
        NewRepositorySearch(),
        NewSaleStageSearch(),
        NewQuotationStatusSearch(),
        NewSalesSourcesSearch(),
        NewClientStatusSearch(),
    }
    for _, model := range models {
model/salesSources.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -84,3 +85,36 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *SalesSourcesSearch) CreateBatch(records []*SalesSources) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *SalesSourcesSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*SalesSources{
        {1, "电话来访"},
        {2, "公司分配"},
        {3, "客户介绍"},
        {4, "独立开发"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}