diff --git a/internal/application/cpdaily/task/sign.go b/internal/application/cpdaily/task/sign.go index a850a5c..1b58317 100644 --- a/internal/application/cpdaily/task/sign.go +++ b/internal/application/cpdaily/task/sign.go @@ -21,6 +21,7 @@ import ( "github.com/gogf/gf/v2/container/gvar" "github.com/google/uuid" "github.com/samber/oops" + "github.com/tidwall/gjson" "github.com/tidwall/match" "resty.dev/v3" ) @@ -457,11 +458,9 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str histSignPhotoUrl := "" histIsMalposition := "" - // 只有有真实的已签到历史数据时,才从历史数据中提取地址和经纬度 - // 否则 rows 中包含的是管理员圈定的范围配置数据,不是用户实际签到地址 - // signPlaceSelected 始终是管理员圈定范围,不应使用 + // 优先使用历史签到数据(真实地址),无历史时保底使用管理员配置的范围信息 if hasHistory { - // 先从 longitude/latitude/position/signAddress 提取 + // 从历史签到数据中提取用户真实的地址和经纬度 if lon := histRows["longitude"]; lon != nil && lon.String() != "" { if lat := histRows["latitude"]; lat != nil && lat.String() != "" { histLatAndLon = lon.String() + "," + lat.String() @@ -488,6 +487,24 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str } } } + // 无历史签到数据时,保底使用管理员配置的范围信息 + if histLatAndLon == "" && histAddress == "" { + if sps := rows["signPlaceSelected"]; sps != nil && sps.String() != "" && sps.String() != "[]" { + placeArr := gjson.Parse(sps.String()).Array() + if len(placeArr) > 0 { + place := placeArr[0] + lng := place.Get("longitude").String() + lat := place.Get("latitude").String() + addr := place.Get("address").String() + if lng != "" && lat != "" { + histLatAndLon = lng + "," + lat + } + if addr != "" { + histAddress = addr + } + } + } + } dto := &formtype.CpTaskFormItem{ Title: "经纬度", diff --git a/internal/application/cpdaily/task/sleepcheck.go b/internal/application/cpdaily/task/sleepcheck.go index 0858c7d..0b8b529 100644 --- a/internal/application/cpdaily/task/sleepcheck.go +++ b/internal/application/cpdaily/task/sleepcheck.go @@ -535,11 +535,9 @@ func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[s histSignPhotoUrl := "" histIsMalposition := "" - // 只有有真实的已签到历史数据时,才从历史数据中提取地址和经纬度 - // 否则 rows 中包含的是管理员圈定的范围配置数据,不是用户实际签到地址 - // signPlaceSelected 始终是管理员圈定范围,不应使用 + // 优先使用历史签到数据(真实地址),无历史时保底使用管理员配置的范围信息 if hasHistory { - // 先从 longitude/latitude/position/signAddress 提取 + // 从历史签到数据中提取用户真实的地址和经纬度 if lon := histRows["longitude"]; lon != nil && lon.String() != "" { if lat := histRows["latitude"]; lat != nil && lat.String() != "" { histLatAndLon = lon.String() + "," + lat.String() @@ -566,6 +564,24 @@ func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[s } } } + // 无历史签到数据时,保底使用管理员配置的范围信息 + if histLatAndLon == "" && histAddress == "" { + if sps := rows["signPlaceSelected"]; sps != nil && sps.String() != "" && sps.String() != "[]" { + placeArr := gjson.Parse(sps.String()).Array() + if len(placeArr) > 0 { + place := placeArr[0] + lng := place.Get("longitude").String() + lat := place.Get("latitude").String() + addr := place.Get("address").String() + if lng != "" && lat != "" { + histLatAndLon = lng + "," + lat + } + if addr != "" { + histAddress = addr + } + } + } + } dto := &formtype.CpTaskFormItem{ Title: "经纬度",