pets.details.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package petsLy
  2. import (
  3. "duoduo/models/mysqlLy"
  4. "duoduo/models/petsLy"
  5. "duoduo/tools"
  6. "duoduo/tools/app"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func PetsDetails(c *gin.Context) {
  11. var inData petsLy.PetsDetailsRequest
  12. var pets mysqlLy.Pets
  13. var outData petsLy.PetsDetailsResponse
  14. var user mysqlLy.User
  15. err := c.ShouldBindJSON(&inData)
  16. if err != nil {
  17. app.Error(c, 400, err, err.Error())
  18. return
  19. }
  20. pets.ID = inData.PetsId
  21. petsInfo, err := pets.Get()
  22. if err != nil {
  23. app.Error(c, 500, err, "查询数据失败")
  24. return
  25. }
  26. user.OpenID = petsInfo.OpenId
  27. userInfo,err := user.Get()
  28. if err != nil{
  29. app.Error(c,500,err,"获取用户信息失败")
  30. return
  31. }
  32. if petsInfo.Status == 2{
  33. userInfo.Phone = "***********"
  34. userInfo.WxCode = "***********"
  35. }
  36. outData.PetsInfo = petsInfo
  37. outData.Phone = userInfo.Phone
  38. outData.WxCode = userInfo.WxCode
  39. outData.DepositDate = outData.PetsInfo.DepositDate.Format("2006-01-02")
  40. err = tools.JsonUnmarshal(outData.PetsInfo.Pictures,&outData.Pictures)
  41. if err != nil{
  42. fmt.Println(err.Error())
  43. app.Error(c,500,err,"解析图片失败")
  44. return
  45. }
  46. app.OK(c, outData, app.Success)
  47. }