package eta import ( "hongze/hz_crm_eta/global" "time" ) type ClassifyMenuRelation struct { Id int `gorm:"column:id;primary_key;AUTO_INCREMENT;NOT NULL;comment:'主键ID'"` ClassifyId int `gorm:"column:classify_id;default:0;NOT NULL;comment:'二级分类ID'"` MenuId int `gorm:"column:menu_id;default:0;NOT NULL;comment:'子目录ID'"` CreateTime time.Time `gorm:"column:create_time;default:NULL;comment:'创建时间'"` } func (c *ClassifyMenuRelation) TableName() string { return "classify_menu_relation" } // GetClassifyMenuRelationList 获取子目录关联列表 func (c *ClassifyMenuRelation) GetClassifyMenuRelationList(condition string, pars []interface{}) (items []*ClassifyMenuRelation, err error) { err = global.MYSQL["rddp"].Model(c).Where(condition, pars...).Order("create_time ASC").Scan(&items).Error return } // DeleteAndInsertClassifyMenuRelation 新增子目录关联 func DeleteAndInsertClassifyMenuRelation(classifyId, menuId int) (err error) { tx := global.MYSQL["rddp"].Begin() defer func() { if err != nil { tx.Rollback() } else { tx.Commit() } }() // 删除 sql := `DELETE FROM classify_menu_relation WHERE classify_id = ?` if e := tx.Exec(sql, classifyId).Error; e != nil { err = e return } // 新增 if menuId > 0 { relate := &ClassifyMenuRelation{ ClassifyId: classifyId, MenuId: menuId, CreateTime: time.Now().Local(), } e := tx.Create(relate).Error if e != nil { err = e } } return }