价格统计
This commit is contained in:
@@ -36,8 +36,11 @@ type StatisticsReportForOrdersList struct {
|
||||
|
||||
type PriceReferSnapshotExt struct {
|
||||
model.PriceReferSnapshot
|
||||
CityName string `json:"cityName"`
|
||||
SkuName string `json:"skuName"`
|
||||
CityName string `json:"cityName"`
|
||||
SkuName string `json:"skuName"`
|
||||
SpecQuality float32
|
||||
Unit string
|
||||
SpecUnit string
|
||||
}
|
||||
|
||||
//查询统计订单信息
|
||||
@@ -187,15 +190,11 @@ func GetGetStatisticsReportForAfsOrders(db *DaoDB, storeIDs []int, fromDate time
|
||||
|
||||
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||
sql := `
|
||||
SELECT b.city_code,a.sku_id,
|
||||
SELECT b.city_code,a.sku_id,c.name_id,
|
||||
ROUND(MAX(a.price/IF(b.pay_percentage < 50,70,b.pay_percentage)*100)) max_price,
|
||||
ROUND(MIN(a.price/IF(b.pay_percentage < 50,70,b.pay_percentage)*100)) min_price,
|
||||
ROUND(AVG(a.price/IF(b.pay_percentage < 50,70,b.pay_percentage)*100)) avg_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT((a.price/IF(b.pay_percentage < 50,70,b.pay_percentage))*100 ORDER BY (a.price/IF(b.pay_percentage < 50,70,b.pay_percentage))*100),',',Count(1)/2),',',-1)) mid_price,
|
||||
ROUND(MAX(a.unit_price/IF(b.pay_percentage < 50,70,b.pay_percentage)*100)) max_unit_price,
|
||||
ROUND(MIN(a.unit_price/IF(b.pay_percentage < 50,70,b.pay_percentage)*100)) min_unit_price,
|
||||
ROUND(AVG(a.unit_price/IF(b.pay_percentage < 50,70,b.pay_percentage)*100)) avg_unit_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT((a.unit_price/IF(b.pay_percentage < 50,70,b.pay_percentage))*100 ORDER BY (a.unit_price/IF(b.pay_percentage < 50,70,b.pay_percentage))*100),',',Count(1)/2),',',-1)) mid_unit_price,
|
||||
MAX(a.jd_price) max_jd_price,
|
||||
MIN(a.jd_price) min_jd_price,
|
||||
ROUND(AVG(a.jd_price)) avg_jd_price,
|
||||
@@ -216,6 +215,7 @@ func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (p
|
||||
t1.avg_vendor_price
|
||||
FROM store_sku_bind a
|
||||
JOIN store b ON a.store_id = b.id AND b.deleted_at = ? AND b.status != ?
|
||||
JOIN sku c ON a.sku_id = c.id
|
||||
LEFT JOIN (
|
||||
SELECT SUM(t1.count),t1.sku_id,MAX(t1.sale_price) max_sale_price,MIN(t1.sale_price) min_sale_price,ROUND(AVG(t1.sale_price)) avg_sale_price,MAX(t1.vendor_price) max_vendor_price,MIN(t1.vendor_price) min_vendor_price,ROUND(AVG(t1.vendor_price)) avg_vendor_price
|
||||
FROM order_sku t1
|
||||
@@ -240,14 +240,14 @@ func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (p
|
||||
sql += " AND b.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
sql += " GROUP BY 1,2"
|
||||
sql += " GROUP BY 1,2,3"
|
||||
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||
return priceReferSnapshot, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []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 := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*,b.name city_name
|
||||
FROM price_refer_snapshot a
|
||||
@@ -258,6 +258,10 @@ func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int, snapDate time.Tim
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if skuNameID > 0 {
|
||||
sql += " AND a.name_id = ?"
|
||||
sqlParams = append(sqlParams, skuNameID)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
|
||||
@@ -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