diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 90de001ea..50a4c9d9f 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -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 { diff --git a/business/model/dao/dao_utils.go b/business/model/dao/dao_utils.go index 8b3c70c7f..368fb0268 100644 --- a/business/model/dao/dao_utils.go +++ b/business/model/dao/dao_utils.go @@ -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 +} diff --git a/business/model/dao/page_store.go b/business/model/dao/page_store.go new file mode 100644 index 000000000..8efc7db50 --- /dev/null +++ b/business/model/dao/page_store.go @@ -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 +} diff --git a/controllers/net_spider.go b/controllers/net_spider.go index a5dcafdce..23b30dd81 100644 --- a/controllers/net_spider.go +++ b/controllers/net_spider.go @@ -2,6 +2,7 @@ package controllers import ( "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/netspider" "github.com/astaxie/beego" ) @@ -30,3 +31,30 @@ func (c *NetSpiderController) GetAndStoreCitiesShops() { return retVal, "", err }) } + +// @Title 同步商家商品信息 +// @Description 同步商家商品信息 +// @Param token header string true "认证token" +// @Param offset query int false "列表起始序号(以0开始,缺省为0)" +// @Param pageSize query int false "列表页大小(缺省为50,-1表示全部)" +// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)" +// @Param vendorStoreID query string false "门店号" +// @Param vendorID query int false "平台ID" +// @Param cityCode query int false "城市代码" +// @Param districtCode query int false "行政区代码" +// @Param tel query string false "手机号" +// @Param minShopScore query float64 false "门店分值最小值" +// @Param minRecentOrderNum query int false "最近单量最小值" +// @Param minSkuCount query int false "SKU数量最小值" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /QueryPageStores [get] +func (c *NetSpiderController) QueryPageStores() { + c.callQueryPageStores(func(params *tNetspiderQueryPageStoresParams) (retVal interface{}, errCode string, err error) { + if params.MapData["vendorID"] == nil { + params.VendorID = -1 + } + retVal, err = dao.QueryPageStores(dao.GetDB(), params.PageSize, params.Offset, params.Keyword, params.VendorStoreID, params.VendorID, params.CityCode, params.DistrictCode, params.Tel, float32(params.MinShopScore), params.MinRecentOrderNum, params.MinSkuCount) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 7f47c0b4a..733f22671 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -520,6 +520,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:NetSpiderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:NetSpiderController"], + beego.ControllerComments{ + Method: "QueryPageStores", + Router: `/QueryPageStores`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"], beego.ControllerComments{ Method: "AcceptOrRefuseFailedGetOrder",