picture.go 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package app
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "lc-fangdaosha/global"
  6. "lc-fangdaosha/model/app"
  7. "lc-fangdaosha/model/common/response"
  8. )
  9. type PictureApi struct {
  10. }
  11. // GetPicture 获取图片信息
  12. func (pa *PictureApi) GetPicture(c *gin.Context) {
  13. code := c.Query("picode")
  14. var dataId int
  15. err := global.Db.Select("p.data_id").
  16. Table("event e JOIN picture p ON e.id = p.event_id").
  17. Where("e.event_code = ?", code).
  18. Find(&dataId).Error
  19. if err != nil {
  20. logrus.Error(err)
  21. response.Fail(c)
  22. return
  23. }
  24. var picData app.PictureData
  25. err = global.Db.Select("id, data").
  26. Model(&app.PictureData{}).
  27. Where("id = ?", dataId).
  28. Find(&picData).Error
  29. if err != nil {
  30. logrus.Error(err)
  31. response.Fail(c)
  32. return
  33. }
  34. c.Header("Content-Type", "image/jpeg;charset=UTF-8")
  35. _, err = c.Writer.Write(picData.Data)
  36. if err != nil {
  37. logrus.Error(err)
  38. response.Fail(c)
  39. return
  40. }
  41. }