门店价格

This commit is contained in:
苏尹岚
2019-12-06 18:12:01 +08:00
parent 6e976487cb
commit 06cea8a047
7 changed files with 98 additions and 64 deletions

View File

@@ -2412,3 +2412,17 @@ func StoreStatus2Chinese(status int) (str string) {
return "未知的营业状态"
}
}
func GetStorePriceScore(ctx *jxcontext.Context, storeIDs []int, snapDate string, offset, pageSize int) (storeTotalScoreEx *model.StoreTotalScoreEx, err error) {
var snapDateParam time.Time
db := dao.GetDB()
if snapDate != "" {
snapDateParam = utils.Str2Time(snapDate)
}
storeTotalScore, totalCount, err := dao.GetStorePriceScore(db, storeIDs, snapDateParam, offset, pageSize)
storeTotalScoreEx = &model.StoreTotalScoreEx{
StoreTotalScoreList: storeTotalScore,
TotalCount: totalCount,
}
return storeTotalScoreEx, err
}

View File

@@ -2185,16 +2185,8 @@ func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCateg
return skuCategory, err
}
func GetStorePriceScore(ctx *jxcontext.Context, storeIDs []int, snapDate string, offset, pageSize int) (storeTotalScoreEx *model.StoreTotalScoreEx, err error) {
var snapDateParam time.Time
func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
db := dao.GetDB()
if snapDate != "" {
snapDateParam = utils.Str2Time(snapDate)
}
storeTotalScore, totalCount, err := dao.GetStorePriceScore(db, storeIDs, snapDateParam, offset, pageSize)
storeTotalScoreEx = &model.StoreTotalScoreEx{
StoreTotalScoreList: storeTotalScore,
TotalCount: totalCount,
}
return storeTotalScoreEx, err
_, err = dao.RefershStoreSkusMidPrice(db, storeIDs)
return err
}

View File

@@ -462,3 +462,40 @@ func GetStoreMapsListWithoutDisabled(db *DaoDB, vendorIDs []int, status int) (st
err = GetRows(db, &storeMapList, sql, sqlParams...)
return storeMapList, err
}
func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, pageSize int) (storeTotalScore []*model.StoreTotalScore, 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
WHERE 1=1
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
utils.DefaultTimeValue,
}
if len(storeIDs) > 0 {
sql += " AND c.store_id IN(" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
if !utils.IsTimeZero(snapDate) {
sql += " AND a.snapshot_at = ?"
sqlParams = append(sqlParams, snapDate)
}
sql += `
GROUP BY c.store_id)t1
ORDER BY t1.store_score
LIMIT ? OFFSET ?
`
sqlParams = append(sqlParams, pageSize, offset)
Begin(db)
defer Commit(db)
if err = GetRows(db, &storeTotalScore, sql, sqlParams...); err == nil {
totalCount = GetLastTotalRowCount(db)
}
return storeTotalScore, totalCount, err
}

View File

@@ -737,37 +737,28 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.
return skuCategory, err
}
func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, pageSize int) (storeTotalScore []*model.StoreTotalScore, totalCount int, err error) {
func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, 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
UPDATE store_sku_bind a
JOIN store d ON d.id = a.store_id
JOIN price_refer_snapshot b ON a.sku_id = b.sku_id AND b.snapshot_at = ? AND d.city_code = b.city_code
SET a.price = b.mid_price*100
WHERE 1=1
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
utils.DefaultTimeValue,
}
if !utils.IsTimeZero(snapDate) {
sql += " AND a.snapshot_at = ?"
sqlParams = append(sqlParams, snapDate)
if len(storeIDs) > 0 {
sql += " AND a.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
sql += `
GROUP BY c.store_id)t1
ORDER BY t1.store_score
LIMIT ? OFFSET ?
AND a.price > b.mid_price*100
AND a.deleted_at = ?
AND a.status = ?
`
sqlParams = append(sqlParams, pageSize, offset)
Begin(db)
defer Commit(db)
if err = GetRows(db, &storeTotalScore, sql, sqlParams...); err == nil {
totalCount = GetLastTotalRowCount(db)
}
return storeTotalScore, totalCount, err
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.SkuStatusNormal)
return ExecuteSQL(db, sql, sqlParams)
}
func SetStoreSkuBindVendorPrice(storeSkuBind *model.StoreSkuBind, vendorID int, vendorPrice int) {

View File

@@ -583,3 +583,23 @@ func (c *StoreController) GetVendorStoreInfo() {
return retVal, "", err
})
}
// @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表示全部"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetStorePriceScore [post]
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)
}
return retVal, "", err
})
}

View File

@@ -484,7 +484,7 @@ func (c *StoreSkuController) GetTopCategorysByStoreIDs() {
// @Title 根据门店刷新中位价
// @Description 根据门店刷新中位价
// @Param token header string false "认证token"
// @Param token header string true "认证token"
// @Param storeIDs query string true "门店列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
@@ -493,27 +493,7 @@ func (c *StoreSkuController) RefershStoreSkusMidPrice() {
var storeIDList []int
c.callRefershStoreSkusMidPrice(func(params *tStoreSkuRefershStoreSkusMidPriceParams) (retVal interface{}, errCode string, err error) {
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
// cms.RefershStoreSkusMidPrice()
}
return retVal, "", err
})
}
// @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表示全部"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetStorePriceScore [post]
func (c *StoreSkuController) GetStorePriceScore() {
var storeIDList []int
c.callGetStorePriceScore(func(params *tStoreSkuGetStorePriceScoreParams) (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)
err = cms.RefershStoreSkusMidPrice(params.Ctx, storeIDList)
}
return retVal, "", err
})

View File

@@ -1386,6 +1386,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: "GetStorePriceScore",
Router: `/GetStorePriceScore`,
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: "GetStoreTotalScoreList",
@@ -1566,15 +1575,6 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
beego.ControllerComments{
Method: "GetStorePriceScore",
Router: `/GetStorePriceScore`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
beego.ControllerComments{
Method: "GetStoreSkus",