You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
956 B

package evaluation
import (
"github.com/gin-gonic/gin"
"recook/internal/back"
"recook/internal/dbc"
"recook/internal/model/goods"
"recook/tools"
)
type queryListParam struct {
GoodsID uint `json:"goodsId"`
Page uint `json:"page"`
}
type evalResp struct {
goods.Evaluation
Photos []goods.EvaluationPhoto `json:"photos"`
}
func QueryGoodsEvaluationList(c *gin.Context) {
var p queryListParam
err := tools.ParseParams(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
list := make([]goods.Evaluation, 0, 0)
dbc.DB.Limit(20).Offset(p.Page*20).Order("id desc").Find(&list, "goods_id = ? and pass=?", p.GoodsID, 1)
array := make([]evalResp, 0, 0)
for i, v := range list {
photos := make([]goods.EvaluationPhoto, 0, 0)
dbc.DB.Select("url, width, height").Order("order_no asc").Find(&photos, "evaluation_id = ?", v.ID)
r := evalResp{
list[i],
photos,
}
array = append(array, r)
}
back.Suc(c, "", array)
}