- 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 {
|
||||
|
||||
Reference in New Issue
Block a user