zhangkunkun 3 gadi atpakaļ
vecāks
revīzija
504ce48b74
3 mainītis faili ar 55 papildinājumiem un 5 dzēšanām
  1. 42 1
      apis/petsLy/pets.list.go
  2. 10 1
      models/petsLy/pets.list.go
  3. 3 3
      report/report.go

+ 42 - 1
apis/petsLy/pets.list.go

@@ -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, "成功")
 
 }

+ 10 - 1
models/petsLy/pets.list.go

@@ -11,5 +11,14 @@ type PetsListRequest struct {
 }
 
 type PetsListResponse struct {
-	Pets []mysqlLy.Pets `json:"pets"`
+	Pets []Pets `json:"pets"`
+}
+
+type Pets struct {
+	Pets     mysqlLy.Pets `json:"pets"`
+	Pictures []string     `json:"pictures"`
+	TimeDiff string       `json:"time_diff"`
+}
+
+type Pictures struct {
 }

+ 3 - 3
report/report.go

@@ -3,9 +3,9 @@ package report
 import "github.com/robfig/cron"
 
 const (
-	cronSettDateCutoff = "0 0 1 * * *"   //每天凌晨1:00:00
-	cronRunStart       = "0 0 17 * * *"  //凌晨一点
-	cronMinuteStart    = "0 */1 * * * *" //每分钟
+	cronSettDateCutoff = "0 0 1 * * *"    //每天凌晨1:00:00
+	cronRunStart       = "0 0 17 * * *"   //凌晨一点
+	cronMinuteStart    = "0 */10 * * * *" //每10分钟
 )
 
 func SysCronStart() {