显示中位价
This commit is contained in:
@@ -262,7 +262,7 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
|||||||
sql += `
|
sql += `
|
||||||
JOIN store_sku_bind t4 ON t4.store_id = t3.id AND t4.sku_id = t2.id AND t4.deleted_at = ?
|
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
|
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 = ?*/
|
WHERE t1.deleted_at = ? AND (t1.is_global = 1 OR t5.id IS NOT NULL OR 1 = ?)/* AND t1.status = ?*/
|
||||||
`
|
`
|
||||||
sqlParams = append(sqlParams, []interface{}{
|
sqlParams = append(sqlParams, []interface{}{
|
||||||
|
|||||||
@@ -97,8 +97,10 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
|||||||
case 1:
|
case 1:
|
||||||
priceReferSnapshotList, err = dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, snapshotAt)
|
priceReferSnapshotList, err = dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, snapshotAt)
|
||||||
var (
|
var (
|
||||||
citySkuMap = make(map[int]map[int][]int)
|
citySkuMap = make(map[int]map[int][]int)
|
||||||
resultMap = make(map[int]map[int]*model.PriceReferSnapshot)
|
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, "")
|
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -145,6 +147,7 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
|||||||
if len(tList) > 0 {
|
if len(tList) > 0 {
|
||||||
for _, vv := range tList {
|
for _, vv := range tList {
|
||||||
skuNameMap[vv.NameID] = append(skuNameMap[vv.NameID], vv.UnitPrice)
|
skuNameMap[vv.NameID] = append(skuNameMap[vv.NameID], vv.UnitPrice)
|
||||||
|
countryMap[vv.NameID] = append(countryMap[vv.NameID], vv.UnitPrice)
|
||||||
}
|
}
|
||||||
if citySkuMap[v.CityCode] != nil {
|
if citySkuMap[v.CityCode] != nil {
|
||||||
for nameID, unitPriceList := range skuNameMap {
|
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 {
|
for k1, v := range citySkuMap {
|
||||||
skuNameMap := make(map[int]*model.PriceReferSnapshot)
|
skuNameMap := make(map[int]*model.PriceReferSnapshot)
|
||||||
for k2, _ := range v {
|
for k2, _ := range v {
|
||||||
@@ -193,6 +216,16 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
|||||||
}()
|
}()
|
||||||
if len(priceReferSnapshotList) > 0 {
|
if len(priceReferSnapshotList) > 0 {
|
||||||
for _, v := range priceReferSnapshotList {
|
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 {
|
if resultMap[v.CityCode][v.NameID] != nil {
|
||||||
v.MidUnitPrice = resultMap[v.CityCode][v.NameID].MidUnitPrice
|
v.MidUnitPrice = resultMap[v.CityCode][v.NameID].MidUnitPrice
|
||||||
v.MaxUnitPrice = resultMap[v.CityCode][v.NameID].MaxUnitPrice
|
v.MaxUnitPrice = resultMap[v.CityCode][v.NameID].MaxUnitPrice
|
||||||
|
|||||||
@@ -189,8 +189,11 @@ func GetGetStatisticsReportForAfsOrders(db *DaoDB, storeIDs []int, fromDate time
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||||
sql := `
|
var sql string
|
||||||
SELECT b.city_code,a.sku_id,c.name_id,
|
sql1 := `
|
||||||
|
SELECT a.sku_id, c.name_id,
|
||||||
|
`
|
||||||
|
sql2 := `
|
||||||
MAX(a.jd_price) max_jd_price,
|
MAX(a.jd_price) max_jd_price,
|
||||||
MIN(a.jd_price) min_jd_price,
|
MIN(a.jd_price) min_jd_price,
|
||||||
ROUND(AVG(a.jd_price)) avg_jd_price,
|
ROUND(AVG(a.jd_price)) avg_jd_price,
|
||||||
@@ -220,6 +223,7 @@ func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (p
|
|||||||
)t1 ON t1.sku_id = a.sku_id
|
)t1 ON t1.sku_id = a.sku_id
|
||||||
WHERE a.deleted_at = ?
|
WHERE a.deleted_at = ?
|
||||||
`
|
`
|
||||||
|
sql = sql1 + "b.city_code, " + sql2
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
utils.DefaultTimeValue,
|
utils.DefaultTimeValue,
|
||||||
model.StoreStatusDisabled,
|
model.StoreStatusDisabled,
|
||||||
@@ -234,7 +238,19 @@ func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (p
|
|||||||
sql += " AND b.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
sql += " AND b.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||||
sqlParams = append(sqlParams, cityCodes)
|
sqlParams = append(sqlParams, cityCodes)
|
||||||
}
|
}
|
||||||
sql += " GROUP BY 1,2,3"
|
sql += ` GROUP BY 1,2,3
|
||||||
|
UNION `
|
||||||
|
sql += sql1 + "0 city_code," + sql2
|
||||||
|
if len(skuIDs) > 0 {
|
||||||
|
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||||
|
sqlParams = append(sqlParams, skuIDs)
|
||||||
|
}
|
||||||
|
if len(cityCodes) > 0 {
|
||||||
|
sql += " AND b.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||||
|
sqlParams = append(sqlParams, cityCodes)
|
||||||
|
}
|
||||||
|
sql += " GROUP BY 1,2"
|
||||||
|
sqlParams = append(sqlParams, sqlParams...)
|
||||||
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||||
return priceReferSnapshot, nil
|
return priceReferSnapshot, nil
|
||||||
}
|
}
|
||||||
@@ -243,9 +259,9 @@ func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (p
|
|||||||
|
|
||||||
func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int, skuNameID int, snapDate time.Time, offset, pageSize int) (priceReferSnapshot []*PriceReferSnapshotExt, totalCount int, err error) {
|
func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int, skuNameID int, snapDate time.Time, offset, pageSize int) (priceReferSnapshot []*PriceReferSnapshotExt, totalCount int, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT SQL_CALC_FOUND_ROWS a.*,b.name city_name
|
SELECT SQL_CALC_FOUND_ROWS a.*,IF(a.city_code = 0,'全国',b.name) city_name
|
||||||
FROM price_refer_snapshot a
|
FROM price_refer_snapshot a
|
||||||
JOIN place b ON a.city_code = b.code
|
LEFT JOIN place b ON a.city_code = b.code
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
AND a.deleted_at = ?
|
AND a.deleted_at = ?
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user