价格统计
This commit is contained in:
@@ -2247,9 +2247,9 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
|
|||||||
}
|
}
|
||||||
for _, v := range skuNameAndPlace {
|
for _, v := range skuNameAndPlace {
|
||||||
if skuNameMap[v.ID] != nil {
|
if skuNameMap[v.ID] != nil {
|
||||||
midPrice, _ := dao.GetMidPriceByNameID(db, cityCode, v.ID, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
priceReferList, _, _ := dao.GetPriceReferSnapshot(db, []int{cityCode}, nil, v.ID, utils.Time2Date(time.Now().AddDate(0, 0, -1)), 0, 9999)
|
||||||
if midPrice != 0 {
|
if len(priceReferList) > 0 {
|
||||||
v.Price = midPrice
|
v.Price = priceReferList[0].MidUnitPrice
|
||||||
}
|
}
|
||||||
v.Type = skuNameMap[v.ID].BrandID
|
v.Type = skuNameMap[v.ID].BrandID
|
||||||
skuNameAndPlaceList = append(skuNameAndPlaceList, v)
|
skuNameAndPlaceList = append(skuNameAndPlaceList, v)
|
||||||
@@ -2813,7 +2813,7 @@ func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync,
|
|||||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, v.NameID, model.StoreSkuBindStatusNormal)
|
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, v.NameID, model.StoreSkuBindStatusNormal)
|
||||||
//有关注过
|
//有关注过
|
||||||
if len(focusList) > 0 {
|
if len(focusList) > 0 {
|
||||||
price = 0
|
price = focusList[0].UnitPrice
|
||||||
skuInfoMap[v.NameID] = append(skuInfoMap[v.NameID], &StoreSkuBindSkuInfo{
|
skuInfoMap[v.NameID] = append(skuInfoMap[v.NameID], &StoreSkuBindSkuInfo{
|
||||||
SkuID: v.ID,
|
SkuID: v.ID,
|
||||||
IsSale: 1,
|
IsSale: 1,
|
||||||
@@ -2920,10 +2920,12 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
|
|||||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, k, model.StoreSkuBindStatusNormal)
|
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, k, model.StoreSkuBindStatusNormal)
|
||||||
//有关注过
|
//有关注过
|
||||||
if len(focusList) > 0 {
|
if len(focusList) > 0 {
|
||||||
price = 0
|
price = focusList[0].UnitPrice
|
||||||
} else {
|
} else {
|
||||||
midPrice, _ := dao.GetMidPriceByNameID(db, store.CityCode, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
priceReferList, _, _ := dao.GetPriceReferSnapshot(db, []int{store.CityCode}, nil, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)), 0, 9999)
|
||||||
price = midPrice
|
if len(priceReferList) > 0 {
|
||||||
|
price = priceReferList[0].MidUnitPrice
|
||||||
|
}
|
||||||
}
|
}
|
||||||
skuBindInfo := &StoreSkuBindInfo{
|
skuBindInfo := &StoreSkuBindInfo{
|
||||||
NameID: k,
|
NameID: k,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
@@ -44,7 +44,7 @@ func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs
|
|||||||
if snapDate != "" {
|
if snapDate != "" {
|
||||||
snapDateParam = utils.Str2Time(snapDate)
|
snapDateParam = utils.Str2Time(snapDate)
|
||||||
}
|
}
|
||||||
priceReferSnapshot, totalCount, err := dao.GetPriceReferSnapshot(db, cityCodes, skuIDs, snapDateParam, offset, pageSize)
|
priceReferSnapshot, totalCount, err := dao.GetPriceReferSnapshot(db, cityCodes, skuIDs, 0, snapDateParam, offset, pageSize)
|
||||||
pagedInfo = &model.PagedInfo{
|
pagedInfo = &model.PagedInfo{
|
||||||
Data: priceReferSnapshot,
|
Data: priceReferSnapshot,
|
||||||
TotalCount: totalCount,
|
TotalCount: totalCount,
|
||||||
@@ -70,15 +70,23 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e
|
|||||||
priceReferSnapshotDelete := &model.PriceReferSnapshot{SnapshotAt: snapshotAt}
|
priceReferSnapshotDelete := &model.PriceReferSnapshot{SnapshotAt: snapshotAt}
|
||||||
dao.DeleteEntity(db, priceReferSnapshotDeleteHis, "SnapshotAt")
|
dao.DeleteEntity(db, priceReferSnapshotDeleteHis, "SnapshotAt")
|
||||||
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
||||||
for _, v := range priceReferSnapshot {
|
task := tasksch.NewParallelTask("生成价格统计", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
v := batchItemList[0].(*model.PriceReferSnapshot)
|
||||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||||
v.SnapshotAt = snapshotAt
|
v.SnapshotAt = snapshotAt
|
||||||
if err = dao.CreateEntity(db, v); err != nil {
|
err = dao.CreateEntity(db, v)
|
||||||
return err
|
priceRefer, err := dao.GetPriceReferUnitPrice(db, v.CityCode, v.NameID, v.SnapshotAt)
|
||||||
}
|
v.MidUnitPrice = priceRefer.MidUnitPrice
|
||||||
}
|
v.MaxUnitPrice = priceRefer.MaxUnitPrice
|
||||||
|
v.MinUnitPrice = priceRefer.MinUnitPrice
|
||||||
|
v.AvgUnitPrice = priceRefer.AvgUnitPrice
|
||||||
|
_, err = dao.UpdateEntity(db, v, "MidUnitPrice", "MaxUnitPrice", "AvgUnitPrice", "MinUnitPrice")
|
||||||
|
return retVal, err
|
||||||
|
}, priceReferSnapshot)
|
||||||
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
|
_, err = task.GetResult(0)
|
||||||
dao.Commit(db)
|
dao.Commit(db)
|
||||||
globals.SugarLogger.Debugf("CreatePriceRefer")
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ type PriceReferSnapshotExt struct {
|
|||||||
model.PriceReferSnapshot
|
model.PriceReferSnapshot
|
||||||
CityName string `json:"cityName"`
|
CityName string `json:"cityName"`
|
||||||
SkuName string `json:"skuName"`
|
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) {
|
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||||
sql := `
|
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(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(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(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(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,
|
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,
|
||||||
@@ -216,6 +215,7 @@ func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (p
|
|||||||
t1.avg_vendor_price
|
t1.avg_vendor_price
|
||||||
FROM store_sku_bind a
|
FROM store_sku_bind a
|
||||||
JOIN store b ON a.store_id = b.id AND b.deleted_at = ? AND b.status != ?
|
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 (
|
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
|
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
|
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)) + ")"
|
sql += " AND b.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||||
sqlParams = append(sqlParams, 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 {
|
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||||
return priceReferSnapshot, nil
|
return priceReferSnapshot, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
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 := `
|
sql := `
|
||||||
SELECT SQL_CALC_FOUND_ROWS a.*,b.name city_name
|
SELECT SQL_CALC_FOUND_ROWS a.*,b.name city_name
|
||||||
FROM price_refer_snapshot a
|
FROM price_refer_snapshot a
|
||||||
@@ -258,6 +258,10 @@ func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int, snapDate time.Tim
|
|||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
utils.DefaultTimeValue,
|
utils.DefaultTimeValue,
|
||||||
}
|
}
|
||||||
|
if skuNameID > 0 {
|
||||||
|
sql += " AND a.name_id = ?"
|
||||||
|
sqlParams = append(sqlParams, skuNameID)
|
||||||
|
}
|
||||||
if len(skuIDs) > 0 {
|
if len(skuIDs) > 0 {
|
||||||
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||||
sqlParams = append(sqlParams, skuIDs)
|
sqlParams = append(sqlParams, skuIDs)
|
||||||
|
|||||||
@@ -1367,33 +1367,42 @@ func GetStoreSkuBindByNameID(db *DaoDB, storeID, nameID, status int) (storeSkuBi
|
|||||||
return storeSkuBind, err
|
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 (
|
var (
|
||||||
sku []*model.SkuAndName
|
pRefer []*PriceReferSnapshotExt
|
||||||
skuMap = make(map[int]int)
|
minUnitPrice int
|
||||||
|
maxUnitPrice int
|
||||||
|
midUnitPrice int
|
||||||
|
avgUnitPrice int
|
||||||
)
|
)
|
||||||
sql := `
|
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
|
FROM price_refer_snapshot a
|
||||||
JOIN sku b ON a.sku_id = b.id
|
JOIN sku b ON a.sku_id = b.id
|
||||||
JOIN sku_name c ON c.id = b.name_id
|
JOIN sku_name c ON c.id = b.name_id
|
||||||
WHERE c.id = ?
|
WHERE 1=1
|
||||||
AND a.snapshot_at = ?
|
AND a.snapshot_at = ?
|
||||||
AND a.city_code = ?
|
AND a.city_code = ?
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
skuNameID,
|
|
||||||
snapDate,
|
snapDate,
|
||||||
cityCode,
|
cityCode,
|
||||||
}
|
}
|
||||||
err = GetRows(db, &sku, sql, sqlParams...)
|
if nameID > 0 {
|
||||||
if err != nil {
|
sql += " AND a.id = ?"
|
||||||
return 0, err
|
sqlParams = append(sqlParams, nameID)
|
||||||
}
|
}
|
||||||
if len(sku) > 0 {
|
err = GetRows(db, &pRefer, sql, sqlParams...)
|
||||||
for _, v := range sku {
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(pRefer) > 0 {
|
||||||
|
for _, v := range pRefer {
|
||||||
var (
|
var (
|
||||||
price int
|
minPrice int
|
||||||
|
maxPrice int
|
||||||
|
midPrice int
|
||||||
|
avgPrice int
|
||||||
specQuality float64
|
specQuality float64
|
||||||
)
|
)
|
||||||
if v.Unit == model.SpecialUnit {
|
if v.Unit == model.SpecialUnit {
|
||||||
@@ -1402,14 +1411,25 @@ func GetMidPriceByNameID(db *DaoDB, cityCode, skuNameID int, snapDate time.Time)
|
|||||||
} else {
|
} else {
|
||||||
specQuality = float64(v.SpecQuality)
|
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 {
|
} else {
|
||||||
price = v.Price
|
maxPrice = v.MaxPrice
|
||||||
|
minPrice = v.MinPrice
|
||||||
|
avgPrice = v.AvgPrice
|
||||||
|
midPrice = v.MidPrice
|
||||||
}
|
}
|
||||||
if skuMap[skuNameID] < price {
|
minUnitPrice += minPrice
|
||||||
skuMap[skuNameID] = price
|
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 result, err
|
||||||
return skuMap[skuNameID], err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -444,6 +444,7 @@ type PriceReferSnapshot struct {
|
|||||||
SnapshotAt time.Time `orm:"type(datetime)" json:"snapshotAt"` // 这个不同于CreatedAt,SnapshotAt是逻辑上的时间,CreatedAt是实际存储的时间
|
SnapshotAt time.Time `orm:"type(datetime)" json:"snapshotAt"` // 这个不同于CreatedAt,SnapshotAt是逻辑上的时间,CreatedAt是实际存储的时间
|
||||||
CityCode int `json:"cityCode"`
|
CityCode int `json:"cityCode"`
|
||||||
SkuID int `orm:"column(sku_id)" json:"skuId"`
|
SkuID int `orm:"column(sku_id)" json:"skuId"`
|
||||||
|
NameID int `orm:"column(name_id)" json:"nameID"`
|
||||||
MaxPrice int `json:"maxPrice"`
|
MaxPrice int `json:"maxPrice"`
|
||||||
MinPrice int `json:"minPrice"`
|
MinPrice int `json:"minPrice"`
|
||||||
AvgPrice int `json:"avgPrice"`
|
AvgPrice int `json:"avgPrice"`
|
||||||
|
|||||||
Reference in New Issue
Block a user