소스 검색

调整产品list 接口

zhangkunkun 3 년 전
부모
커밋
d6437c7d24
4개의 변경된 파일26개의 추가작업 그리고 1개의 파일을 삭제
  1. 8 1
      apis/petsLy/pets.list.go
  2. BIN
      duoduo
  3. 14 0
      models/mysqlLy/pets.go
  4. 4 0
      models/petsLy/pets.list.go

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

@@ -5,6 +5,7 @@ import (
 	"duoduo/models/petsLy"
 	"duoduo/tools"
 	"duoduo/tools/app"
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"strconv"
 	"time"
@@ -24,6 +25,8 @@ func PetsList(c *gin.Context) {
 		return
 	}
 
+	fmt.Println("indata = %+v", inData)
+
 	if inData.PageSize != 0 {
 		pageSize = inData.PageSize
 	}
@@ -32,6 +35,10 @@ func PetsList(c *gin.Context) {
 	}
 
 	pets.OpenId = inData.OpenId
+	pets.IsFee = inData.IsFee
+	pets.Status = inData.Status
+	pets.City = inData.City
+	pets.Pet = inData.Pet
 	petsList, petsCount, err := pets.GetPetsList(pageSize, pageIndex)
 	if err != nil {
 		app.Error(c, 500, err, "")
@@ -46,7 +53,7 @@ func PetsList(c *gin.Context) {
 			return
 		}
 		timeDiff := time.Now().Unix() - petsList[i].CreateTime.Unix()
-		if timeDiff > 0 && timeDiff < 60 { //秒前
+		if timeDiff >= 0 && timeDiff < 60 { //秒前
 			pet.TimeDiff = strconv.FormatInt(timeDiff, 10)
 			pet.TimeDiff = pet.TimeDiff + "秒前"
 		} else if timeDiff >= 60 && timeDiff < 60*60 { //分钟前

BIN
duoduo


+ 14 - 0
models/mysqlLy/pets.go

@@ -58,6 +58,20 @@ func (m *Pets) GetPetsList(pageSize int, pageIndex int) ([]Pets, int, error) {
 	if m.OpenId != "" {
 		table = table.Where("open_id = ?  ", m.OpenId)
 	}
+	if m.Pet != "" { //品种
+		table = table.Where("pet = ?  ", m.Pet)
+	}
+	if m.City != "" { //城市
+		table = table.Where("city = ?", m.City)
+	}
+	if m.Status != 0 { //状态
+		table = table.Where("status = ?", m.Status)
+	}
+	if m.IsFee == 1 || m.IsFee == 2 { //
+		table = table.Where("is_fee in (1,2)")
+	} else if m.IsFee == 3 {
+		table = table.Where("is_fee = 3")
+	}
 
 	var count int
 	if err := table.Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {

+ 4 - 0
models/petsLy/pets.list.go

@@ -6,6 +6,10 @@ import (
 
 type PetsListRequest struct {
 	OpenId    string `json:"open_id"`
+	IsFee     int    `json:"is_fee"` //有偿,无偿
+	City      string `json:"city"`   //城市
+	Pet       string `json:"pet"`    //品种
+	Status    int    `json:"status"` //领养状态
 	PageSize  int    `json:"pageSize"`
 	PageIndex int    `json:"pageIndex"`
 }