This commit is contained in:
suyl
2021-09-01 09:43:17 +08:00
parent 11513a7415
commit 3eda219ba9

View File

@@ -438,6 +438,14 @@ func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]inte
}
}
if params["mapLongitude"] != nil && params["mapLatitude"] != nil && params["mapRadius"] != nil {
mapLongitude := utils.Str2Float64(params["mapLongitude"].(string))
mapLatitude := utils.Str2Float64(params["mapLatitude"].(string))
mapRadius := params["mapRadius"].(int)
sqlWhere += " AND getDistance(?, ?, CAST(t1.lng AS DECIMAL(15,6))/1000000, CAST(t1.lat AS DECIMAL(15,6))/1000000) * 1000 <= ?"
sqlWhereParams = append(sqlWhereParams, mapLongitude, mapLatitude, mapRadius)
}
sql = sqlFrom + sqlWhere
sqlParams = append(sqlParams, sqlFromParams...)
sqlParams = append(sqlParams, sqlWhereParams...)
@@ -512,8 +520,8 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
sql = `
SELECT
DISTINCT t1.*,
CAST(t1.lng AS DECIMAL(15,6))/1000000 float_lng,
CAST(t1.lat AS DECIMAL(15,6))/1000000 float_lat,
-- CAST(t1.lng AS DECIMAL(15,6))/1000000 float_lng,
-- CAST(t1.lat AS DECIMAL(15,6))/1000000 float_lat,
IF(mm.name <> '', mm.name, mm.user_id2) market_man_name,
bank.value payee_bank_name,
IF(om.name <> '', om.name, om.user_id2) operator_name,
@@ -536,33 +544,33 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
var storeList []*StoreExt
offset = jxutils.FormalizePageOffset(offset)
pageSize = jxutils.FormalizePageSize(pageSize)
mapLimit := false
//mapLimit := false
// globals.SugarLogger.Debug(sql)
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil {
// 地图区域限制过滤
if mapLongitude2, ok := params["mapLongitude"].(string); ok {
var (
mapLatitude, mapLongitude float64
mapRadius int
)
mapLimit = true
mapLongitude = utils.Str2Float64(mapLongitude2)
mapLatitude = utils.Str2Float64(params["mapLatitude"].(string))
mapRadius = params["mapRadius"].(int)
for _, v := range storeList {
valid := !mapLimit
if mapLimit {
valid = jxutils.EarthDistance(mapLongitude, mapLatitude, v.FloatLng, v.FloatLat)*1000 <= float64(mapRadius)
}
if valid {
retVal.Stores = append(retVal.Stores, v)
}
}
} else {
retVal.Stores = storeList
}
//if mapLongitude2, ok := params["mapLongitude"].(string); ok {
// var (
// mapLatitude, mapLongitude float64
// mapRadius int
// )
// mapLimit = true
// mapLongitude = utils.Str2Float64(mapLongitude2)
// mapLatitude = utils.Str2Float64(params["mapLatitude"].(string))
// mapRadius = params["mapRadius"].(int)
// for _, v := range storeList {
// valid := !mapLimit
// if mapLimit {
// valid = jxutils.EarthDistance(mapLongitude, mapLatitude, v.FloatLng, v.FloatLat)*1000 <= float64(mapRadius)
// }
// if valid {
// retVal.Stores = append(retVal.Stores, v)
// }
// }
//} else {
// retVal.Stores = storeList
//}
//权限
if permission.IsRoled(ctx) {
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {