价格参考

This commit is contained in:
苏尹岚
2019-12-06 09:04:55 +08:00
parent 25982cf994
commit c6abdbbd3e
6 changed files with 172 additions and 6 deletions

View File

@@ -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,32 @@ 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.Str2Time(time.Now().Format("2006-01-02"))
priceReferSnapshot, err := dao.GetStatisticsReportForStoreSkusPrice(db, cityCodes, skuIDs)
dao.Begin(db)
defer func() {
if r := recover(); r != nil || err != nil {
dao.Rollback(db)
if r != nil {
panic(r)
}
}
}()
for _, v := range priceReferSnapshot {
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
v.SnapshotAt = snapshotAt
dao.DeleteEntity(db, v, "CityCode", "SkuID", "SnapshotAt")
if err = dao.CreateEntity(db, v); err != nil {
return err
}
}
dao.Commit(db)
return err
}