You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
3.1 KiB
65 lines
3.1 KiB
package console
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
)
|
|
|
|
// 代工厂/组装厂档案(oem_factory)——与品牌商(brand)并列的独立实体:
|
|
// 品牌商是「这货挂谁的牌子卖」,代工厂是「这货由哪家厂生产组装」,同一品牌可以换厂、
|
|
// 同一厂也给多个品牌代工,所以不能复用 brand。
|
|
//
|
|
// ⚠️ 表名用 oem_factory 而不是 factory:库里已经有一张遗留的 `factory` 表
|
|
// (旧「厂家」概念的残留,2026-09-01 核查时全代码库无任何引用,TableFactory 常量都不存在),
|
|
// 列结构和这里对不上。占用同名会让 gorm 往那张旧表上加列、把两套语义混在一起。
|
|
// 旧 factory 表可以单独 DROP,但不要在这里顺手复用它。
|
|
type OemFactory struct {
|
|
Id uint32 `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
|
|
Name string `gorm:"column:name;size:64;index" json:"name"` // 工厂名称
|
|
Contact string `gorm:"column:contact;size:64" json:"contact"` // 联系人
|
|
Phone string `gorm:"column:phone;size:32" json:"phone"` // 联系电话
|
|
Contactmails string `gorm:"column:contactmails;size:255" json:"contactmails"` // 联系人邮箱,逗号分隔
|
|
Address string `gorm:"column:address;size:255" json:"address"` // 工厂地址
|
|
Description string `gorm:"column:description;size:255" json:"description"` // 说明:产能、擅长品类等
|
|
Enabled bool `gorm:"column:enabled" json:"enabled"` // 停用后不在下拉里出现,存量数据仍能显示其名字
|
|
Sort int32 `gorm:"column:sort" json:"sort"` // 列表排序,小的在前;相同则按 id
|
|
Createtime int64 `gorm:"column:createtime" json:"createtime"`
|
|
Updatetime int64 `gorm:"column:updatetime" json:"updatetime"`
|
|
}
|
|
|
|
func (OemFactory) TableName() string { return comm.TableOemFactory }
|
|
|
|
// ---- 代工厂 CRUD(console 主库,与方案商/品牌商同库)----
|
|
|
|
func dvOemFactories(sys *appConn) (models []*OemFactory, err error) {
|
|
models = make([]*OemFactory, 0)
|
|
err = sys.AdminDB().Find(comm.TableOemFactory, &models, "")
|
|
return
|
|
}
|
|
|
|
func dvOemFactory(sys *appConn, id uint32) (model *OemFactory, err error) {
|
|
model = &OemFactory{}
|
|
// 用 FindOne:不存在时返回 ErrRecordNotFound,存在性校验才有效(Find 对空结果不报错)。
|
|
err = sys.AdminDB().FindOne(comm.TableOemFactory, model, "id=?", id)
|
|
return
|
|
}
|
|
|
|
func dvAddOemFactory(sys *appConn, model *OemFactory) (err error) {
|
|
err = sys.AdminDB().Insert(comm.TableOemFactory, model)
|
|
return
|
|
}
|
|
|
|
func dvSaveOemFactory(sys *appConn, model *OemFactory) (err error) {
|
|
err = sys.AdminDB().Save(comm.TableOemFactory, model)
|
|
return
|
|
}
|
|
|
|
func dvDelOemFactory(sys *appConn, id uint32) (err error) {
|
|
err = sys.AdminDB().Delete(comm.TableOemFactory, "id=?", id)
|
|
return
|
|
}
|
|
|
|
// dvCountBatchesByFactory 统计关联到某工厂的生产批次数,删除前用它挡住「删了批次就追溯不到厂」。
|
|
func dvCountBatchesByFactory(sys *appConn, factoryId uint32) (n int64, err error) {
|
|
err = sys.AdminDB().Table(comm.TableProductionBatch).Where("factoryid=?", factoryId).Count(&n).Error
|
|
return
|
|
}
|
|
|