- GetPlaces don't support vendorID.

This commit is contained in:
gazebo
2018-09-17 21:31:06 +08:00
parent 6c683d5cf2
commit 80d76ba94f
2 changed files with 8 additions and 21 deletions

View File

@@ -29,20 +29,16 @@ var (
ErrCanNotFindVendor = errors.New("vendorID参数不合法") ErrCanNotFindVendor = errors.New("vendorID参数不合法")
) )
func GetPlaces(parentCode int, vendorID int, includeDisabled bool) ([]*model.Place, error) { func GetPlaces(parentCode int, includeDisabled bool) ([]*model.Place, error) {
db := dao.GetDB() db := dao.GetDB()
places := []*model.Place{} places := []*model.Place{}
sql := "SELECT * FROM place WHERE enabled = 1 " cond := map[string]interface{}{
if includeDisabled { "ParentCode": parentCode,
sql = "1 = 1 "
} }
if vendorID >= 0 { if !includeDisabled {
if vendorID == model.VendorIDJD { cond["Enabled"] = 1
return places, dao.GetRows(db, &places, sql+"AND jd_code <> 0 AND level >= 2")
} }
return nil, ErrHaveNotImplementedYet return places, dao.GetEntities(db, &places, cond, false)
}
return places, dao.GetRows(db, &places, sql+"AND parent_code = ?", parentCode)
} }
func UpdatePlaces(places []map[string]interface{}, userName string) (num int64, err error) { func UpdatePlaces(places []map[string]interface{}, userName string) (num int64, err error) {

View File

@@ -1,8 +1,6 @@
package controllers package controllers
import ( import (
"errors"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
@@ -16,21 +14,14 @@ type StoreController struct {
// @Title 得到地点(省,城市,区)信息 // @Title 得到地点(省,城市,区)信息
// @Description parentCode与vendorID必传入一个vendorID的意思是得到所有与这个厂商相关的城市列表。地点级别省为1市为2区为3注意直辖市也要分省与市级 // @Description parentCode与vendorID必传入一个vendorID的意思是得到所有与这个厂商相关的城市列表。地点级别省为1市为2区为3注意直辖市也要分省与市级
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Param parentCode query int false "上级地点code这个指的是国家标准CODE中国为100000北京为110000北京市为110100不是数据库中的ID" // @Param parentCode query int true "上级地点code这个指的是国家标准CODE中国为100000北京为110000北京市为110100不是数据库中的ID"
// @Param vendorID query int false "得到所有与这个厂商相关的省与城市列表"
// @Param includeDisabled query bool false "是否包括禁用的城市(缺省不包括)" // @Param includeDisabled query bool false "是否包括禁用的城市(缺省不包括)"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult
// @router /GetPlaces [get] // @router /GetPlaces [get]
func (c *StoreController) GetPlaces() { func (c *StoreController) GetPlaces() {
c.callGetPlaces(func(params *tStoreGetPlacesParams) (retVal interface{}, errCode string, err error) { c.callGetPlaces(func(params *tStoreGetPlacesParams) (retVal interface{}, errCode string, err error) {
if c.GetString("vendorID") == "" { retVal, err = cms.GetPlaces(params.ParentCode, params.IncludeDisabled)
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 return retVal, "", err
}) })
} }