价格统计
This commit is contained in:
@@ -2965,7 +2965,7 @@ func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
for _, v := range storeList {
|
||||
storeSkuList, _ := dao.GetStoreSkusAndSkuName(db, []int{v.ID}, skuIDs)
|
||||
storeSkuList, _ := dao.GetStoreSkusAndSkuName(db, []int{v.ID}, skuIDs, nil)
|
||||
for _, vv := range storeSkuList {
|
||||
if nameMap[vv.ID] != nil {
|
||||
nameMap[vv.ID].Skus = append(nameMap[vv.ID].Skus, &StoreSkuBindSkuInfo{
|
||||
|
||||
@@ -216,7 +216,7 @@ func doDailyWork() {
|
||||
|
||||
// 每天补全前一天与当天的订单
|
||||
curDate := utils.Time2Date(time.Now())
|
||||
orderman.FixedOrderManager.AmendMissingOrders(jxcontext.AdminCtx, nil, 0, curDate.Add(-24*time.Hour), curDate, true, true)
|
||||
orderman.FixedOrderManager.AmendMissingOrders(jxcontext.AdminCtx, nil, 0, curDate.Add(-72*time.Hour), curDate, true, true)
|
||||
//订单门店归属补漏
|
||||
//fromDate, toDate都不传默认刷新当前天5天以前的订单,只传fromDate默认刷新fromDate到当天的订单
|
||||
//只传toDate默认刷新toDate到5天以前的订单
|
||||
|
||||
@@ -81,5 +81,26 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e
|
||||
_, err = task.GetResult(0)
|
||||
dao.Commit(db)
|
||||
}
|
||||
priceReferSnapshotList, err := dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, snapshotAt)
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if len(priceReferSnapshotList) > 0 {
|
||||
for _, v := range priceReferSnapshotList {
|
||||
result, _ := dao.GetPriceReferPrice(db, v.CityCode, v.SkuID, snapshotAt)
|
||||
v.MaxPrice = result.MaxPrice
|
||||
v.MinPrice = result.MinPrice
|
||||
v.AvgPrice = result.AvgPrice
|
||||
v.MidPrice = result.MidPrice
|
||||
dao.UpdateEntity(db, v, "MidPrice", "MaxPrice", "MinPrice", "AvgPrice")
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -191,10 +191,6 @@ 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,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,
|
||||
@@ -227,14 +223,12 @@ func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (p
|
||||
GROUP BY 2
|
||||
)t1 ON t1.sku_id = a.sku_id
|
||||
WHERE a.deleted_at = ?
|
||||
AND a.status = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
time.Now().AddDate(0, -1, 0),
|
||||
utils.DefaultTimeValue,
|
||||
model.SkuStatusNormal,
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
|
||||
@@ -569,14 +569,13 @@ func GetStorePriceScoreSnapshot(db *DaoDB, snapDate time.Time) (storePriceScoreS
|
||||
sql := `
|
||||
SELECT c.store_id,ROUND(count(c.price <= a.mid_price or NULL)/count(*)*100,2) score
|
||||
FROM price_refer_snapshot a
|
||||
JOIN store_sku_bind c ON c.sku_id = a.sku_id AND c.status = 1 AND c.deleted_at = ?
|
||||
JOIN store_sku_bind c ON c.sku_id = a.sku_id AND c.status = ? AND c.deleted_at = ?
|
||||
JOIN store d ON c.store_id = d.id AND d.city_code = a.city_code AND d.deleted_at = ? AND d.status != ?
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
model.StoreSkuBindStatusNormal, utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue, model.StoreStatusDisabled,
|
||||
}
|
||||
if !utils.IsTimeZero(snapDate) {
|
||||
sql += " AND a.snapshot_at = ?"
|
||||
|
||||
@@ -132,6 +132,7 @@ type StoreSkuNameExt struct {
|
||||
|
||||
PendingOpType int8 `json:"pendingOpType"` // 取值同 StoreOpRequest.Type
|
||||
PendingUnitPrice int `json:"pendingUnitPrice"` // 这个是待审核的价格申请
|
||||
Status int
|
||||
}
|
||||
|
||||
// GetStoreSkus用
|
||||
@@ -1369,17 +1370,13 @@ func GetStoreSkuBindByNameID(db *DaoDB, storeID, nameID, status int) (storeSkuBi
|
||||
return storeSkuBind, err
|
||||
}
|
||||
|
||||
func GetPriceReferUnitPrice(db *DaoDB, cityCode int, nameID int, snapDate time.Time) (result *PriceReferSnapshotExt, err error) {
|
||||
func GetPriceReferPrice(db *DaoDB, cityCode int, skuID int, snapDate time.Time) (result *PriceReferSnapshotExt, err error) {
|
||||
var (
|
||||
pRefer []*PriceReferSnapshotExt
|
||||
priceRefer = &PriceReferSnapshotExt{}
|
||||
minUnitPrice int
|
||||
maxUnitPrice int
|
||||
midUnitPrice int
|
||||
avgUnitPrice int
|
||||
pRefer *PriceReferSnapshotExt
|
||||
priceRefer *PriceReferSnapshotExt
|
||||
)
|
||||
sql := `
|
||||
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
|
||||
SELECT a.max_unit_price, a.min_unit_price, a.avg_unit_price, a.mid_unit_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
|
||||
@@ -1391,53 +1388,39 @@ func GetPriceReferUnitPrice(db *DaoDB, cityCode int, nameID int, snapDate time.T
|
||||
snapDate,
|
||||
cityCode,
|
||||
}
|
||||
if nameID > 0 {
|
||||
sql += " AND a.name_id = ?"
|
||||
sqlParams = append(sqlParams, nameID)
|
||||
if skuID > 0 {
|
||||
sql += " AND a.sku_id = ?"
|
||||
sqlParams = append(sqlParams, skuID)
|
||||
}
|
||||
err = GetRows(db, &pRefer, sql, sqlParams...)
|
||||
err = GetRow(db, &pRefer, sql, sqlParams...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(pRefer) > 0 {
|
||||
for _, v := range pRefer {
|
||||
var (
|
||||
minPrice int
|
||||
maxPrice int
|
||||
midPrice int
|
||||
avgPrice int
|
||||
specQuality float64
|
||||
)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
}
|
||||
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)))
|
||||
if pRefer != nil {
|
||||
var (
|
||||
specQuality float64
|
||||
)
|
||||
if pRefer.Unit == model.SpecialUnit {
|
||||
if pRefer.SpecUnit == model.SpecUnitNames[1] || pRefer.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(pRefer.SpecQuality) * 1000
|
||||
} else {
|
||||
maxPrice = v.MaxPrice
|
||||
minPrice = v.MinPrice
|
||||
avgPrice = v.AvgPrice
|
||||
midPrice = v.MidPrice
|
||||
specQuality = float64(pRefer.SpecQuality)
|
||||
}
|
||||
minUnitPrice += minPrice
|
||||
maxUnitPrice += maxPrice
|
||||
midUnitPrice += midPrice
|
||||
avgUnitPrice += avgPrice
|
||||
priceRefer.MaxPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.MaxUnitPrice)))
|
||||
priceRefer.MinPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.MinUnitPrice)))
|
||||
priceRefer.AvgPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.AvgUnitPrice)))
|
||||
priceRefer.MidPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.MidUnitPrice)))
|
||||
} else {
|
||||
priceRefer.MaxPrice = pRefer.MaxUnitPrice
|
||||
priceRefer.MinPrice = pRefer.MinUnitPrice
|
||||
priceRefer.AvgPrice = pRefer.AvgUnitPrice
|
||||
priceRefer.MidPrice = pRefer.MidUnitPrice
|
||||
}
|
||||
priceRefer.MinUnitPrice = minUnitPrice / len(pRefer)
|
||||
priceRefer.MaxUnitPrice = maxUnitPrice / len(pRefer)
|
||||
priceRefer.AvgUnitPrice = avgUnitPrice / len(pRefer)
|
||||
priceRefer.MidUnitPrice = midUnitPrice / len(pRefer)
|
||||
}
|
||||
return priceRefer, err
|
||||
}
|
||||
|
||||
func GetStoreSkusAndSkuName(db *DaoDB, storeIDs, skuIDs []int) (storeSkuNameExt []*StoreSkuNameExt, err error) {
|
||||
func GetStoreSkusAndSkuName(db *DaoDB, storeIDs, skuIDs, nameIDs []int) (storeSkuNameExt []*StoreSkuNameExt, err error) {
|
||||
sql := `
|
||||
SELECT a.*,c.id
|
||||
FROM store_sku_bind a
|
||||
@@ -1458,6 +1441,10 @@ func GetStoreSkusAndSkuName(db *DaoDB, storeIDs, skuIDs []int) (storeSkuNameExt
|
||||
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(nameIDs) > 0 {
|
||||
sql += " AND b.name_id IN (" + GenQuestionMarks(len(nameIDs)) + ")"
|
||||
sqlParams = append(sqlParams, nameIDs)
|
||||
}
|
||||
err = GetRows(db, &storeSkuNameExt, sql, sqlParams...)
|
||||
return storeSkuNameExt, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user