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

This commit is contained in:
gazebo
2019-12-06 09:45:22 +08:00
6 changed files with 174 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,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
}