154 lines
6.6 KiB
Go
154 lines
6.6 KiB
Go
package controllers
|
||
|
||
import (
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||
"git.rosy.net.cn/jx-callback/business/model"
|
||
"github.com/astaxie/beego"
|
||
)
|
||
|
||
type SkuController struct {
|
||
beego.Controller
|
||
}
|
||
|
||
// @Title 得到厂商商品类别
|
||
// @Description 得到厂商商品类别(区别于商家SKU类别)
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorID query int true "厂商ID"
|
||
// @Param parentID query int false "父ID,-1表示所有,缺省为-1"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetVendorCategories [get]
|
||
func (c *SkuController) GetVendorCategories() {
|
||
c.callGetVendorCategories(func(params *tSkuGetVendorCategoriesParams) (retVal interface{}, errCode string, err error) {
|
||
if c.GetString("parentID") == "" {
|
||
params.ParentID = -1
|
||
}
|
||
retVal, err = cms.GetVendorCategories(params.VendorID, params.ParentID)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到商品相关的一些基础信息
|
||
// @Description 得到商品相关的一些基础信息,包括unit列表,specUnit列表
|
||
// @Param token header string true "认证token"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetSkuMetaInfo [get]
|
||
func (c *SkuController) GetSkuMetaInfo() {
|
||
c.callGetSkuMetaInfo(func(params *tSkuGetSkuMetaInfoParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = cms.GetSkuMetaInfo()
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到商品类别
|
||
// @Description 得到商品类别(区别于厂商家SKU类别)
|
||
// @Param token header string true "认证token"
|
||
// @Param parentID query int false "父ID,-1表示所有,缺省为-1"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetCategories [get]
|
||
func (c *SkuController) GetCategories() {
|
||
c.callGetCategories(func(params *tSkuGetCategoriesParams) (retVal interface{}, errCode string, err error) {
|
||
if c.GetString("parentID") == "" {
|
||
params.ParentID = -1
|
||
}
|
||
retVal, err = cms.GetCategories(params.ParentID)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 新增商品类别
|
||
// @Description 新增商品类别(区别于厂商家SKU类别)
|
||
// @Param token header string true "认证token"
|
||
// @Param payload formData string true "json数据,skuCategory对象()"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /AddCategory [post]
|
||
func (c *SkuController) AddCategory() {
|
||
c.callAddCategory(func(params *tSkuAddCategoryParams) (retVal interface{}, errCode string, err error) {
|
||
cat := &model.SkuCategory{}
|
||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), cat); err == nil {
|
||
retVal, err = cms.AddCategory(cat, GetUserNameFromToken(params.Token))
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 修改商品类别
|
||
// @Description 修改商品类别(区别于厂商家SKU类别)
|
||
// @Param token header string true "认证token"
|
||
// @Param categoryID formData int true "类别ID,payload中的相应字段会被忽略"
|
||
// @Param payload formData string true "json数据,skuCategory对象()"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /UpdateCategory [put]
|
||
func (c *SkuController) UpdateCategory() {
|
||
c.callUpdateCategory(func(params *tSkuUpdateCategoryParams) (retVal interface{}, errCode string, err error) {
|
||
payload := make(map[string]interface{})
|
||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &payload); err == nil {
|
||
retVal, err = cms.UpdateCategory(params.CategoryID, payload, GetUserNameFromToken(params.Token))
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 商品类别重排序
|
||
// @Description 商品类别重排序(区别于厂商家SKU类别)
|
||
// @Param token header string true "认证token"
|
||
// @Param categoryID formData int true "父ID"
|
||
// @Param ids formData string true "同一父类别下的所有子类别ID列表([1,2,3,4])"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /ReorderCategories [put]
|
||
func (c *SkuController) ReorderCategories() {
|
||
c.callReorderCategories(func(params *tSkuReorderCategoriesParams) (retVal interface{}, errCode string, err error) {
|
||
var idList []int
|
||
if err = utils.UnmarshalUseNumber([]byte(params.Ids), &idList); err == nil {
|
||
err = cms.ReorderCategories(params.CategoryID, idList, GetUserNameFromToken(params.Token))
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 删除商品类别
|
||
// @Description 删除商品类别,只有无商品且无子类别的才能删除
|
||
// @Param token header string true "认证token"
|
||
// @Param categoryID query int true "商品类别ID"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /DeleteCategory [delete]
|
||
func (c *SkuController) DeleteCategory() {
|
||
c.callDeleteCategory(func(params *tSkuDeleteCategoryParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = cms.DeleteCategory(params.CategoryID, false, GetUserNameFromToken(params.Token))
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到京西门店信息
|
||
// @Description 得到京西门店信息,如下条件之间是与的关系
|
||
// @Param token header string true "认证token"
|
||
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
|
||
// @Param id query int false "SkuName ID"
|
||
// @Param name query string false "商品名称(不要求完全一致)"
|
||
// @Param prefix query string false "商品前缀(不要求完全一致)"
|
||
// @Param placeCode query int false "可售地点Code"
|
||
// @Param isGlobal query bool false "是否全球可售"
|
||
// @Param categoryID query int false "商品所属类别ID"
|
||
// @Param unit query string false "商品单位"
|
||
// @Param jdID query int false "商品京东ID"
|
||
// @Param fromStatus query int false "查询起始状态(0:正常,1:下架)"
|
||
// @Param toStatus query int false "查询结束状态(0:正常,1:下架)"
|
||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||
// @Param pageSize query int false "门店列表页大小(缺省为50)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetSkuNames [get]
|
||
func (c *SkuController) GetSkuNames() {
|
||
c.callGetSkuNames(func(params *tSkuGetSkuNamesParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = cms.GetSkuNames(params.Keyword, params.MapData, params.Offset, params.PageSize)
|
||
return retVal, "", err
|
||
})
|
||
}
|