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.

68 lines
1.3 KiB

5 years ago
package goods
import (
"github.com/gin-gonic/gin"
"live/app/common"
"live/app/lib"
"live/app/lib/back"
"live/app/lib/tools"
"live/app/logic/goods"
)
type Cupboard struct {
}
// 橱柜列表请求参数
type ListArgs struct {
lib.Page
}
// @Title 获取橱柜列表
// @Param keyword string false "检索关键字"
// @Param page int false "页数 默认1"
// @Param limit int false "分页大小"
func (cup *Cupboard) List(c *gin.Context) {
uid := common.GetUserId(c)
if uid == 0 {
back.Fail(c, "未登录")
5 years ago
return
}
args := ListArgs{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
list, count := (&goods.Cupboard{}).GetList(uid, args.Page)
back.Suc(c, "操作成功", gin.H{
"list": list,
"total": count,
5 years ago
})
}
type ArgsDel struct {
5 years ago
Ids []int `json:"ids" form:"ids"`
5 years ago
}
// @Title 删除橱柜商品
// @Param Ids []int true "删除橱柜商品id数组"
func (cup *Cupboard) Delete(c *gin.Context) {
uid := common.GetUserId(c)
argsDel := ArgsDel{}
if err := tools.ParseParams(&argsDel, c); err != nil {
back.Fail(c, err.Error())
return
}
5 years ago
if len(argsDel.Ids) == 0 {
back.Fail(c, "参数不全")
return
}
5 years ago
if (&goods.Cupboard{}).Delete(uid, argsDel.Ids) {
back.Suc(c, "操作成功", "")
return
} else {
back.Fail(c, "操作失败")
return
}
}