From 66ddae2162b8bb401ba394e8a8682f8a31d5b9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 6 Aug 2020 11:43:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=A1=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/common/common.go | 42 +++++++++++++++++++++++++++ controllers/cms_store.go | 14 +++++++++ routers/commentsRouter_controllers.go | 9 ++++++ 3 files changed, 65 insertions(+) diff --git a/business/jxstore/common/common.go b/business/jxstore/common/common.go index 8e236f12b..072f1bf0b 100644 --- a/business/jxstore/common/common.go +++ b/business/jxstore/common/common.go @@ -61,6 +61,48 @@ func (x Store4UserList) Swap(i, j int) { x[i], x[j] = x[j], x[i] } +func GetNearSupplyGoodsStoreByStoreID(ctx *jxcontext.Context, storeID int) (store *model.Store, err error) { + var ( + stores []*model.Store + db = dao.GetDB() + ) + stores2, _ := dao.GetStoreList(db, []int{storeID}, nil, nil, nil, "") + store2 := stores2[0] + sql := ` + SELECT a.* + FROM store a + JOIN store_map b ON b.store_id = a.id + JOIN store c ON c.city_code = a.city_code AND c.id = ? + WHERE a.deleted_at = ? + AND b.deleted_at = ? + AND b.vendor_id = ? + AND b.is_supply_goods = ? + AND a.status = ? + ` + sqlParams := []interface{}{ + storeID, + utils.DefaultTimeValue, utils.DefaultTimeValue, + model.VendorIDJX, model.YES, model.StoreStatusOpened, + } + err = dao.GetRows(db, &stores, sql, sqlParams) + if len(stores) > 0 { + realDistance := float64(0) + for _, v := range stores { + distance := jxutils.EarthDistance(jxutils.IntCoordinate2Standard(v.Lng), jxutils.IntCoordinate2Standard(v.Lat), jxutils.IntCoordinate2Standard(store2.Lng), jxutils.IntCoordinate2Standard(store2.Lat)) + if realDistance == 0 { + realDistance = distance + store = v + } else { + if realDistance > distance { + realDistance = distance + store = v + } + } + } + } + return store, err +} + func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, maxRadius int, needWalkDistance, isJds bool) (storeList []*Store4User, err error) { const ( maxStoreCount4User = 5 diff --git a/controllers/cms_store.go b/controllers/cms_store.go index d265ac08f..eb65996a1 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -794,3 +794,17 @@ func (c *StoreController) UpdateStorePricePack() { return retVal, "", err }) } + +// @Title 根据门店获取距离最近的货源店铺 +// @Description 修根据门店获取距离最近的货源店铺 +// @Param token header string true "认证token" +// @Param storeID query int true "门店ID" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetNearSupplyGoodsStoreByStoreID [get] +func (c *StoreController) GetNearSupplyGoodsStoreByStoreID() { + c.callGetNearSupplyGoodsStoreByStoreID(func(params *tStoreGetNearSupplyGoodsStoreByStoreIDParams) (retVal interface{}, errCode string, err error) { + retVal, err = common.GetNearSupplyGoodsStoreByStoreID(params.Ctx, params.StoreID) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index d0f89c7bf..940482211 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1746,6 +1746,15 @@ func init() { Filters: nil, 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: "GetNearSupplyGoodsStoreByStoreID", + Router: `/GetNearSupplyGoodsStoreByStoreID`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + 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: "GetStoreAlertList",