显示中位价
This commit is contained in:
@@ -262,7 +262,7 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
sql += `
|
||||
JOIN store_sku_bind t4 ON t4.store_id = t3.id AND t4.sku_id = t2.id AND t4.deleted_at = ?
|
||||
LEFT JOIN sku_name_place_bind t5 ON t1.id = t5.name_id AND t3.city_code = t5.place_code
|
||||
JOIN price_refer_snapshot t6 ON t6.city_code = t3.city_code AND t6.sku_id = t2.id AND t6.snapshot_at = ?
|
||||
LEFT JOIN price_refer_snapshot t6 ON t6.city_code = 0 AND t6.sku_id = t2.id AND t6.snapshot_at = ?
|
||||
WHERE t1.deleted_at = ? AND (t1.is_global = 1 OR t5.id IS NOT NULL OR 1 = ?)/* AND t1.status = ?*/
|
||||
`
|
||||
sqlParams = append(sqlParams, []interface{}{
|
||||
|
||||
@@ -97,8 +97,10 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
case 1:
|
||||
priceReferSnapshotList, err = dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, snapshotAt)
|
||||
var (
|
||||
citySkuMap = make(map[int]map[int][]int)
|
||||
resultMap = make(map[int]map[int]*model.PriceReferSnapshot)
|
||||
citySkuMap = make(map[int]map[int][]int)
|
||||
countryMap = make(map[int][]int)
|
||||
resultMap = make(map[int]map[int]*model.PriceReferSnapshot)
|
||||
resultCountryMap = make(map[int]*model.PriceReferSnapshot)
|
||||
)
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
if err != nil {
|
||||
@@ -145,6 +147,7 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
if len(tList) > 0 {
|
||||
for _, vv := range tList {
|
||||
skuNameMap[vv.NameID] = append(skuNameMap[vv.NameID], vv.UnitPrice)
|
||||
countryMap[vv.NameID] = append(countryMap[vv.NameID], vv.UnitPrice)
|
||||
}
|
||||
if citySkuMap[v.CityCode] != nil {
|
||||
for nameID, unitPriceList := range skuNameMap {
|
||||
@@ -159,6 +162,26 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, v := range countryMap {
|
||||
var midUnitPrice int
|
||||
var avgUnitPrice int
|
||||
sort.Ints(v)
|
||||
if len(v)%2 == 0 {
|
||||
midUnitPrice = v[len(v)/2-1]
|
||||
} else {
|
||||
midUnitPrice = v[len(v)/2]
|
||||
}
|
||||
for _, vv := range v {
|
||||
avgUnitPrice += vv
|
||||
}
|
||||
priceRefer := &model.PriceReferSnapshot{
|
||||
MidUnitPrice: midUnitPrice,
|
||||
MaxUnitPrice: v[len(v)-1],
|
||||
MinUnitPrice: v[0],
|
||||
AvgUnitPrice: avgUnitPrice / len(v),
|
||||
}
|
||||
resultCountryMap[k] = priceRefer
|
||||
}
|
||||
for k1, v := range citySkuMap {
|
||||
skuNameMap := make(map[int]*model.PriceReferSnapshot)
|
||||
for k2, _ := range v {
|
||||
@@ -193,6 +216,16 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
}()
|
||||
if len(priceReferSnapshotList) > 0 {
|
||||
for _, v := range priceReferSnapshotList {
|
||||
if v.CityCode == 0 {
|
||||
if resultCountryMap[v.NameID] != nil {
|
||||
v.MidUnitPrice = resultCountryMap[v.NameID].MidUnitPrice
|
||||
v.MaxUnitPrice = resultCountryMap[v.NameID].MaxUnitPrice
|
||||
v.AvgUnitPrice = resultCountryMap[v.NameID].AvgUnitPrice
|
||||
v.MinUnitPrice = resultCountryMap[v.NameID].MinUnitPrice
|
||||
dao.UpdateEntity(db, v, "MidUnitPrice", "MaxUnitPrice", "MinUnitPrice", "AvgUnitPrice")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if resultMap[v.CityCode][v.NameID] != nil {
|
||||
v.MidUnitPrice = resultMap[v.CityCode][v.NameID].MidUnitPrice
|
||||
v.MaxUnitPrice = resultMap[v.CityCode][v.NameID].MaxUnitPrice
|
||||
|
||||
Reference in New Issue
Block a user