Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark
This commit is contained in:
@@ -4,9 +4,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
@@ -34,7 +36,34 @@ func GetStatisticsReportForAfsOrders(ctx *jxcontext.Context, storeIDs []int, fro
|
||||
return statisticsReportForOrdersList, err
|
||||
}
|
||||
|
||||
func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err error) {
|
||||
func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs []int) (priceRefer []*model.PriceReferSnapshot, err error) {
|
||||
db := dao.GetDB()
|
||||
return dao.GetStatisticsReportForStoreSkusPrice(db, cityCodes, skuIDs)
|
||||
return dao.GetPriceReferSnapshot(db, cityCodes, skuIDs)
|
||||
}
|
||||
|
||||
func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err error) {
|
||||
db := dao.GetDB()
|
||||
snapshotAt := utils.Time2Date(time.Now())
|
||||
priceReferSnapshot, err := dao.GetStatisticsReportForStoreSkusPrice(db, cityCodes, skuIDs)
|
||||
if len(priceReferSnapshot) > 0 {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
dao.DeleteEntity(db, priceReferSnapshot[0], "SnapshotAt")
|
||||
for _, v := range priceReferSnapshot {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
v.SnapshotAt = snapshotAt
|
||||
if err = dao.CreateEntity(db, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -178,7 +178,82 @@ func GetGetStatisticsReportForAfsOrders(db *DaoDB, storeIDs []int, fromDate time
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (err error) {
|
||||
|
||||
return err
|
||||
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||
sql := `
|
||||
SELECT b.city_code,a.sku_id,
|
||||
MAX(a.price/100) max_price,
|
||||
MIN(a.price/100) min_price,
|
||||
ROUND(AVG(a.price/100),2) avg_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.price/100 ORDER BY a.price/100),',',Count(1)/2),',',-1),2) mid_price,
|
||||
MAX(a.jd_price/100) max_jd_price,
|
||||
MIN(a.jd_price/100) min_jd_price,
|
||||
ROUND(AVG(a.jd_price/100),2) avg_jd_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.jd_price/100 ORDER BY a.jd_price/100),',',Count(1)/2),',',-1),2) mid_jd_price,
|
||||
MAX(a.ebai_price/100) max_ebai_price,
|
||||
MIN(a.ebai_price/100) min_ebai_price,
|
||||
ROUND(AVG(a.ebai_price/100),2) avg_ebai_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.ebai_price/100 ORDER BY a.ebai_price/100),',',Count(1)/2),',',-1),2) mid_ebai_price,
|
||||
MAX(a.mtwm_price/100) max_mtwm_price,
|
||||
MIN(a.mtwm_price/100) min_mtwm_price,
|
||||
ROUND(AVG(a.mtwm_price/100),2) avg_mtwm_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.mtwm_price/100 ORDER BY a.mtwm_price/100),',',Count(1)/2),',',-1),2) mid_mtwm_price,
|
||||
t1.max_sale_price,
|
||||
t1.min_sale_price,
|
||||
t1.avg_sale_price,
|
||||
t1.max_vendor_price,
|
||||
t1.min_vendor_price,
|
||||
t1.avg_vendor_price
|
||||
FROM store_sku_bind a
|
||||
JOIN store b ON a.store_id = b.id AND b.deleted_at = ?
|
||||
JOIN sku d ON a.sku_id = d.id AND d.deleted_at = ?
|
||||
LEFT JOIN (
|
||||
SELECT SUM(t1.count),t1.sku_id,MAX(t1.sale_price/100) max_sale_price,MIN(t1.sale_price/100) min_sale_price,ROUND(AVG(t1.sale_price/100),2) avg_sale_price,MAX(t1.vendor_price/100) max_vendor_price,MIN(t1.vendor_price/100) min_vendor_price,ROUND(AVG(t1.vendor_price/100),2) avg_vendor_price
|
||||
FROM order_sku t1
|
||||
WHERE t1.order_created_at BETWEEN ? AND NOW()
|
||||
GROUP BY 2
|
||||
)t1 ON t1.sku_id = a.sku_id
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
time.Now().AddDate(0, -1, 0),
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND b.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
sql += " GROUP BY 1,2"
|
||||
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||
return priceReferSnapshot, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM price_refer_snapshot
|
||||
WHERE 1=1
|
||||
AND delete_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||
return priceReferSnapshot, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -422,6 +422,47 @@ func (*StoreCourierMap) TableUnique() [][]string {
|
||||
}
|
||||
}
|
||||
|
||||
type PriceReferSnapshot struct {
|
||||
ModelIDCULD
|
||||
SnapshotAt time.Time `orm:"type(datetime)" json:"snapshotAt"` // 这个不同于CreatedAt,SnapshotAt是逻辑上的时间,CreatedAt是实际存储的时间
|
||||
CityCode int `json:"cityCode"`
|
||||
SkuID int `orm:"column(sku_id)" json:"skuId"`
|
||||
MaxPrice float64 `json:"maxPrice"`
|
||||
MinPrice float64 `json:"minPrice"`
|
||||
AvgPrice float64 `json:"avgPrice"`
|
||||
MidPrice float64 `json:"midPrice"`
|
||||
MaxJdPrice float64 `json:"maxJdPrice"`
|
||||
MinJdPrice float64 `json:"minJdPrice"`
|
||||
AvgJdPrice float64 `json:"avgJdPrice"`
|
||||
MidJdPrice float64 `json:"midJdPrice"`
|
||||
MaxEbaiPrice float64 `json:"maxEbaiPrice"`
|
||||
MinEbaiPrice float64 `json:"minEbaiPrice"`
|
||||
AvgEbaiPrice float64 `json:"avgEbaiPrice"`
|
||||
MidEbaiPrice float64 `json:"midEbaiPrice"`
|
||||
MaxMtwmPrice float64 `json:"maxMtwmPrice"`
|
||||
MinMtwmPrice float64 `json:"minMtwmPrice"`
|
||||
AvgMtwmPrice float64 `json:"avgMtwmPrice"`
|
||||
MidMtwmPrice float64 `json:"midMtwmPrice"`
|
||||
MaxSalePrice float64 `json:"maxSalePrice"`
|
||||
MinSalePrice float64 `json:"minSalePrice"`
|
||||
AvgSalePrice float64 `json:"avgSalePrice"`
|
||||
MaxVendorPrice float64 `json:"maxVendorPrice"`
|
||||
MinVendorPrice float64 `json:"minVendorPrice"`
|
||||
AvgVendorPrice float64 `json:"avgVendorPrice"`
|
||||
}
|
||||
|
||||
func (*PriceReferSnapshot) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CityCode", "SkuID", "SnapshotAt"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*PriceReferSnapshot) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"SnapshotAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type VendorStoreSnapshot struct {
|
||||
ModelIDCULD
|
||||
|
||||
|
||||
@@ -61,8 +61,21 @@ func (c *ReportController) StatisticsReportForStoreSkusPrice() {
|
||||
c.callStatisticsReportForStoreSkusPrice(func(params *tReportStatisticsReportForStoreSkusPriceParams) (retVal interface{}, errCode string, err error) {
|
||||
var cityCodeList, skuIDList []int
|
||||
if err = jxutils.Strings2Objs(params.CityCodes, &cityCodeList, params.SkuIDs, &skuIDList); err == nil {
|
||||
err = report.StatisticsReportForStoreSkusPrice(params.Ctx, cityCodeList, skuIDList)
|
||||
retVal, err = report.StatisticsReportForStoreSkusPrice(params.Ctx, cityCodeList, skuIDList)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 生成价格参考数据
|
||||
// @Description 生成价格参考数据
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /PriceRefer [post]
|
||||
func (c *ReportController) PriceRefer() {
|
||||
c.callPriceRefer(func(params *tReportPriceReferParams) (retVal interface{}, errCode string, err error) {
|
||||
report.BeginSavePriceRefer(params.Ctx, nil, nil)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ func Init() {
|
||||
|
||||
orm.RegisterModel(&model.PageShop{})
|
||||
orm.RegisterModel(&model.VendorStoreSnapshot{})
|
||||
orm.RegisterModel(&model.PriceReferSnapshot{})
|
||||
|
||||
// orm.RegisterModel(&model.ActivityForSku{})
|
||||
// orm.RegisterModel(&legacymodel.JxBadComments2{})
|
||||
|
||||
@@ -1044,6 +1044,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"],
|
||||
beego.ControllerComments{
|
||||
Method: "PriceRefer",
|
||||
Router: `/PriceRefer`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"],
|
||||
beego.ControllerComments{
|
||||
Method: "StatisticsReportForAfsOrders",
|
||||
|
||||
Reference in New Issue
Block a user