+ QueryPageStores
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
@@ -275,12 +276,7 @@ func IsEmptyID(id int64) bool {
|
||||
}
|
||||
|
||||
func FormalizePageSize(pageSize int) int {
|
||||
if pageSize == 0 {
|
||||
return model.DefPageSize
|
||||
} else if pageSize < 0 {
|
||||
return model.UnlimitedPageSize
|
||||
}
|
||||
return pageSize
|
||||
return dao.FormalizePageSize(pageSize)
|
||||
}
|
||||
|
||||
func FormalizeName(name string) string {
|
||||
|
||||
@@ -172,3 +172,12 @@ func value2Value(srcValue, dstValue reflect.Value, copyType int) {
|
||||
func IsVendorThingIDEmpty(vendorThingID string) bool {
|
||||
return vendorThingID == "" || vendorThingID == "0"
|
||||
}
|
||||
|
||||
func FormalizePageSize(pageSize int) int {
|
||||
if pageSize == 0 {
|
||||
return model.DefPageSize
|
||||
} else if pageSize < 0 {
|
||||
return model.UnlimitedPageSize
|
||||
}
|
||||
return pageSize
|
||||
}
|
||||
|
||||
90
business/model/dao/page_store.go
Normal file
90
business/model/dao/page_store.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type PageShopWithPlaceName struct {
|
||||
model.PageShop
|
||||
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
}
|
||||
|
||||
func QueryPageStores(db *DaoDB, pageSize, offset int, keyword string, vendorStoreID string, vendorID int, cityCode, districtCode int, tel string, minShopScore float32, minRecentOrderNum, minSkuCount int) (pagedInfo *model.PagedInfo, err error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*,
|
||||
t2.name city_name, t3.name district_name
|
||||
FROM page_shop t1
|
||||
LEFT JOIN place t2 ON t2.code = t1.city_code
|
||||
LEFT JOIN place t3 ON t3.code = t1.district_code
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
|
||||
if vendorStoreID != "" {
|
||||
sql += " AND t1.vendor_store_id = ?"
|
||||
sqlParams = append(sqlParams, vendorStoreID)
|
||||
}
|
||||
if vendorID != -1 {
|
||||
sql += " AND t1.vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if cityCode != 0 {
|
||||
sql += " AND t1.city_code = ?"
|
||||
sqlParams = append(sqlParams, cityCode)
|
||||
}
|
||||
if districtCode != 0 {
|
||||
sql += " AND t1.district_code = ?"
|
||||
sqlParams = append(sqlParams, districtCode)
|
||||
}
|
||||
if tel != "" {
|
||||
sql += " AND t1.tel1 = ?"
|
||||
sqlParams = append(sqlParams, tel)
|
||||
}
|
||||
if minShopScore > 0 {
|
||||
sql += " AND t1.shop_score >= ?"
|
||||
sqlParams = append(sqlParams, minShopScore)
|
||||
}
|
||||
if minRecentOrderNum > 0 {
|
||||
sql += " AND t1.recent_order_num >= ?"
|
||||
sqlParams = append(sqlParams, minRecentOrderNum)
|
||||
}
|
||||
if minSkuCount > 0 {
|
||||
sql += " AND t1.sku_count >= ?"
|
||||
sqlParams = append(sqlParams, minSkuCount)
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND (t1.name LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.org_code LIKE ? OR t1.address LIKE ? OR t2.name LIKE ? OR t3.name LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
sql += ")"
|
||||
}
|
||||
sql += `
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
pageSize = FormalizePageSize(pageSize)
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
var shopList []*PageShopWithPlaceName
|
||||
Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if err = GetRows(db, &shopList, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
Data: shopList,
|
||||
}
|
||||
Commit(db)
|
||||
} else {
|
||||
Rollback(db)
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
Reference in New Issue
Block a user