[code]func UpdateArticleDetails(title, content, cover, desc, tags, keyword string, menuId, categoryId int, isTop, hot, recommend, prod, markdown bool, id int) error {// 0 草稿箱 1发布 2垃圾箱var save intif prod {save = 1} else {save = 0}a := &models.Article{Id: id}if tags != \"\" {a.Tags = &tags}if categoryId != -1 {a.CategoryId = &categoryId}if keyword != \"\" {a.Keyword = &keyword}// 开始事务tx := db.DbConn.Begin()defer tx.Commit()if categoryId == -1 {err := tx.Model(&a).Updates(map[string]interface{}{\"title\": title, \"cover\": cover, \"desc\": desc, \"menu_id\": menuId, \"category_id\": nil, \"tags\": tags, \"hot\": hot, \"recommend\": recommend, \"markdown\": markdown, \"type\": save, \"update_time\": time.Now()}).Errorif err != nil {logger.Error(err.Error())tx.Rollback()return err}} else {err := tx.Model(&a).Updates(map[string]interface{}{\"title\": title, \"cover\": cover, \"desc\": desc, \"menu_id\": menuId, \"category_id\": categoryId, \"tags\": tags, \"hot\": hot, \"recommend\": recommend, \"markdown\": markdown, \"type\": save, \"update_time\": time.Now()}).Errorif err != nil {logger.Error(err.Error())tx.Rollback()return err}}err := tx.Model(&models.ArticleContent{}).Where(\"article_id = ?\", &a.Id).Update(\"content\", content).Errorif err != nil {logger.Error(err.Error())tx.Rollback()return err}var count intif isTop {s := models.System{TopId: sql.NullInt64{Int64: int64(id), Valid: true},CreatedTime: time.Now(),}err = tx.Select([]string{\"id\"}).Model(&models.System{}).Count(&count).Errorif err != nil {logger.Error(err.Error())tx.Rollback()return err}if count == 0 {err = db.DbConn.Create(&s).Error} else {err = tx.Model(&s).Updates(map[string]interface{}{\"top_id\": id, \"update_time\": time.Now()}).Error}if err != nil {logger.Error(err.Error())tx.Rollback()return err}} else {s := models.System{TopId: sql.NullInt64{Int64: int64(id), Valid: true},CreatedTime: time.Now(),}err = tx.Select([]string{\"id\"}).Model(&models.System{}).Count(&count).Errorif err != nil {logger.Error(err.Error())tx.Rollback()return err}if count == 0 {err = db.DbConn.Create(&s).Error} else {err = tx.Model(&s).Updates(map[string]interface{}{\"top_id\": nil, \"update_time\": time.Now()}).Error}if err != nil {logger.Error(err.Error())tx.Rollback()return err}}return nil}