From f2f46cb867c5c6abbdebd621927fdd4b8d82f8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 9 Mar 2021 11:03:23 +0800 Subject: [PATCH] aa --- business/jxstore/report/report.go | 64 ++++++++++++++++++------- business/jxutils/jxutils.go | 18 +++++++ business/model/dao/store.go | 4 ++ business/model/store.go | 9 ++-- business/partner/purchase/ebai/store.go | 17 ++++++- 5 files changed, 91 insertions(+), 21 deletions(-) diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 0869984de..0bd0abe4f 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -5,8 +5,11 @@ import ( "fmt" "math" "sort" + "strings" "time" + "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/partner" "git.rosy.net.cn/jx-callback/business/jxstore/permission" @@ -388,17 +391,17 @@ func GetManageState(ctx *jxcontext.Context, cityCodes []int, vendorID int) (getM } type GetStoreManageStateResult struct { - StoreID int `json:"storeID"` - StoreName string `json:"storeName"` - CoverArea int `json:"coverArea"` - MarketScale int `json:"marketScale"` //市场规模 - OpenTime int `json:"openTime"` //营业时长 - SkuCount int `json:"skuCount"` //商品数 - HighSkuCount int `json:"highSkuCount"` //虚高商品数 - ActAmple int `json:"actAmple"` //活动丰富的 - NullOrderCount int `json:"nullOrderCount"` //无效订单数 - RefuseOrderCount int `json:"refuseOrderCount"` //拒绝订单数 - RepurchaseRate int `json:"repurchaseRate"` //复购率(转化率) + StoreID int `json:"storeID"` + StoreName string `json:"storeName"` + CoverArea float64 `json:"coverArea"` + MarketScale int `json:"marketScale"` //市场规模 + OpenTime int `json:"openTime"` //营业时长 + SkuCount int `json:"skuCount"` //商品数 + HighSkuCount int `json:"highSkuCount"` //虚高商品数 + ActAmple int `json:"actAmple"` //活动丰富的 + NullOrderCount int `json:"nullOrderCount"` //无效订单数 + RefuseOrderCount int `json:"refuseOrderCount"` //拒绝订单数 + RepurchaseRate int `json:"repurchaseRate"` //复购率(转化率) } func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, fromTime, toTime string) (getStoreManageStateResult []*GetStoreManageStateResult, err error) { @@ -427,13 +430,42 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f for _, v := range storeIDs { storeDetail, _ := dao.GetStoreDetail(db, v, vendorID, "") result := &GetStoreManageStateResult{ - StoreID: v, - StoreName: storeDetail.Name, + StoreID: v, + StoreName: storeDetail.Name, + MarketScale: storeDetail.MarketScale, + CoverArea: storeDetail.CoverArea, + } + if result.CoverArea == 0 { + handler := partner.GetPurchasePlatformFromVendorID(vendorID) + store, _ := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID) + if storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, []int{v}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", ""); len(storeMaps) > 0 && err == nil { + storeMaps[0].CoverArea = CalculateCoverArea(strings.Split(store.DeliveryRange, ";")) + dao.UpdateEntity(db, storeMaps[0], "CoverArea") + result.CoverArea = storeMaps[0].CoverArea + } } - handler := partner.GetPurchasePlatformFromVendorID(vendorID) - store, _ := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID) - fmt.Println("testdddd", store.DeliveryRange) getStoreManageStateResult = append(getStoreManageStateResult, result) } return getStoreManageStateResult, err } + +func CalculateCoverArea(coordinate []string) (area float64) { + if len(coordinate) == 0 { + return 0 + } + var xyList [][2]float64 + for _, v := range coordinate { + cell := strings.Split(v, ",") + lat := utils.Str2Float64WithDefault(cell[0], 0) + lng := utils.Str2Float64WithDefault(cell[1], 0) + xys := jxutils.MillierConvertion(lat, lng) + xyList = append(xyList, xys) + } + var sum float64 + for i := 0; i < len(xyList)-1; i++ { + sum += (xyList[i+1][0] - xyList[i][0]) * (xyList[i+1][1] + xyList[i+1][1]) + } + sum += (xyList[0][0] - xyList[len(xyList)-1][0]) * (xyList[0][1] + xyList[len(xyList)-1][1]) + sum /= 2 + return math.Round(sum) +} diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index d1c34a7ba..6f54b82d3 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -267,6 +267,24 @@ func WalkingDistance(lng1, lat1, lng2, lat2 float64) (distance float64) { return distance } +//经纬度坐标转换到平面坐标 +func MillierConvertion(lat float64, lon float64) [2]float64 { + var L, H, W, temp, mill, x, y float64 + L = 6381372 * math.Pi * 2 //地球周长 + W = L // 平面展开后,x轴等于周长 + H = L / 2 // y轴约等于周长一半 + mill = 2.3 // 米勒投影中的一个常数,范围大约在正负2.3之间 + temp = math.Pi + x = lon * temp / 180 // 将经度从度数转换为弧度 + y = lat * temp / 180 // 将纬度从度数转换为弧度 + y = 1.25 * math.Log(math.Tan(0.25*temp+0.4*y)) // 米勒投影的转换 + // 弧度转为实际距离 + x = (W / 2) + (W/(2*math.Pi))*x + y = (H / 2) - (H/(2*mill))*y + var result = [2]float64{x, y} + return result +} + func StandardCoordinate2Int(value float64) int { return int(math.Round(value * 1000000)) } diff --git a/business/model/dao/store.go b/business/model/dao/store.go index 0b7cdf912..4005f65d7 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -67,6 +67,9 @@ type StoreDetail struct { BrandLogo string `json:"brandLogo"` BrandIsOpen int `json:"brandIsOpen"` BrandIsPrint int `json:"brandIsPrint"` + + CoverArea int `json:"coverArea"` + MarketScale float64 `json:"marketScale"` //市场规模 } // 带快递门店信息的 @@ -112,6 +115,7 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID, vendorOrgCo t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee_deduction_sill, t2.delivery_fee_deduction_fee, t2.sync_status, t2.vendor_org_code, t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync, t2.vendor_store_name, t2.is_order, t2.yb_app_id, t2.yb_app_key, t2.yb_store_prefix, t2.jds_street_code, t2.jds_street_name, t2.is_supply_goods, t2.vendor_pay_percentage, t2.mtwm_token, t2.ebai_supplier_id, t2.create_delivery_type, + t2.market_scale, t2.cover_area, t3.value price_percentage_pack_str, t4.value freight_deduction_pack_str, province.name province_name, diff --git a/business/model/store.go b/business/model/store.go index e0ed6529f..347602fce 100644 --- a/business/model/store.go +++ b/business/model/store.go @@ -456,10 +456,11 @@ type StoreMap struct { YbAppKey string `orm:"size(255)" json:"ybAppKey"` YbStorePrefix string `orm:"size(255)" json:"ybStorePrefix"` - MtwmToken string `orm:"size(255)" json:"mtwmToken"` //美团外卖商超token,有效期30天,每20天刷一次 - MtwmRefreshToken string `orm:"size(255)" json:"mtwmRefreshToken"` //美团外卖商超refreshToken - EbaiSupplierID string `orm:"column(ebai_supplier_id)" json:"ebaiSupplierID"` //饿百供应商ID - MarketScale int `json:"marketScale"` //市场规模 + MtwmToken string `orm:"size(255)" json:"mtwmToken"` //美团外卖商超token,有效期30天,每20天刷一次 + MtwmRefreshToken string `orm:"size(255)" json:"mtwmRefreshToken"` //美团外卖商超refreshToken + EbaiSupplierID string `orm:"column(ebai_supplier_id)" json:"ebaiSupplierID"` //饿百供应商ID + MarketScale int `json:"marketScale"` //市场规模 + CoverArea float64 `json:"coverArea"` //覆盖范围 } func (*StoreMap) TableUnique() [][]string { diff --git a/business/partner/purchase/ebai/store.go b/business/partner/purchase/ebai/store.go index f8dba5834..57fd8c749 100644 --- a/business/partner/purchase/ebai/store.go +++ b/business/partner/purchase/ebai/store.go @@ -232,7 +232,9 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendo retVal.DeliveryRangeType = model.DeliveryRangeTypePolygon retVal.DeliveryRange = EbaiDeliveryRegion2Jx(result["delivery_region"]) if retVal.DeliveryRange == "" { - api.EbaiAPI.ShopDeliveryinfoGet("", utils.Str2Int64(vendorStoreID)) + if list, err := api.EbaiAPI.ShopDeliveryinfoGet("", utils.Str2Int64(vendorStoreID)); err == nil { + retVal.DeliveryRange = EbaiDeliveryRegion2Jx2(list[0]) + } } return retVal, nil } @@ -399,6 +401,19 @@ func EbaiDeliveryRegion2Jx(deliveryRegion interface{}) string { return "" } +func EbaiDeliveryRegion2Jx2(deliveryRegion map[string]interface{}) string { + if len(deliveryRegion) > 0 { + region := deliveryRegion["delivery_areas"].([]interface{})[0].(map[string]interface{})["coordinates"].([]interface{}) + coords := make([]string, len(region)) + for k, v := range region { + mapV := v.(map[string]interface{}) + coords[k] = fmt.Sprintf("%.6f,%.6f", utils.MustInterface2Float64(mapV["longitude"]), utils.MustInterface2Float64(mapV["latitude"])) + } + return strings.Join(coords, ";") + } + return "" +} + func JxDeliveryRegion2Ebai(store *model.Store) (deliveryRegion interface{}) { rangeStr := strings.Trim(store.DeliveryRange, ";") if store.DeliveryRangeType == model.DeliveryRangeTypeRadius {