sys_group.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package crm
  2. import (
  3. "eta/eta_bridge/global"
  4. "time"
  5. )
  6. type SysGroup struct {
  7. GroupId int `gorm:"primaryKey;column:group_id;type:int(11);not null" json:"group_id"`
  8. DepartmentId int `gorm:"index:idx_department_id;column:department_id;type:int(11)" json:"department_id"` // 部门id
  9. GroupName string `gorm:"column:group_name;type:varchar(255);default:''" json:"group_name"` // 分组名称
  10. CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"`
  11. ParentId int `gorm:"column:parent_id;type:int(11);default:0" json:"parent_id"`
  12. Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` // 排序
  13. }
  14. func (m *SysGroup) TableName() string {
  15. return "sys_group"
  16. }
  17. // Create 新增分组
  18. func (m *SysGroup) Create() (err error) {
  19. err = global.MYSQL["hz_crm"].Create(m).Error
  20. return
  21. }
  22. // Update 更新分组
  23. func (m *SysGroup) Update(cols []string) (err error) {
  24. err = global.MYSQL["hz_crm"].Model(m).Select(cols).Updates(m).Error
  25. return
  26. }
  27. // GetSysGroupByGroupId 获取分组-根据主键
  28. func GetSysGroupByGroupId(groupId int) (item *SysGroup, err error) {
  29. err = global.MYSQL["hz_crm"].Where("group_id = ?", groupId).First(&item).Error
  30. return
  31. }
  32. // DeleteGroupByGroupId 删除分组-根据主键
  33. func DeleteGroupByGroupId(groupId int) (err error) {
  34. sql := `DELETE FROM sys_group WHERE group_id = ? LIMIT 1`
  35. err = global.MYSQL["hz_crm"].Exec(sql, groupId).Error
  36. if err != nil {
  37. return
  38. }
  39. // 清除关联
  40. sql = `UPDATE admin SET group_id = 0, group_name = '' WHERE group_id = ? `
  41. err = global.MYSQL["hz_crm"].Exec(sql, groupId).Error
  42. return
  43. }