Files
jx-callback/controllers/cms_store.go
2018-09-12 19:04:19 +08:00

231 lines
11 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package controllers
import (
"errors"
"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 StoreController struct {
beego.Controller
}
// @Title 得到地点(省,城市,区)信息
// @Description parentCode与vendorID必传入一个vendorID的意思是得到所有与这个厂商相关的城市列表。地点级别省为1市为2区为3注意直辖市也要分省与市级
// @Param token header string true "认证token"
// @Param parentCode query int false "上级地点code这个指的是国家标准CODE中国为100000北京为110000北京市为110100不是数据库中的ID"
// @Param vendorID query int false "得到所有与这个厂商相关的省与城市列表"
// @Param includeDisabled query bool false "是否包括禁用的城市(缺省不包括)"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetPlaces [get]
func (c *StoreController) GetPlaces() {
c.callGetPlaces(func(params *tStoreGetPlacesParams) (retVal interface{}, errCode string, err error) {
if c.GetString("vendorID") == "" {
params.VendorID = -1 // -1表示没有指定因为0表示京东到家
}
if params.VendorID == -1 && params.ParentCode == 0 {
return nil, "", errors.New("parentCode与vendorID至少要指定一个")
}
retVal, err = cms.GetPlaces(params.ParentCode, params.VendorID, params.IncludeDisabled)
return retVal, "", err
})
}
// @Title 批量修改地点信息
// @Description 只支持修改enabled, jd_code和mtps_price这三个属性
// @Param token header string true "认证token"
// @Param payload formData string true "json数据place对象数组"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdatePlaces [put]
func (c *StoreController) UpdatePlaces() {
c.callUpdatePlaces(func(params *tStoreUpdatePlacesParams) (retVal interface{}, errCode string, err error) {
placeList := make([]map[string]interface{}, 0)
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &placeList); err == nil {
retVal, err = cms.UpdatePlaces(placeList, GetUserNameFromToken(params.Token))
}
return retVal, "", err
})
}
// @Title 修改地点信息
// @Description 只支持修改enabled, jd_code和mtps_price这三个属性
// @Param token header string true "认证token"
// @Param code formData int true "地点编号注意是code不是IDpayload中的code会被忽略"
// @Param payload formData string true "json数据place对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdatePlace [put]
func (c *StoreController) UpdatePlace() {
c.callUpdatePlace(func(params *tStoreUpdatePlaceParams) (retVal interface{}, errCode string, err error) {
place := make(map[string]interface{}, 0)
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &place); err == nil {
retVal, err = cms.UpdatePlace(params.Code, place, GetUserNameFromToken(params.Token))
}
return retVal, "", err
})
}
// @Title 得到京西门店信息
// @Description 得到京西门店信息,如下条件之间是与的关系
// @Param token header string true "认证token"
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
// @Param storeID query int false "门店ID"
// @Param name query string false "门店名称(不要求完全一致)"
// @Param placeID query int false "所属地点ID"
// @Param placeLevel query int false "所属地点级别"
// @Param address query string false "门店地址"
// @Param tel query string false "电话"
// @Param fromStatus query int false "查询起始状态(-1禁用0休息关店1正常开店"
// @Param toStatus query int false "查询结束状态(-1禁用0休息关店1正常开店"
// @Param vendorStoreCond query string false "查询关联门店的条件andor指的是jdCondelmCondebaiCod这三个条件间的关系这组条件与其它条件都是与的关系"
// @Param jdCond query int false "京东关联条件,-1没有关联0不限定1有关联缺省为0"
// @Param elmCond query int false "饿了么关联条件,-1没有关联0不限定1有关联缺省为0"
// @Param ebaiCond query int false "饿百关联条件,-1没有关联0不限定1有关联缺省为0"
// @Param offset query int false "门店列表起始序号以0开始缺省为0"
// @Param pageSize query int false "门店列表页大小缺省为50"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetStores [get]
func (c *StoreController) GetStores() {
c.callGetStores(func(params *tStoreGetStoresParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetStores(params.Keyword, params.MapData, params.Offset, params.PageSize)
return retVal, "", err
})
}
// @Title 远程查询厂商门店信息
// @Description 远程查询厂商门店信息这个是实时调用API远程查询
// @Param token header string true "认证token"
// @Param vendorStoreID query string true "门店ID"
// @Param vendorID query int true "门店所属的厂商ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetVendorStore [get]
func (c *StoreController) GetVendorStore() {
c.callGetVendorStore(func(params *tStoreGetVendorStoreParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetVendorStore(params.VendorStoreID, params.VendorID)
return retVal, "", err
})
}
// @Title 修改门店信息
// @Description 修改门店信息
// @Param token header string true "认证token"
// @Param storeID formData int true "京西门店编号payload中的京西门店编号会被忽略"
// @Param payload formData string true "json数据store对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateStore [put]
func (c *StoreController) UpdateStore() {
c.callUpdateStore(func(params *tStoreUpdateStoreParams) (retVal interface{}, errCode string, err error) {
store := make(map[string]interface{})
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &store); err == nil {
retVal, err = cms.UpdateStore(params.StoreID, store, GetUserNameFromToken(params.Token))
}
return retVal, "", err
})
}
// @Title 创建京西门店
// @Description 创建京西门店
// @Param token header string true "认证token"
// @Param payload formData string true "json数据store对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateStore [post]
func (c *StoreController) CreateStore() {
c.callCreateStore(func(params *tStoreCreateStoreParams) (retVal interface{}, errCode string, err error) {
store := &model.Store{}
if err = utils.UnmarshalUseNumber([]byte(params.Payload), store); err == nil {
retVal, err = cms.CreateStore(store, GetUserNameFromToken(params.Token))
}
return retVal, "", err
})
}
// @Title 空方法,占位用
// @Description 空方法,占位用
// @Param token header string true "认证token"
// @Param payload formData string true "json数据store对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ZZZZZ [put]
func (c *StoreController) ZZZZZ() {
}
// @Title 得到门店映射信息
// @Description 得到门店映射信息
// @Param token header string true "认证token"
// @Param storeID query int true "门店ID"
// @Param vendorID query int false "厂商ID缺省为全部"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetStoreVendorMaps [get]
func (c *StoreController) GetStoreVendorMaps() {
c.callGetStoreVendorMaps(func(params *tStoreGetStoreVendorMapsParams) (retVal interface{}, errCode string, err error) {
if c.GetString("vendorID") == "" {
params.VendorID = -1
}
retVal, err = cms.GetStoreVendorMaps(nil, params.StoreID, params.VendorID)
return retVal, "", err
})
}
// @Title 修改门店映射信息
// @Description 修改门店映射信息
// @Param token header string true "认证token"
// @Param storeID query int true "门店IDpayload中的相应字段会被忽略"
// @Param vendorID query int true "厂商IDpayload中的相应字段会被忽略"
// @Param payload formData string true "json数据storeMap对象"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateStoreVendorMap [put]
func (c *StoreController) UpdateStoreVendorMap() {
c.callUpdateStoreVendorMap(func(params *tStoreUpdateStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
storeMap := make(map[string]interface{})
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &storeMap); err == nil {
retVal, err = cms.UpdateStoreVendorMap(nil, params.StoreID, params.VendorID, storeMap, GetUserNameFromToken(params.Token))
}
return retVal, "", err
})
}
// @Title 新增门店映射信息
// @Description 新增门店映射信息
// @Param token header string true "认证token"
// @Param storeID formData int true "门店IDpayload中的相应字段会被忽略"
// @Param vendorID formData int true "厂商IDpayload中的相应字段会被忽略"
// @Param payload formData string true "json数据storeMap对象({'vendorID':0,'vendorStoreID':'11732425','autoPickup':1,'deliveryCompetition':1, 'pricePercentage':100})"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /AddStoreVendorMap [post]
func (c *StoreController) AddStoreVendorMap() {
c.callAddStoreVendorMap(func(params *tStoreAddStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
storeMap := &model.StoreMap{}
if err = utils.UnmarshalUseNumber([]byte(params.Payload), storeMap); err == nil {
retVal, err = cms.AddStoreVendorMap(nil, params.StoreID, params.VendorID, storeMap, GetUserNameFromToken(params.Token))
}
return retVal, "", err
})
}
// @Title 删除门店映射信息
// @Description 删除门店映射信息
// @Param token header string true "认证token"
// @Param storeID query int true "门店ID"
// @Param vendorID query int true "厂商ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /DeleteStoreVendorMap [delete]
func (c *StoreController) DeleteStoreVendorMap() {
c.callDeleteStoreVendorMap(func(params *tStoreDeleteStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.DeleteStoreVendorMap(nil, params.StoreID, params.VendorID, GetUserNameFromToken(params.Token))
return retVal, "", err
})
}