门店价格插叙

This commit is contained in:
suyl
2019-12-07 20:26:52 +08:00
parent 6eb984987d
commit 4caf019e70
7 changed files with 124 additions and 26 deletions

View File

@@ -2413,16 +2413,43 @@ func StoreStatus2Chinese(status int) (str string) {
} }
} }
func GetStorePriceScore(ctx *jxcontext.Context, storeIDs []int, snapDate string, offset, pageSize int) (storePriceScoreEx *dao.StorePriceScoreEx, err error) { func GetStorePriceScore(ctx *jxcontext.Context, storeIDs []int, fromScore, toScore, sort int, snapDate string, offset, pageSize int) (storePriceScoreEx *dao.StorePriceScoreEx, err error) {
var snapDateParam time.Time var snapDateParam time.Time
db := dao.GetDB() db := dao.GetDB()
if snapDate != "" { if snapDate != "" {
snapDateParam = utils.Str2Time(snapDate) snapDateParam = utils.Str2Time(snapDate)
} }
storePriceScore, totalCount, err := dao.GetStorePriceScore(db, storeIDs, snapDateParam, offset, pageSize) storePriceScore, totalCount, err := dao.GetStorePriceScore(db, storeIDs, fromScore, toScore, sort, snapDateParam, offset, pageSize)
storePriceScoreEx = &dao.StorePriceScoreEx{ storePriceScoreEx = &dao.StorePriceScoreEx{
StorePriceScoreList: storePriceScore, StorePriceScoreList: storePriceScore,
TotalCount: totalCount, TotalCount: totalCount,
} }
return storePriceScoreEx, err return storePriceScoreEx, err
} }
func CreateStorePriceScore(ctx *jxcontext.Context) (err error) {
db := dao.GetDB()
snapshotAt := utils.Time2Date(time.Now())
storePriceScoreSnapshot, err := dao.GetStorePriceScoreSnapshot(db, snapshotAt)
if len(storePriceScoreSnapshot) > 0 {
dao.Begin(db)
defer func() {
if r := recover(); r != nil || err != nil {
dao.Rollback(db)
if r != nil {
panic(r)
}
}
}()
dao.DeleteEntity(db, storePriceScoreSnapshot[0], "SnapshotAt")
for _, v := range storePriceScoreSnapshot {
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
v.SnapshotAt = snapshotAt
if err = dao.CreateEntity(db, v); err != nil {
return err
}
}
dao.Commit(db)
}
return err
}

View File

