package router

import (
	"demo/data/dao"
	"demo/data/domain"
	"demo/share"
	"github.com/gin-gonic/gin"
	"github.com/mitchellh/mapstructure"
)

// BackGoodsRouter 废弃
func BackGoodsRouter(engine *gin.RouterGroup) {
	user := engine.Group("/back/goods")
	PushRouter(user, "POST", "/sort", SortSku)
}

func SortSku(c *gin.Context) {
	data := share.GetJsonAnyParam(c)
	list, _ := data("sortList")
	sorts := make([]domain.SkuSort, 0)

	err := mapstructure.Decode(list, &sorts)
	if err != nil {
		c.JSON(200, CreateResultError(400, "参数解析错误"))

		return
	}
	err = dao.SortSkuList(sorts)
	if err != nil {
		c.JSON(200, CreateResultError(400, "排序失败"))
		return
	}
	c.JSON(200, CreateResult())
}
