门店价格插叙
This commit is contained in:
@@ -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
|
||||
db := dao.GetDB()
|
||||
if 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{
|
||||
StorePriceScoreList: storePriceScore,
|
||||
TotalCount: totalCount,
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -134,6 +134,9 @@ func Init() {
|
||||
ScheduleTimerFunc("BeginSavePriceRefer", func() {
|
||||
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil)
|
||||
}, createStorePriceTimeList)
|
||||
ScheduleTimerFunc("CreateStorePriceScore", func() {
|
||||
cms.CreateStorePriceScore(jxcontext.AdminCtx)
|
||||
}, openRemoteStoreTimeList)
|
||||
}
|
||||
ScheduleTimerFunc("AutoSaleStoreSku", func() {
|
||||
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
||||
|
||||
@@ -57,7 +57,7 @@ type CityBrankBranch struct {
|
||||
}
|
||||
|
||||
type StorePriceScore struct {
|
||||
StoreID int `json:"storeID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
StoreName string `json:"storeName"`
|
||||
StoreScore float64 `json:"storeScore"`
|
||||
CityName string `json:"cityName"`
|
||||
@@ -475,20 +475,18 @@ func GetStoreMapsListWithoutDisabled(db *DaoDB, vendorIDs []int, status int) (st
|
||||
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 := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.* FROM(
|
||||
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
|
||||
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 !=-2
|
||||
JOIN place e ON e.code = d.city_code
|
||||
SELECT SQL_CALC_FOUND_ROWS a.store_id,score store_score,e.name city_name,b.name store_name
|
||||
FROM store_price_score_snapshot a
|
||||
JOIN store b ON b.id = a.store_id
|
||||
JOIN place e ON e.code = b.city_code
|
||||
WHERE 1=1
|
||||
`
|
||||
AND a.score BETWEEN ? AND ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
fromScore,
|
||||
toScore,
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
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 = ?"
|
||||
sqlParams = append(sqlParams, snapDate)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY c.store_id)t1
|
||||
ORDER BY t1.store_score
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
if sort == 0 {
|
||||
sql += " ORDER BY a.score"
|
||||
} else {
|
||||
sql += " ORDER BY a.score DESC"
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
@@ -511,3 +510,27 @@ func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, p
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -465,6 +465,25 @@ func (*PriceReferSnapshot) TableIndex() [][]string {
|
||||
}
|
||||
}
|
||||
|
||||
type StorePriceScoreSnapshot struct {
|
||||
ModelIDCULD
|
||||
SnapshotAt time.Time `orm:"type(datetime)" json:"snapshotAt"` // 这个不同于CreatedAt,SnapshotAt是逻辑上的时间,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 {
|
||||
ModelIDCULD
|
||||
|
||||
|
||||
@@ -586,11 +586,14 @@ func (c *StoreController) GetVendorStoreInfo() {
|
||||
|
||||
// @Title 查询门店价格评分
|
||||
// @Description 查询门店价格评分
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs query string false "门店列表"
|
||||
// @Param snapDate query string true "时间,默认当天(格式2006-01-02"
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs formData string false "门店列表"
|
||||
// @Param snapDate formData string true "时间,默认前一天(格式2006-01-02"
|
||||
// @Param fromScore formData int false "分数范围开始 默认0"
|
||||
// @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
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetStorePriceScore [post]
|
||||
@@ -598,8 +601,21 @@ func (c *StoreController) GetStorePriceScore() {
|
||||
var storeIDList []int
|
||||
c.callGetStorePriceScore(func(params *tStoreGetStorePriceScoreParams) (retVal interface{}, errCode string, err error) {
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
// @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
|
||||
})
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ func Init() {
|
||||
orm.RegisterModel(&model.PageShop{})
|
||||
orm.RegisterModel(&model.VendorStoreSnapshot{})
|
||||
orm.RegisterModel(&model.PriceReferSnapshot{})
|
||||
orm.RegisterModel(&model.StorePriceScoreSnapshot{})
|
||||
|
||||
// orm.RegisterModel(&model.ActivityForSku{})
|
||||
// orm.RegisterModel(&legacymodel.JxBadComments2{})
|
||||
|
||||
@@ -1075,7 +1075,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "StatisticsReportForStoreSkusPrice",
|
||||
Router: `/StatisticsReportForStoreSkusPrice`,
|
||||
AllowHTTPMethods: []string{"Get"},
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
@@ -1305,6 +1305,15 @@ func init() {
|
||||
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.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.ControllerComments{
|
||||
Method: "DeleteStore",
|
||||
|
||||
Reference in New Issue
Block a user