package crm import ( "hongze/hz_crm_eta/global" "time" ) type SysGroup struct { GroupId int `gorm:"primaryKey;column:group_id;type:int(11);not null" json:"group_id"` DepartmentId int `gorm:"index:idx_department_id;column:department_id;type:int(11)" json:"department_id"` // 部门id GroupName string `gorm:"column:group_name;type:varchar(255);default:''" json:"group_name"` // 分组名称 CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"` ParentId int `gorm:"column:parent_id;type:int(11);default:0" json:"parent_id"` Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` // 排序 } func (m *SysGroup) TableName() string { return "sys_group" } // Create 新增分组 func (m *SysGroup) Create() (err error) { err = global.MYSQL["hz_crm"].Create(m).Error return } // Update 更新分组 func (m *SysGroup) Update(cols []string) (err error) { err = global.MYSQL["hz_crm"].Model(m).Select(cols).Updates(m).Error return } // GetSysGroupByGroupId 获取分组-根据主键 func GetSysGroupByGroupId(groupId int) (item *SysGroup, err error) { err = global.MYSQL["hz_crm"].Where("group_id = ?", groupId).First(&item).Error return } // DeleteGroupByGroupId 删除分组-根据主键 func DeleteGroupByGroupId(groupId int) (err error) { sql := `DELETE FROM sys_group WHERE group_id = ? LIMIT 1` err = global.MYSQL["hz_crm"].Exec(sql, groupId).Error if err != nil { return } // 清除关联 sql = `UPDATE admin SET group_id = 0, group_name = '' WHERE group_id = ? ` err = global.MYSQL["hz_crm"].Exec(sql, groupId).Error return }