价格统计

This commit is contained in:
苏尹岚
2019-12-30 17:08:17 +08:00
parent e82d9851de
commit 2548908b68
5 changed files with 79 additions and 44 deletions

View File

@@ -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)