picture.go 623 B

123456789101112131415161718192021222324252627282930
  1. package app
  2. import (
  3. "github.com/sirupsen/logrus"
  4. "gorm.io/gorm"
  5. "lc-fangdaosha/global"
  6. "lc-fangdaosha/model/app"
  7. )
  8. type PictureService struct {
  9. }
  10. // SaveEventPicture 保存事件图片
  11. func (ps *PictureService) SaveEventPicture(pic *app.Picture, picData *app.PictureData) {
  12. err := global.Db.Transaction(func(tx *gorm.DB) error {
  13. err := global.Db.Create(picData).Error
  14. if err != nil {
  15. return err
  16. }
  17. pic.DataId = picData.ID
  18. err = global.Db.Create(pic).Error
  19. if err != nil {
  20. return err
  21. }
  22. return nil
  23. })
  24. if err != nil {
  25. logrus.WithField("eventId", pic.EventId).Error("图片保存失败")
  26. }
  27. }