Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark

This commit is contained in:
gazebo
2019-12-06 18:38:45 +08:00
7 changed files with 166 additions and 15 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) (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)
storePriceScoreEx = &dao.StorePriceScoreEx{
StorePriceScoreList: storePriceScore,
TotalCount: totalCount,
}
return storePriceScoreEx, err
}

View File

@@ -2161,16 +2161,16 @@ func ReCalculateJxPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
return err
}
func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuName []*model.SkuName, err error) {
func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuAndName []*model.SkuAndName, err error) {
if len(storeIDs) == 0 {
return skuName, err
return skuAndName, err
}
db := dao.GetDB()
skuName, err = dao.GetTopSkusByStoreIDs(db, storeIDs)
skuAndName, err = dao.GetTopSkusByStoreIDs(db, storeIDs)
if err != nil {
return nil, err
}
return skuName, err
return skuAndName, err
}
func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
@@ -2184,3 +2184,9 @@ func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCateg
}
return skuCategory, err
}
func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
db := dao.GetDB()
_, err = dao.RefershStoreSkusMidPrice(db, storeIDs)
return err
}

View File

@@ -56,6 +56,18 @@ type CityBrankBranch struct {
PayeeBankCode string `orm:"size(8)" json:"payeeBankCode"` // 开户行代码
}
type StorePriceScore struct {
StoreID int `json:"storeID"`
StoreName string `json:"storeName"`
StoreScore float64 `json:"storeScore"`
CityName string `json:"cityName"`
}
type StorePriceScoreEx struct {
StorePriceScoreList []*StorePriceScore `json:"storePriceScoreList"`
TotalCount int `json:"totalCount"`
}
func (s *StoreDetail) GetPricePerentage(price int) (pricePercentage int) {
return pricePercentage
}
@@ -462,3 +474,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) (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
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, &StorePriceScore, sql, sqlParams...); err == nil {
totalCount = GetLastTotalRowCount(db)
}
return StorePriceScore, totalCount, err
}

View File

@@ -660,11 +660,11 @@ func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*St
return skuList, err
}
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuName []*model.SkuName, err error) {
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndName []*model.SkuAndName, err error) {
sql := `
SELECT t3.*
FROM(
SELECT SUM(b.count) count,d.id
SELECT SUM(b.count) count,c.id
FROM goods_order a
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ?
@@ -678,7 +678,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuName []*model.SkuName,
time.Now().AddDate(0, -1, 0),
}
if len(storeIDs) > 0 {
sql += " AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")"
sql += " AND a.store_id IN(" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
sql += `
@@ -689,8 +689,8 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuName []*model.SkuName,
LIMIT ?
`
sqlParams = append(sqlParams, 100, 30)
err = GetRows(db, &skuName, sql, sqlParams...)
return skuName, err
err = GetRows(db, &skuAndName, sql, sqlParams...)
return skuAndName, err
}
func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
@@ -705,19 +705,22 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ?
JOIN sku_name d ON d.id = c.name_id AND d.deleted_at = ?
WHERE 1=1
AND a.order_created_at BETWEEN ? and NOW()
JOIN store e ON e.id = a.store_id
JOIN (SELECT city_code FROM store WHERE 1=1
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
utils.DefaultTimeValue,
time.Now().AddDate(0, -1, 0),
}
if len(storeIDs) > 0 {
sql += " AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")"
sql += " AND id IN(" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
sql += `
)t6 ON t6.city_code = e.city_code
WHERE 1=1
AND a.order_created_at BETWEEN ? and NOW()
AND b.sale_price > ?
GROUP BY d.category_id)t1
JOIN sku_category t3 ON t1.category_id = t3.id
@@ -729,11 +732,35 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.
Order by t4.count DESC)t5
LIMIT ?
`
sqlParams = append(sqlParams, 100, 2, utils.DefaultTimeValue, 1, 10)
sqlParams = append(sqlParams, time.Now().AddDate(0, -1, 0), 100, 2, utils.DefaultTimeValue, 1, 10)
err = GetRows(db, &skuCategory, sql, sqlParams...)
return skuCategory, err
}
func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, err error) {
sql := `
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,
}
if len(storeIDs) > 0 {
sql += " AND a.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
sql += `
AND a.price > b.mid_price*100
AND a.deleted_at = ?
AND a.status = ?
`
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.SkuStatusNormal)
return ExecuteSQL(db, sql, sqlParams)
}
func SetStoreSkuBindVendorPrice(storeSkuBind *model.StoreSkuBind, vendorID int, vendorPrice int) {
switch vendorID {
case model.VendorIDJD:

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

@@ -481,3 +481,20 @@ func (c *StoreSkuController) GetTopCategorysByStoreIDs() {
return retVal, "", err
})
}
// @Title 根据门店刷新中位价
// @Description 根据门店刷新中位价
// @Param token header string true "认证token"
// @Param storeIDs query string true "门店列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefershStoreSkusMidPrice [put]
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 {
err = cms.RefershStoreSkusMidPrice(params.Ctx, storeIDList)
}
return retVal, "", err
})
}

View File

@@ -1075,7 +1075,7 @@ func init() {
beego.ControllerComments{
Method: "StatisticsReportForStoreSkusPrice",
Router: `/StatisticsReportForStoreSkusPrice`,
AllowHTTPMethods: []string{"post"},
AllowHTTPMethods: []string{"Get"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
@@ -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",
@@ -1620,6 +1629,15 @@ 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: "RefershStoreSkusMidPrice",
Router: `/RefershStoreSkusMidPrice`,
AllowHTTPMethods: []string{"put"},
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: "RefreshStoresSkuByVendor",