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.

81 lines
1.7 KiB

package goods
import (
"github.com/gin-gonic/gin"
"live/app/lib"
"live/app/lib/back"
"live/app/lib/tools"
"live/app/logic/goods"
)
type Goods struct {
}
type ArgsGoodsList struct {
Keyword string `json:"keyword" form:"keyword"`
lib.Page
}
// @Title 商品列表 关键字检索
// @Param keyword string true "检索关键字"
func (g *Goods) List(c *gin.Context) {
argsGoodsList := ArgsGoodsList{}
if err := tools.ParseParams(&argsGoodsList, c); err != nil {
back.Fail(c, err.Error())
return
}
if argsGoodsList.Keyword == "" {
back.Fail(c, "参数不全")
return
}
list := (&goods.Goods{}).GetGoodsList(argsGoodsList.Keyword, argsGoodsList.Page)
back.Suc(c, "操作成功", list)
}
// @Title 品牌列表
func (g *Goods) BrandList(c *gin.Context) {
page := lib.Page{}
if err := tools.ParseParams(&page, c); err != nil {
back.Fail(c, err.Error())
return
}
list := (&goods.Goods{}).BrandList(page)
back.Suc(c, "操作成功", list)
}
type ArgsBrandGoodsList struct {
BrandId uint `json:"brandId" form:"brandId"`
lib.Page
}
// @Title 品牌列表
func (g *Goods) BrandGoodsList(c *gin.Context) {
argsBrandGoodsList := ArgsBrandGoodsList{}
if err := tools.ParseParams(&argsBrandGoodsList, c); err != nil {
back.Fail(c, err.Error())
return
}
if argsBrandGoodsList.BrandId == 0 {
back.Fail(c, "参数不全")
return
}
list := (&goods.Goods{}).GoodsListByBrandId(argsBrandGoodsList.BrandId, argsBrandGoodsList.Page)
back.Suc(c, "操作成功", list)
}
func (g *Goods) Hot(c *gin.Context) {
args := lib.Page{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
list, total := (&goods.Goods{}).HotGoods(args)
back.Suc(c, "操作成功", gin.H{
"total": total,
"list": list,
})
}