- return totalCount for GetStores.
This commit is contained in:
@@ -19,6 +19,11 @@ type StoreExt struct {
|
||||
DistrictName string `json:"districtName"`
|
||||
}
|
||||
|
||||
type StoresInfo struct {
|
||||
TotalCount int `json:"totalCount"`
|
||||
Stores []*StoreExt `json:"stores"`
|
||||
}
|
||||
|
||||
var (
|
||||
ErrMissingInput = errors.New("没有有效的输入参数")
|
||||
ErrCanNotVendor = errors.New("vendorID参数不合法")
|
||||
@@ -60,9 +65,8 @@ func UpdatePlaces(places []*model.Place, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal []*StoreExt, err error) {
|
||||
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, 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
|
||||
@@ -121,19 +125,29 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
sql += " AND t1.status >= ? AND t1.status <= ?"
|
||||
params2 = append(params2, fromStatus, toStatus)
|
||||
}
|
||||
sql += `
|
||||
sqlCount := "SELECT COUNT(*) ct\n" + sql
|
||||
type tcount struct {
|
||||
Ct int
|
||||
}
|
||||
countInfo := []tcount{}
|
||||
if err = dao.GetRows(nil, &countInfo, sqlCount, params2...); err == nil {
|
||||
sqlData := "SELECT t1.*, city.name city_name, district.name district_name\n" + sql + `
|
||||
ORDER BY id
|
||||
LIMIT ? OFFSET ?`
|
||||
if pageSize == 0 {
|
||||
pageSize = model.DefPageSize
|
||||
if pageSize == 0 {
|
||||
pageSize = model.DefPageSize
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
params2 = append(params2, pageSize, offset)
|
||||
retVal := &StoresInfo{
|
||||
TotalCount: countInfo[0].Ct,
|
||||
}
|
||||
err = dao.GetRows(nil, &retVal.Stores, sqlData, params2...)
|
||||
return retVal, err
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
params2 = append(params2, pageSize, offset)
|
||||
|
||||
err = dao.GetRows(nil, &retVal, sql, params2...)
|
||||
return retVal, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err error) {
|
||||
|
||||
Reference in New Issue
Block a user