This commit is contained in:
苏尹岚
2021-03-09 11:03:23 +08:00
parent defbdb0462
commit f2f46cb867
5 changed files with 91 additions and 21 deletions

View File

@@ -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)
}