- combile SearchStores and GetStores to one func.
This commit is contained in:
@@ -60,15 +60,29 @@ func UpdatePlaces(places []*model.Place, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetStores(params map[string]interface{}, offset, pageSize int) (retVal []*StoreExt, err error) {
|
||||
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal []*StoreExt, err error) {
|
||||
sql := `
|
||||
SELECT t1.*, city.name city_name, district.name district_name
|
||||
FROM store t1
|
||||
LEFT JOIN place city ON t1.city_code = city.code AND city.level = 2
|
||||
LEFT JOIN place district ON t1.district_code = district.code AND district.level = 3
|
||||
WHERE 1 = 1`
|
||||
WHERE`
|
||||
|
||||
params2 := make([]interface{}, 0)
|
||||
if keyword != "" {
|
||||
sql += " (t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ?"
|
||||
keywordLike := "%" + keyword + "%"
|
||||
params2 = append(params2, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
sql += " OR t1.id = ? OR t1.city_code = ? OR t1.district_code = ? OR t1.lng = ? OR t1.lat = ?"
|
||||
params2 = append(params2, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64)
|
||||
}
|
||||
sql += ")"
|
||||
} else {
|
||||
sql += " 1 = 1"
|
||||
}
|
||||
|
||||
if params["id"] != nil {
|
||||
sql += " AND t1.id = ?"
|
||||
params2 = append(params2, params["id"].(int))
|
||||
@@ -122,39 +136,6 @@ func GetStores(params map[string]interface{}, offset, pageSize int) (retVal []*S
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func SearchStores(keyword string, fromStatus, toStatus int, offset, pageSize int) (retVal []*StoreExt, err error) {
|
||||
sql := `
|
||||
SELECT t1.*, city.name city_name, district.name district_name
|
||||
FROM store t1
|
||||
LEFT JOIN place city ON t1.city_code = city.code AND city.level = 2
|
||||
LEFT JOIN place district ON t1.district_code = district.code AND district.level = 3
|
||||
WHERE t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ?`
|
||||
keywordLike := "%" + keyword + "%"
|
||||
params := []interface{}{keywordLike, keywordLike, keywordLike, keywordLike, keywordLike}
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
sql += " OR t1.id = ? OR t1.city_code = ? OR t1.district_code = ? OR t1.lng = ? OR t1.lat = ?"
|
||||
params = append(params, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64)
|
||||
}
|
||||
|
||||
sql += " AND t1.status >= ? AND t1.status <= ?"
|
||||
params = append(params, fromStatus, toStatus)
|
||||
|
||||
sql += `
|
||||
ORDER BY id
|
||||
LIMIT ? OFFSET ?`
|
||||
if pageSize == 0 {
|
||||
pageSize = model.DefPageSize
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
params = append(params, pageSize, offset)
|
||||
|
||||
err = dao.GetRows(nil, &retVal, sql, params...)
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err error) {
|
||||
handler := basesch.FixedBaseScheduler.GetPurchasePlatformFromVendorID(vendorID)
|
||||
if handler != nil {
|
||||
|
||||
@@ -54,6 +54,7 @@ func (c *StoreController) UpdatePlaces() {
|
||||
// @Title 得到京西门店信息
|
||||
// @Description 得到京西门店信息,如下条件之间是与的关系
|
||||
// @Param token header string true "认证token"
|
||||
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
|
||||
// @Param id query int false "门店ID"
|
||||
// @Param name query string false "门店名称(不要求完全一致)"
|
||||
// @Param placeID query int false "所属地点ID"
|
||||
@@ -69,31 +70,7 @@ func (c *StoreController) UpdatePlaces() {
|
||||
// @router /GetStores [get]
|
||||
func (c *StoreController) GetStores() {
|
||||
c.callGetStores(func(params *tStoreGetStoresParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetStores(params.MapData, params.Offset, params.PageSize)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 查询京西门店信息
|
||||
// @Description 查询京西门店信息,根据关键字查询门店,如果关键字可以转换成数字,还会尝试数值相关的信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param keyword query string true "查询关键字"
|
||||
// @Param fromStatus query int false "起始状态(缺省为营业中状态)"
|
||||
// @Param toStatus query int false "结束状态"
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SearchStores [get]
|
||||
func (c *StoreController) SearchStores() {
|
||||
c.callSearchStores(func(params *tStoreSearchStoresParams) (retVal interface{}, errCode string, err error) {
|
||||
if params.MapData["fromStatus"] == nil {
|
||||
params.FromStatus = 1
|
||||
}
|
||||
if params.MapData["toStatus"] == nil {
|
||||
params.ToStatus = params.FromStatus
|
||||
}
|
||||
retVal, err = cms.SearchStores(params.Keyword, params.FromStatus, params.ToStatus, params.Offset, params.PageSize)
|
||||
retVal, err = cms.GetStores(params.Keyword, params.MapData, params.Offset, params.PageSize)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -159,14 +159,6 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SearchStores",
|
||||
Router: `/SearchStores`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdatePlaces",
|
||||
|
||||
Reference in New Issue
Block a user