package app import ( "github.com/sirupsen/logrus" "gorm.io/gorm" "lc-fangdaosha/global" "lc-fangdaosha/model/app" ) type PictureService struct { } // SaveEventPicture 保存事件图片 func (ps *PictureService) SaveEventPicture(pic *app.Picture, picData *app.PictureData) { err := global.Db.Transaction(func(tx *gorm.DB) error { err := global.Db.Create(picData).Error if err != nil { return err } pic.DataId = picData.ID err = global.Db.Create(pic).Error if err != nil { return err } return nil }) if err != nil { logrus.WithField("eventId", pic.EventId).Error("图片保存失败") } }