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