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.
94 lines
1.8 KiB
94 lines
1.8 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 Car struct {
|
||
|
}
|
||
|
|
||
|
// 橱柜列表请求参数
|
||
|
type argsList struct {
|
||
|
lib.Page
|
||
|
}
|
||
|
|
||
|
// @Title 获取直播车列表
|
||
|
// @Param keyword string false "检索关键字"
|
||
|
// @Param page int false "页数 默认1"
|
||
|
// @Param limit int false "分页大小"
|
||
|
func (car *Car) List(c *gin.Context) {
|
||
|
uid := common.GetUserId(c)
|
||
|
if uid == 0 {
|
||
|
back.Fail(c, "未登录")
|
||
|
return
|
||
|
}
|
||
|
args := argsList{}
|
||
|
if err := tools.ParseParams(&args, c); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
list, count := (&goods.Car{}).GetList(uid, args.Page)
|
||
|
|
||
|
back.Suc(c, "操作成功", gin.H{
|
||
|
"list": list,
|
||
|
"total": count,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
type argsDel struct {
|
||
|
Ids []int `json:"ids" form:"ids"`
|
||
|
}
|
||
|
|
||
|
// @Title 删除直播车商品
|
||
|
// @Param Ids []int true "删除橱柜商品id数组"
|
||
|
func (car *Car) Delete(c *gin.Context) {
|
||
|
uid := common.GetUserId(c)
|
||
|
argsDel := argsDel{}
|
||
|
if err := tools.ParseParams(&argsDel, c); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
if len(argsDel.Ids) == 0 {
|
||
|
back.Fail(c, "参数不全")
|
||
|
return
|
||
|
}
|
||
|
if (&goods.Car{}).Delete(uid, argsDel.Ids) {
|
||
|
back.Suc(c, "操作成功", "")
|
||
|
return
|
||
|
} else {
|
||
|
back.Fail(c, "操作失败")
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
type argsAdd struct {
|
||
|
GoodsIds []uint `json:"goodsIds" form:"goodsIds"`
|
||
|
}
|
||
|
|
||
|
// @Title 添加直播车商品
|
||
|
// @Param Ids []int true "添加直播车商品id数组"
|
||
|
func (car *Car) Add(c *gin.Context) {
|
||
|
uid := common.GetUserId(c)
|
||
|
args := argsAdd{}
|
||
|
if err := tools.ParseParams(&args, c); err != nil {
|
||
|
back.Fail(c, err.Error())
|
||
|
return
|
||
|
}
|
||
|
if len(args.GoodsIds) == 0 {
|
||
|
back.Fail(c, "参数不全")
|
||
|
return
|
||
|
}
|
||
|
if (&goods.Car{}).Add(uid, args.GoodsIds) > 0 {
|
||
|
back.Suc(c, "操作成功", "")
|
||
|
return
|
||
|
} else {
|
||
|
back.Fail(c, "操作失败")
|
||
|
return
|
||
|
}
|
||
|
}
|