From f85c182f44b8f7022e36874cc1333d86bc2eb18e Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 8 Nov 2019 09:01:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=81=E7=94=A8=E4=B8=8E=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=9A=84=E9=97=A8=E5=BA=97=E5=88=9B=E5=BB=BA=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E6=8E=92=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 4 ++-- business/jxstore/cms/store.go | 21 +++++---------------- business/jxutils/jxutils.go | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 9a14ebd6f..9b6907fb2 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -131,7 +131,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac for _, vendorID := range vendorIDs { storeDetail, err2 := dao.GetStoreDetail(db, storeID, vendorID) if err = err2; err == nil { - if storeDetail.IsSync != 0 && storeDetail.Status != model.StoreStatusDisabled { + if storeDetail.IsSync != 0 && storeDetail.Status != model.StoreStatusDisabled && storeDetail.VendorStatus != model.StoreStatusDisabled { for _, v := range oneStoreSkuParam { validVendorMap[vendorID] = 1 validSkuMap[v.SkuID] = 1 @@ -168,7 +168,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac } actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage)) if actSkuMap.ActualActPrice > 10 { - actSkuMap.ActualActPrice = int64(math.Round(float64(actSkuMap.ActualActPrice)/10) * 10) + actSkuMap.ActualActPrice = int64(math.Floor(float64(actSkuMap.ActualActPrice)/10) * 10) } } if actSkuMap.ActualActPrice <= 0 { diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index c2e101aa0..fd96c1695 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -203,7 +203,9 @@ func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]inte sqlVendorStoreCond += " AND ( 1 = 0" } } - sqlFrom += "\nLEFT JOIN " + tableName + " " + tableAlias + " ON " + tableAlias + ".vendor_id = ? AND " + tableAlias + ".store_id = t1.id AND " + tableAlias + ".deleted_at = ?" + sqlFrom += "\nLEFT JOIN " + tableName + " " + tableAlias + " ON " + tableAlias + ".vendor_id = ? AND " + + tableAlias + ".store_id = t1.id AND " + tableAlias + ".deleted_at = ? AND " + + tableAlias + ".is_sync <> 0 " sqlFromParams = append(sqlFromParams, vendor, utils.DefaultTimeValue) if cond == 1 { sqlVendorStoreCond += " " + mapCond + " " + tableAlias + ".id IS NOT NULL" @@ -2102,21 +2104,8 @@ func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, needWalkDi 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 { + if distance := jxutils.Point2StoreDistance(lng, lat, v.Lng, v.Lat, v.DeliveryRangeType, v.DeliveryRange); distance > 0 { + v.Distance = distance storeList2 = append(storeList2, v) } } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 8f20044d5..0fe81a89c 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -235,7 +235,7 @@ func IntCoordinate2MarsStandard(gpsLng, gpsLat int, coordinateType int) (marsLng case model.CoordinateTypeGPS: coordSys = autonavi.CoordSysGPS case model.CoordinateTypeMars: - coordSys = autonavi.CoordSysAutonavi + return marsLng, marsLat, nil case model.CoordinateTypeBaiDu: coordSys = autonavi.CoordSysBaidu case model.CoordinateTypeMapbar: @@ -779,3 +779,22 @@ func GetOneEmailFromStr(str string) (email string) { } return email } + +// 计算一个坐标点距离一个门店的距离,单位为米,如果不在有效范围内,则返回0 +func Point2StoreDistance(lng, lat float64, intStoreLng, intStoreLat int, deliveryRangeType int8, deliveryRange string) (distance int) { + storeLng := IntCoordinate2Standard(intStoreLng) + storeLat := IntCoordinate2Standard(intStoreLat) + if deliveryRangeType == model.DeliveryRangeTypeRadius { + maxDistance := int(utils.Str2Int64WithDefault(deliveryRange, 0)) + distance = int(EarthDistance(lng, lat, storeLng, storeLat) * 1000) + if distance > maxDistance { + distance = 0 + } + } else { + points := CoordinateStr2Points(deliveryRange) + if utils.IsPointInPolygon(lng, lat, points) { + distance = int(EarthDistance(lng, lat, storeLng, storeLat) * 1000) + } + } + return distance +}