GetStoreListByLocation
This commit is contained in:
@@ -61,6 +61,30 @@ type StoreExt struct {
|
|||||||
OrderCount int `json:"orderCount"`
|
OrderCount int `json:"orderCount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Store4User struct {
|
||||||
|
model.Store
|
||||||
|
FloatLng float64 `json:"lng"`
|
||||||
|
FloatLat float64 `json:"lat"`
|
||||||
|
CityName string `json:"cityName"`
|
||||||
|
DistrictName string `json:"districtName"`
|
||||||
|
|
||||||
|
Distance int `json:"distance"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Store4UserList []*Store4User
|
||||||
|
|
||||||
|
func (x Store4UserList) Len() int {
|
||||||
|
return len(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x Store4UserList) Less(i, j int) bool {
|
||||||
|
return x[i].Distance < x[j].Distance
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x Store4UserList) Swap(i, j int) {
|
||||||
|
x[i], x[j] = x[j], x[i]
|
||||||
|
}
|
||||||
|
|
||||||
type StoresInfo struct {
|
type StoresInfo struct {
|
||||||
TotalCount int `json:"totalCount"`
|
TotalCount int `json:"totalCount"`
|
||||||
MapCenterLng float64 `json:"mapCenterLng"`
|
MapCenterLng float64 `json:"mapCenterLng"`
|
||||||
@@ -2003,3 +2027,61 @@ func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContin
|
|||||||
}
|
}
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64) (storeList []*Store4User, err error) {
|
||||||
|
const (
|
||||||
|
maxRadius = 5000
|
||||||
|
maxStoreCount4User = 5
|
||||||
|
)
|
||||||
|
|
||||||
|
lng2, _ := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 90)
|
||||||
|
_, lat2 := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 0)
|
||||||
|
lng1 := lng - (lng2 - lng)
|
||||||
|
lat1 := lat - (lat2 - lat)
|
||||||
|
// globals.SugarLogger.Debugf("%f,%f,%f,%f\n", lng1, lng2, lat1, lat2)
|
||||||
|
sql := `
|
||||||
|
SELECT t1.*,
|
||||||
|
city.name city_name
|
||||||
|
FROM store t1
|
||||||
|
JOIN place city ON city.code = t1.city_code
|
||||||
|
WHERE t1.deleted_at = ? AND t1.status <> ? AND t1.lng > ? AND t1.lng < ? AND t1.lat > ? AND t1.lat < ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
model.StoreStatusDisabled,
|
||||||
|
jxutils.StandardCoordinate2Int(lng1),
|
||||||
|
jxutils.StandardCoordinate2Int(lng2),
|
||||||
|
jxutils.StandardCoordinate2Int(lat1),
|
||||||
|
jxutils.StandardCoordinate2Int(lat2),
|
||||||
|
}
|
||||||
|
|
||||||
|
var storeList1 []*Store4User
|
||||||
|
if err = dao.GetRows(dao.GetDB(), &storeList1, sql, sqlParams...); err == nil {
|
||||||
|
var storeList2 []*Store4User
|
||||||
|
for _, v := range storeList1 {
|
||||||
|
isStoreOK := false
|
||||||
|
v.FloatLng = jxutils.IntCoordinate2Standard(v.Lng)
|
||||||
|
v.FloatLat = jxutils.IntCoordinate2Standard(v.Lat)
|
||||||
|
if v.DeliveryRangeType == model.DeliveryRangeTypeRadius {
|
||||||
|
maxDistance := int(utils.Str2Int64WithDefault(v.DeliveryRange, 0))
|
||||||
|
v.Distance = int(jxutils.EarthDistance(lng, lat, v.FloatLng, v.FloatLat) * 1000)
|
||||||
|
isStoreOK = v.Distance <= maxDistance
|
||||||
|
} else {
|
||||||
|
points := jxutils.CoordinateStr2Points(v.DeliveryRange)
|
||||||
|
if utils.IsPointInPolygon(lng, lat, points) {
|
||||||
|
v.Distance = int(jxutils.EarthDistance(lng, lat, v.FloatLng, v.FloatLat) * 1000)
|
||||||
|
isStoreOK = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isStoreOK {
|
||||||
|
storeList2 = append(storeList2, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Sort(Store4UserList(storeList2))
|
||||||
|
storeList = storeList2
|
||||||
|
if len(storeList) > maxStoreCount4User {
|
||||||
|
storeList = storeList[:maxStoreCount4User]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return storeList, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ func GetMyStoreListNew(ctx *jxcontext.Context) (storesInfo interface{}, errCode
|
|||||||
}
|
}
|
||||||
var storeList []*dao.StoreWithCityName
|
var storeList []*dao.StoreWithCityName
|
||||||
if storeList, err = GetStoreList4User(ctx, mobileNum, userID); err == nil && len(storeList) > 0 {
|
if storeList, err = GetStoreList4User(ctx, mobileNum, userID); err == nil && len(storeList) > 0 {
|
||||||
// todo,应该用通过方法
|
// todo,应该用通用方法
|
||||||
mapDataList := make([]map[string]interface{}, len(storeList))
|
mapDataList := make([]map[string]interface{}, len(storeList))
|
||||||
for k, v := range storeList {
|
for k, v := range storeList {
|
||||||
mapDataList[k] = map[string]interface{}{
|
mapDataList[k] = map[string]interface{}{
|
||||||
|
|||||||
@@ -314,6 +314,12 @@ func (*Store) TableUnique() [][]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*Store) TableIndex() [][]string {
|
||||||
|
return [][]string{
|
||||||
|
[]string{"Lng", "Lat"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Store) IsPrinterDisabled() bool {
|
func (s *Store) IsPrinterDisabled() bool {
|
||||||
return s.PrinterDisabled == 1
|
return s.PrinterDisabled == 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -529,3 +529,18 @@ func (c *StoreController) SyncStoresCourierInfo() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 根据位置得到推荐门店列表
|
||||||
|
// @Description 根据位置得到推荐门店列表
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param lng query float64 true "经度"
|
||||||
|
// @Param lat query float64 true "纬度"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /GetStoreListByLocation [get]
|
||||||
|
func (c *StoreController) GetStoreListByLocation() {
|
||||||
|
c.callGetStoreListByLocation(func(params *tStoreGetStoreListByLocationParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
retVal, err = cms.GetStoreListByLocation(params.Ctx, params.Lng, params.Lat)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1269,6 +1269,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: 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: "GetStoreListByLocation",
|
||||||
|
Router: `/GetStoreListByLocation`,
|
||||||
|
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.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetStoreTotalScoreList",
|
Method: "GetStoreTotalScoreList",
|
||||||
|
|||||||
Reference in New Issue
Block a user