价格统计
This commit is contained in:
@@ -1367,33 +1367,42 @@ func GetStoreSkuBindByNameID(db *DaoDB, storeID, nameID, status int) (storeSkuBi
|
||||
return storeSkuBind, err
|
||||
}
|
||||
|
||||
func GetMidPriceByNameID(db *DaoDB, cityCode, skuNameID int, snapDate time.Time) (midPrice int, err error) {
|
||||
func GetPriceReferUnitPrice(db *DaoDB, cityCode int, nameID int, snapDate time.Time) (result *PriceReferSnapshotExt, err error) {
|
||||
var (
|
||||
sku []*model.SkuAndName
|
||||
skuMap = make(map[int]int)
|
||||
pRefer []*PriceReferSnapshotExt
|
||||
minUnitPrice int
|
||||
maxUnitPrice int
|
||||
midUnitPrice int
|
||||
avgUnitPrice int
|
||||
)
|
||||
sql := `
|
||||
SELECT a.mid_price price, a.sku_id id, b.spec_quality, c.unit, b.spec_unit
|
||||
SELECT a.max_price, a.min_price, a.avg_price, a.mid_price, a.sku_id id, b.spec_quality, c.unit, b.spec_unit
|
||||
FROM price_refer_snapshot a
|
||||
JOIN sku b ON a.sku_id = b.id
|
||||
JOIN sku_name c ON c.id = b.name_id
|
||||
WHERE c.id = ?
|
||||
WHERE 1=1
|
||||
AND a.snapshot_at = ?
|
||||
AND a.city_code = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
skuNameID,
|
||||
snapDate,
|
||||
cityCode,
|
||||
}
|
||||
err = GetRows(db, &sku, sql, sqlParams...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if nameID > 0 {
|
||||
sql += " AND a.id = ?"
|
||||
sqlParams = append(sqlParams, nameID)
|
||||
}
|
||||
if len(sku) > 0 {
|
||||
for _, v := range sku {
|
||||
err = GetRows(db, &pRefer, sql, sqlParams...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(pRefer) > 0 {
|
||||
for _, v := range pRefer {
|
||||
var (
|
||||
price int
|
||||
minPrice int
|
||||
maxPrice int
|
||||
midPrice int
|
||||
avgPrice int
|
||||
specQuality float64
|
||||
)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
@@ -1402,14 +1411,25 @@ func GetMidPriceByNameID(db *DaoDB, cityCode, skuNameID int, snapDate time.Time)
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
}
|
||||
price = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.Price)))
|
||||
maxPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.MaxPrice)))
|
||||
minPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.MinPrice)))
|
||||
avgPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.AvgPrice)))
|
||||
midPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.MidPrice)))
|
||||
} else {
|
||||
price = v.Price
|
||||
}
|
||||
if skuMap[skuNameID] < price {
|
||||
skuMap[skuNameID] = price
|
||||
maxPrice = v.MaxPrice
|
||||
minPrice = v.MinPrice
|
||||
avgPrice = v.AvgPrice
|
||||
midPrice = v.MidPrice
|
||||
}
|
||||
minUnitPrice += minPrice
|
||||
maxUnitPrice += maxPrice
|
||||
midUnitPrice += midPrice
|
||||
avgUnitPrice += avgPrice
|
||||
}
|
||||
result.MinUnitPrice = minUnitPrice / len(pRefer)
|
||||
result.MaxUnitPrice = maxUnitPrice / len(pRefer)
|
||||
result.AvgUnitPrice = avgUnitPrice / len(pRefer)
|
||||
result.MidUnitPrice = midUnitPrice / len(pRefer)
|
||||
}
|
||||
return skuMap[skuNameID], err
|
||||
return result, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user