价格参考

This commit is contained in:
苏尹岚
2019-12-06 09:04:55 +08:00
parent 25982cf994
commit c6abdbbd3e
6 changed files with 172 additions and 6 deletions

View File

@@ -178,7 +178,82 @@ func GetGetStatisticsReportForAfsOrders(db *DaoDB, storeIDs []int, fromDate time
return nil, err
}
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (err error) {
return err
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
sql := `
SELECT b.city_code,a.sku_id,
MAX(a.price/100) max_price,
MIN(a.price/100) min_price,
ROUND(AVG(a.price/100),2) avg_price,
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.price/100 ORDER BY a.price/100),',',Count(1)/2),',',-1),2) mid_price,
MAX(a.jd_price/100) max_jd_price,
MIN(a.jd_price/100) min_jd_price,
ROUND(AVG(a.jd_price/100),2) avg_jd_price,
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.jd_price/100 ORDER BY a.jd_price/100),',',Count(1)/2),',',-1),2) mid_jd_price,
MAX(a.ebai_price/100) max_ebai_price,
MIN(a.ebai_price/100) min_ebai_price,
ROUND(AVG(a.ebai_price/100),2) avg_ebai_price,
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.ebai_price/100 ORDER BY a.ebai_price/100),',',Count(1)/2),',',-1),2) mid_ebai_price,
MAX(a.mtwm_price/100) max_mtwm_price,
MIN(a.mtwm_price/100) min_mtwm_price,
ROUND(AVG(a.mtwm_price/100),2) avg_mtwm_price,
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.mtwm_price/100 ORDER BY a.mtwm_price/100),',',Count(1)/2),',',-1),2) mid_mtwm_price,
t1.max_sale_price,
t1.min_sale_price,
t1.avg_sale_price,
t1.max_vendor_price,
t1.min_vendor_price,
t1.avg_vendor_price
FROM store_sku_bind a
JOIN store b ON a.store_id = b.id AND b.deleted_at = ?
JOIN sku d ON a.sku_id = d.id AND d.deleted_at = ?
LEFT JOIN (
SELECT SUM(t1.count),t1.sku_id,MAX(t1.sale_price/100) max_sale_price,MIN(t1.sale_price/100) min_sale_price,ROUND(AVG(t1.sale_price/100),2) avg_sale_price,MAX(t1.vendor_price/100) max_vendor_price,MIN(t1.vendor_price/100) min_vendor_price,ROUND(AVG(t1.vendor_price/100),2) avg_vendor_price
FROM order_sku t1
WHERE t1.order_created_at BETWEEN ? AND NOW()
GROUP BY 2
)t1 ON t1.sku_id = a.sku_id
WHERE 1=1
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
utils.DefaultTimeValue,
time.Now().AddDate(0, -1, 0),
}
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"
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
return priceReferSnapshot, nil
}
return nil, err
}
func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
sql := `
SELECT *
FROM price_refer_snapshot
WHERE 1=1
AND delete_at = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
}
if len(skuIDs) > 0 {
sql += " AND sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
sqlParams = append(sqlParams, skuIDs)
}
if len(cityCodes) > 0 {
sql += " AND city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
sqlParams = append(sqlParams, cityCodes)
}
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
return priceReferSnapshot, nil
}
return nil, err
}