|
@@ -3,13 +3,17 @@ package petsLy
|
|
|
import (
|
|
|
"duoduo/models/mysqlLy"
|
|
|
"duoduo/models/petsLy"
|
|
|
+ "duoduo/tools"
|
|
|
"duoduo/tools/app"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
func PetsList(c *gin.Context) {
|
|
|
var inData petsLy.PetsListRequest
|
|
|
var pets mysqlLy.Pets
|
|
|
+ var outData petsLy.PetsListResponse
|
|
|
|
|
|
var pageSize = 10
|
|
|
var pageIndex = 1
|
|
@@ -33,6 +37,43 @@ func PetsList(c *gin.Context) {
|
|
|
app.Error(c, 500, err, "")
|
|
|
return
|
|
|
}
|
|
|
- app.PageOK(c, petsList, petsCount, pageIndex, pageSize, "成功")
|
|
|
+ for i := 0; i < len(petsList); i++ {
|
|
|
+ var pet petsLy.Pets
|
|
|
+ pet.Pets = petsList[i]
|
|
|
+ err := tools.JsonUnmarshal(petsList[i].Pictures, &pet.Pictures)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 500, err, "")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ timeDiff := time.Now().Unix() - petsList[i].CreateTime.Unix()
|
|
|
+ if timeDiff > 0 && timeDiff < 60 { //秒前
|
|
|
+ pet.TimeDiff = strconv.FormatInt(timeDiff, 10)
|
|
|
+ pet.TimeDiff = pet.TimeDiff + "秒前"
|
|
|
+ } else if timeDiff >= 60 && timeDiff < 60*60 { //分钟前
|
|
|
+ number := timeDiff / 60
|
|
|
+ pet.TimeDiff = strconv.FormatInt(number, 10)
|
|
|
+ pet.TimeDiff = pet.TimeDiff + "分钟前"
|
|
|
+
|
|
|
+ } else if timeDiff >= 60*60 && timeDiff < 60*60*24 { //小时前
|
|
|
+ number := timeDiff / (60 * 60)
|
|
|
+ pet.TimeDiff = strconv.FormatInt(number, 10)
|
|
|
+ pet.TimeDiff = pet.TimeDiff + "小时前"
|
|
|
+ } else if timeDiff >= 60*60*24 && timeDiff < 60*60*24*30 { //天前
|
|
|
+ number := timeDiff / (60 * 60 * 24)
|
|
|
+ pet.TimeDiff = strconv.FormatInt(number, 10)
|
|
|
+ pet.TimeDiff = pet.TimeDiff + "天前"
|
|
|
+ } else if timeDiff >= 60*60*24*30 && timeDiff < 60*60*24*365 { //月前
|
|
|
+ number := timeDiff / (60 * 60 * 24 * 30)
|
|
|
+ pet.TimeDiff = strconv.FormatInt(number, 10)
|
|
|
+ pet.TimeDiff = pet.TimeDiff + "月前"
|
|
|
+ } else if timeDiff >= 60*60*24*365 { //年前
|
|
|
+ number := timeDiff / (60 * 60 * 24 * 365)
|
|
|
+ pet.TimeDiff = strconv.FormatInt(number, 10)
|
|
|
+ pet.TimeDiff = pet.TimeDiff + "年前"
|
|
|
+ }
|
|
|
+
|
|
|
+ outData.Pets = append(outData.Pets, pet)
|
|
|
+ }
|
|
|
+ app.PageOK(c, outData, petsCount, pageIndex, pageSize, "成功")
|
|
|
|
|
|
}
|