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.
153 lines
4.2 KiB
153 lines
4.2 KiB
package v1
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"pure-admin/global"
|
|
"pure-admin/model/request"
|
|
"pure-admin/model/response"
|
|
"pure-admin/service"
|
|
)
|
|
|
|
// UpdateCategory
|
|
// @Summary 更新分类
|
|
// @Description
|
|
// @Tags category
|
|
// @Security ApiKeyAuth
|
|
// @Param data body request.UpdateCategory false "params"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
// @Router /category [put]
|
|
func UpdateCategory(c *gin.Context) {
|
|
var info request.UpdateCategory
|
|
err := c.ShouldBindJSON(&info)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
err = service.UpdateCategory(info.Id, info.Name)
|
|
if err != nil {
|
|
global.MG_LOG.Error("获取失败! " + err.Error())
|
|
response.FailWithMessage("操作失败", c)
|
|
return
|
|
}
|
|
response.OkWithMessage("操作成功", c)
|
|
}
|
|
|
|
// CreateCategory
|
|
// @Summary 创建分类
|
|
// @Description
|
|
// @Tags category
|
|
// @Security ApiKeyAuth
|
|
// @Param data body request.CreateCategory false "params"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
// @Router /category [post]
|
|
func CreateCategory(c *gin.Context) {
|
|
var info request.CreateCategory
|
|
err := c.ShouldBindJSON(&info)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
err = service.CreateCategory(info.Name, info.Pid, info.Layer)
|
|
if err != nil {
|
|
global.MG_LOG.Error("获取失败! " + err.Error())
|
|
response.FailWithMessage("操作失败", c)
|
|
}
|
|
response.OkWithMessage("操作成功", c)
|
|
}
|
|
|
|
// DeleteCategory
|
|
// @Summary 删除分类
|
|
// @Description
|
|
// @Tags category
|
|
// @Security ApiKeyAuth
|
|
// @Param data body request.IdsReq false "params"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
// @Router /category [delete]
|
|
func DeleteCategory(c *gin.Context) {
|
|
var info request.IdsReq
|
|
err := c.ShouldBindJSON(&info)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
if err := service.DeleteCategory(info.Ids); err != nil {
|
|
global.MG_LOG.Error("获取失败! " + err.Error())
|
|
response.FailWithMessage("操作失败", c)
|
|
} else {
|
|
response.OkWithMessage("操作成功", c)
|
|
}
|
|
}
|
|
|
|
// ListCategoryPage
|
|
// @Summary 商品分类分页
|
|
// @Description
|
|
// @Tags category
|
|
// @Security ApiKeyAuth
|
|
// @Param data query request.ListCategoryPage false "params"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
// @Router /category/list [get]
|
|
func ListCategoryPage(c *gin.Context) {
|
|
var info request.ListCategoryPage
|
|
_ = c.ShouldBindQuery(&info)
|
|
if info.Page <= 0 {
|
|
info.Page = 1
|
|
}
|
|
list, total, err := service.ListCategoryTree(info)
|
|
if err != nil {
|
|
global.MG_LOG.Error("获取失败! " + err.Error())
|
|
response.FailWithMessage("获取失败", c)
|
|
} else {
|
|
response.OkWithDetailed(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: info.Page,
|
|
PageSize: info.PageSize,
|
|
}, "获取成功", c)
|
|
}
|
|
}
|
|
|
|
// ListCategoryChildren
|
|
// @Summary 查询分类下级
|
|
// @Description
|
|
// @Tags category
|
|
// @Security ApiKeyAuth
|
|
// @Param data query request.ListCategoryChildren false "params"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
// @Router /category/children [get]
|
|
func ListCategoryChildren(c *gin.Context) {
|
|
var info request.ListCategoryChildren
|
|
err := c.ShouldBindQuery(&info)
|
|
if err != nil {
|
|
global.MG_LOG.Error(err.Error())
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
list, err := service.ListCategoryChildren(info.Pid)
|
|
if err != nil {
|
|
global.MG_LOG.Error("获取失败! " + err.Error())
|
|
response.FailWithMessage("获取失败", c)
|
|
return
|
|
}
|
|
response.OkWithDetailed(list, "获取成功", c)
|
|
}
|
|
// GetCategoryItem
|
|
// @Summary 查询单个商品分类
|
|
// @Description
|
|
// @Tags category
|
|
// @Security ApiKeyAuth
|
|
// @Param data body request.IdReq false "params"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
// @Router /category [get]
|
|
func GetCategoryItem(c *gin.Context) {
|
|
var info request.IdReq
|
|
_ = c.ShouldBindQuery(&info)
|
|
item, err := service.GetCategoryTree(int64(info.ID))
|
|
if err != nil {
|
|
global.MG_LOG.Error("获取失败! " + err.Error())
|
|
response.FailWithMessage("获取失败", c)
|
|
} else {
|
|
response.OkWithDetailed(item, "获取成功", c)
|
|
}
|
|
}
|