@@ -134,6 +134,9 @@ func Init() {
ScheduleTimerFunc("BeginSavePriceRefer", func() { ScheduleTimerFunc("BeginSavePriceRefer", func() {
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil) report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil)
}, createStorePriceTimeList) }, createStorePriceTimeList)
ScheduleTimerFunc("CreateStorePriceScore", func() {
cms.CreateStorePriceScore(jxcontext.AdminCtx)
}, openRemoteStoreTimeList)
} }
ScheduleTimerFunc("AutoSaleStoreSku", func() { ScheduleTimerFunc("AutoSaleStoreSku", func() {
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false) cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)

View File

@@ -57,7 +57,7 @@ type CityBrankBranch struct {
} }
type StorePriceScore struct { type StorePriceScore struct {
StoreID int `json:"storeID"` StoreID int `orm:"column(store_id)" json:"storeID"`
StoreName string `json:"storeName"` StoreName string `json:"storeName"`
StoreScore float64 `json:"storeScore"` StoreScore float64 `json:"storeScore"`
CityName string `json:"cityName"` CityName string `json:"cityName"`
@@ -475,20 +475,18 @@ func GetStoreMapsListWithoutDisabled(db *DaoDB, vendorIDs []int, status int) (st
return storeMapList, err return storeMapList, err
} }
func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, pageSize int) (StorePriceScore []*StorePriceScore, totalCount int, err error) { func GetStorePriceScore(db *DaoDB, storeIDs []int, fromScore, toScore, sort int, snapDate time.Time, offset, pageSize int) (StorePriceScore []*StorePriceScore, totalCount int, err error) {
sql := ` sql := `
SELECT SQL_CALC_FOUND_ROWS SELECT SQL_CALC_FOUND_ROWS a.store_id,score store_score,e.name city_name,b.name store_name
t1.* FROM( FROM store_price_score_snapshot a
SELECT c.store_id,d.name store_name,e.name city_name,ROUND(count(c.price/100 <= a.mid_price or NULL)/count(*)*100,2) store_score JOIN store b ON b.id = a.store_id
FROM price_refer_snapshot a JOIN place e ON e.code = b.city_code
JOIN store_sku_bind c ON c.sku_id = a.sku_id AND c.status = 1 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 !=-2
JOIN place e ON e.code = d.city_code
WHERE 1=1 WHERE 1=1
` AND a.score BETWEEN ? AND ?
`
sqlParams := []interface{}{ sqlParams := []interface{}{
utils.DefaultTimeValue, fromScore,
utils.DefaultTimeValue, toScore,
} }
if len(storeIDs) > 0 { if len(storeIDs) > 0 {
sql += " AND c.store_id IN(" + GenQuestionMarks(len(storeIDs)) + ")" sql += " AND c.store_id IN(" + GenQuestionMarks(len(storeIDs)) + ")"
@@ -498,11 +496,12 @@ func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, p
sql += " AND a.snapshot_at = ?" sql += " AND a.snapshot_at = ?"
sqlParams = append(sqlParams, snapDate) sqlParams = append(sqlParams, snapDate)
} }
sql += ` if sort == 0 {
GROUP BY c.store_id)t1 sql += " ORDER BY a.score"
ORDER BY t1.store_score } else {
LIMIT ? OFFSET ? sql += " ORDER BY a.score DESC"
` }
sql += " LIMIT ? OFFSET ?"
sqlParams = append(sqlParams, pageSize, offset) sqlParams = append(sqlParams, pageSize, offset)
Begin(db) Begin(db)
defer Commit(db) defer Commit(db)
@@ -511,3 +510,27 @@ func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, p
} }
return StorePriceScore, totalCount, err return StorePriceScore, totalCount, err
} }
func GetStorePriceScoreSnapshot(db *DaoDB, snapDate time.Time) (storePriceScoreSnapshot []*model.StorePriceScoreSnapshot, err error) {
sql := `
SELECT c.store_id,ROUND(count(c.price/100 <= 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 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,
}
if !utils.IsTimeZero(snapDate) {
sql += " AND a.snapshot_at = ?"
sqlParams = append(sqlParams, snapDate)
}
sql += `
GROUP BY c.store_id
`
err = GetRows(db, &storePriceScoreSnapshot, sql, sqlParams...)
return storePriceScoreSnapshot, err
}

View File

@@ -465,6 +465,25 @@ func (*PriceReferSnapshot) TableIndex() [][]string {
} }
} }
type StorePriceScoreSnapshot struct {
ModelIDCULD
SnapshotAt time.Time `orm:"type(datetime)" json:"snapshotAt"` // 这个不同于CreatedAtSnapshotAt是逻辑上的时间CreatedAt是实际存储的时间
StoreID int `orm:"column(store_id)" json:"storeID"`
Score float64 `json:"score"`
}
func (*StorePriceScoreSnapshot) TableUnique() [][]string {
return [][]string{
[]string{"StoreID", "Score", "SnapshotAt"},
}
}
func (*StorePriceScoreSnapshot) TableIndex() [][]string {
return [][]string{
[]string{"SnapshotAt"},
}
}
type VendorStoreSnapshot struct { type VendorStoreSnapshot struct {
ModelIDCULD ModelIDCULD

View File

@@ -586,11 +586,14 @@ func (c *StoreController) GetVendorStoreInfo() {
// @Title 查询门店价格评分 // @Title 查询门店价格评分
// @Description 查询门店价格评分 // @Description 查询门店价格评分
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Param storeIDs query string false "门店列表" // @Param storeIDs formData string false "门店列表"
// @Param snapDate query string true "时间,默认格式2006-01-02" // @Param snapDate formData string true "时间,默认前一格式2006-01-02"
// @Param offset query int false "门店列表起始序号以0开始缺省为0" // @Param fromScore formData int false "分数范围开始 默认0"
// @Param pageSize query int false "门店列表页大小缺省为50-1表示全部" // @Param toScore formData int false "分数范围结束 默认100"
// @Param sort formData int false "排序默认降序0为降序1为升序"
// @Param offset formData int false "门店列表起始序号以0开始缺省为0"
// @Param pageSize formData int false "门店列表页大小缺省为50-1表示全部"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult
// @router /GetStorePriceScore [post] // @router /GetStorePriceScore [post]
@@ -598,8 +601,21 @@ func (c *StoreController) GetStorePriceScore() {
var storeIDList []int var storeIDList []int
c.callGetStorePriceScore(func(params *tStoreGetStorePriceScoreParams) (retVal interface{}, errCode string, err error) { c.callGetStorePriceScore(func(params *tStoreGetStorePriceScoreParams) (retVal interface{}, errCode string, err error) {
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
retVal, err = cms.GetStorePriceScore(params.Ctx, storeIDList, params.SnapDate, params.Offset, params.PageSize) retVal, err = cms.GetStorePriceScore(params.Ctx, storeIDList, params.FromScore, params.ToScore, params.Sort, params.SnapDate, params.Offset, params.PageSize)
} }
return retVal, "", err return retVal, "", err
}) })
} }
// @Title 生成门店价格分数表
// @Description 生成门店价格分数表
// @Param token header string true "认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateStorePriceScore [post]
func (c *StoreController) CreateStorePriceScore() {
c.callCreateStorePriceScore(func(params *tStoreCreateStorePriceScoreParams) (retVal interface{}, errCode string, err error) {
err = cms.CreateStorePriceScore(params.Ctx)
return retVal, "", err
})
}

View File

@@ -39,6 +39,7 @@ func Init() {
orm.RegisterModel(&model.PageShop{}) orm.RegisterModel(&model.PageShop{})
orm.RegisterModel(&model.VendorStoreSnapshot{}) orm.RegisterModel(&model.VendorStoreSnapshot{})
orm.RegisterModel(&model.PriceReferSnapshot{}) orm.RegisterModel(&model.PriceReferSnapshot{})
orm.RegisterModel(&model.StorePriceScoreSnapshot{})
// orm.RegisterModel(&model.ActivityForSku{}) // orm.RegisterModel(&model.ActivityForSku{})
// orm.RegisterModel(&legacymodel.JxBadComments2{}) // orm.RegisterModel(&legacymodel.JxBadComments2{})

View File

@@ -1075,7 +1075,7 @@ func init() {
beego.ControllerComments{ beego.ControllerComments{
Method: "StatisticsReportForStoreSkusPrice", Method: "StatisticsReportForStoreSkusPrice",
Router: `/StatisticsReportForStoreSkusPrice`, Router: `/StatisticsReportForStoreSkusPrice`,
AllowHTTPMethods: []string{"Get"}, AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(), MethodParams: param.Make(),
Filters: nil, Filters: nil,
Params: nil}) Params: nil})
@@ -1305,6 +1305,15 @@ func init() {
Filters: nil, Filters: nil,
Params: nil}) Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
beego.ControllerComments{
Method: "CreateStorePriceScore",
Router: `/CreateStorePriceScore`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
beego.ControllerComments{ beego.ControllerComments{
Method: "DeleteStore", Method: "DeleteStore",