Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark
This commit is contained in:
@@ -140,6 +140,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"refundStatusName": model.RefundStatusName,
|
||||
"autoReplyTypeName": model.AutoReplyTypeName,
|
||||
"complaintReasons": model.ComplaintReasons,
|
||||
"supplementType": model.SupplementTypeName,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2595,7 +2595,7 @@ func CreateStorePriceScore(ctx *jxcontext.Context) (err error) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
priceReferSnapshotDeleteHis := &model.StorePriceScoreSnapshot{SnapshotAt: snapshotAt.AddDate(0, -1, 0)}
|
||||
priceReferSnapshotDeleteHis := &model.StorePriceScoreSnapshot{SnapshotAt: snapshotAt.AddDate(0, 0, -7)}
|
||||
priceReferSnapshotDelete := &model.StorePriceScoreSnapshot{SnapshotAt: snapshotAt}
|
||||
dao.DeleteEntity(db, priceReferSnapshotDeleteHis, "SnapshotAt")
|
||||
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
||||
|
||||
@@ -154,6 +154,11 @@ type DataLock struct {
|
||||
locker sync.RWMutex
|
||||
}
|
||||
|
||||
type tUpdateStoresSkus struct {
|
||||
StoreID int
|
||||
SkuBindInfos []*StoreSkuBindInfo
|
||||
}
|
||||
|
||||
const (
|
||||
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
@@ -2243,9 +2248,9 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
|
||||
}
|
||||
for _, v := range skuNameAndPlace {
|
||||
if skuNameMap[v.ID] != nil {
|
||||
midPrice, _ := dao.GetMidPriceByNameID(db, cityCode, v.ID, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
if midPrice != 0 {
|
||||
v.Price = midPrice
|
||||
priceReferList, _, _ := dao.GetPriceReferSnapshot(db, []int{cityCode}, nil, v.ID, utils.Time2Date(time.Now().AddDate(0, 0, -1)), 0, 9999)
|
||||
if len(priceReferList) > 0 {
|
||||
v.Price = priceReferList[0].MidUnitPrice
|
||||
}
|
||||
v.Type = skuNameMap[v.ID].BrandID
|
||||
skuNameAndPlaceList = append(skuNameAndPlaceList, v)
|
||||
@@ -2310,7 +2315,39 @@ func GetTopCategoriesByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCate
|
||||
|
||||
func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
|
||||
db := dao.GetDB()
|
||||
_, err = dao.RefershStoreSkusMidPrice(db, storeIDs)
|
||||
if len(storeIDs) == 0 {
|
||||
return err
|
||||
}
|
||||
for _, v := range storeIDs {
|
||||
var skuBindInfos []*StoreSkuBindInfo
|
||||
store, err := dao.GetStoreDetail(db, v, -1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var payPercentage int
|
||||
if store.PayPercentage < 50 {
|
||||
payPercentage = 70
|
||||
} else {
|
||||
payPercentage = store.PayPercentage
|
||||
}
|
||||
storeSkuList, err := dao.GetStoresSkusInfo(db, []int{v}, nil)
|
||||
for _, storeSku := range storeSkuList {
|
||||
priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, []int{storeSku.SkuID}, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(priceReferList) > 0 {
|
||||
if storeSku.UnitPrice > priceReferList[0].MidUnitPrice*payPercentage/100 {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: priceReferList[0].NameID,
|
||||
UnitPrice: priceReferList[0].MidUnitPrice * payPercentage / 100,
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false)
|
||||
}
|
||||
if err == nil {
|
||||
CreateStorePriceScore(ctx)
|
||||
}
|
||||
@@ -2760,22 +2797,20 @@ func FocusStoreSkusByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader
|
||||
|
||||
func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
skuMap = make(map[int]int)
|
||||
skuNameMap = make(map[int]int)
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
db = dao.GetDB()
|
||||
storeIDs []int
|
||||
skuIDs []int
|
||||
skuMap = make(map[int]int)
|
||||
db = dao.GetDB()
|
||||
skuIDs []int
|
||||
result1 []interface{}
|
||||
)
|
||||
sheetParam := &SheetParam{
|
||||
OutSkuIDCol: 1,
|
||||
SkuPriceCol: 3,
|
||||
SkuRow: 1,
|
||||
}
|
||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
xlsx, err := excelize.OpenReader(reader)
|
||||
if err != nil {
|
||||
return result, err
|
||||
@@ -2792,43 +2827,72 @@ func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync,
|
||||
skuIDs = append(skuIDs, k)
|
||||
}
|
||||
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
if err != nil && len(skuList) == 0 {
|
||||
return result, err
|
||||
}
|
||||
for _, v := range skuList {
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
var (
|
||||
price int
|
||||
specQuality float64
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
skuNameMap = make(map[int]int)
|
||||
skuInfoMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
for _, v := range skuList {
|
||||
var (
|
||||
price int
|
||||
specQuality float64
|
||||
)
|
||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, v.NameID, model.StoreSkuBindStatusNormal)
|
||||
//有关注过
|
||||
if len(focusList) > 0 {
|
||||
price = focusList[0].UnitPrice
|
||||
skuInfoMap[v.NameID] = append(skuInfoMap[v.NameID], &StoreSkuBindSkuInfo{
|
||||
SkuID: v.ID,
|
||||
IsSale: 1,
|
||||
})
|
||||
skuNameMap[v.NameID] = price
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
}
|
||||
price = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(skuMap[v.ID])))
|
||||
} else {
|
||||
price = skuMap[v.ID]
|
||||
}
|
||||
if skuNameMap[v.NameID] < price {
|
||||
skuNameMap[v.NameID] = price
|
||||
}
|
||||
}
|
||||
price = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(skuMap[v.ID])))
|
||||
} else {
|
||||
price = skuMap[v.ID]
|
||||
}
|
||||
if skuNameMap[v.NameID] < price {
|
||||
skuNameMap[v.NameID] = price
|
||||
for k, v := range skuNameMap {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: v,
|
||||
IsFocus: 1,
|
||||
IsSale: 1,
|
||||
Skus: skuInfoMap[k],
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
}
|
||||
for k, v := range skuNameMap {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: v,
|
||||
IsFocus: 1,
|
||||
IsSale: 1,
|
||||
tUpdate := &tUpdateStoresSkus{
|
||||
StoreID: store.ID,
|
||||
SkuBindInfos: skuBindInfos,
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
for _, v := range storeList {
|
||||
storeIDs = append(storeIDs, v.ID)
|
||||
retVal = []*tUpdateStoresSkus{tUpdate}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("根据skuID关注商品", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
result1, _ = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
for _, v := range result1 {
|
||||
tUpdate := v.(*tUpdateStoresSkus)
|
||||
UpdateStoresSkus(ctx, []int{tUpdate.StoreID}, tUpdate.SkuBindInfos, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
@@ -2861,9 +2925,9 @@ func GetCellForFocusStoreSkus(db *dao.DaoDB, rowNum int, row []string, sheetPara
|
||||
|
||||
func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
skuNameMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
storeIDs []int
|
||||
skuNameMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
storeIDs []int
|
||||
result1 []interface{}
|
||||
)
|
||||
db := dao.GetDB()
|
||||
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||
@@ -2883,26 +2947,42 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
|
||||
case 1:
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
var skuBindInfos []*StoreSkuBindInfo
|
||||
for k, v := range skuNameMap {
|
||||
midPrice, _ := dao.GetMidPriceByNameID(db, store.CityCode, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
var price int
|
||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, k, model.StoreSkuBindStatusNormal)
|
||||
//有关注过
|
||||
if len(focusList) > 0 {
|
||||
price = focusList[0].UnitPrice
|
||||
} else {
|
||||
priceReferList, _, _ := dao.GetPriceReferSnapshot(db, []int{store.CityCode}, nil, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)), 0, 9999)
|
||||
if len(priceReferList) > 0 {
|
||||
price = priceReferList[0].MidUnitPrice
|
||||
}
|
||||
}
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: midPrice,
|
||||
UnitPrice: price,
|
||||
IsFocus: 1,
|
||||
Skus: v,
|
||||
}
|
||||
retVal = []*StoreSkuBindInfo{skuBindInfo}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
tUpdate := &tUpdateStoresSkus{
|
||||
StoreID: store.ID,
|
||||
SkuBindInfos: skuBindInfos,
|
||||
}
|
||||
retVal = []*tUpdateStoresSkus{tUpdate}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("根据skuID部分关注商品", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
result1, _ := taskParallel.GetResult(0)
|
||||
for _, v := range result1 {
|
||||
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
||||
}
|
||||
result1, _ = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
for _, v := range result1 {
|
||||
tUpdate := v.(*tUpdateStoresSkus)
|
||||
UpdateStoresSkus(ctx, []int{tUpdate.StoreID}, tUpdate.SkuBindInfos, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
@@ -2917,6 +2997,63 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync bool) (err error) {
|
||||
var (
|
||||
nameMap = make(map[int]*StoreSkuBindInfo)
|
||||
)
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
for _, v := range storeList {
|
||||
storeSkuList, _ := dao.GetStoreSkusAndSkuName(db, []int{v.ID}, skuIDs, nil)
|
||||
for _, vv := range storeSkuList {
|
||||
if nameMap[vv.ID] != nil {
|
||||
nameMap[vv.ID].Skus = append(nameMap[vv.ID].Skus, &StoreSkuBindSkuInfo{
|
||||
SkuID: vv.SkuID,
|
||||
})
|
||||
} else {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
UnitPrice: vv.UnitPrice,
|
||||
NameID: vv.ID,
|
||||
StoreID: v.ID,
|
||||
Skus: []*StoreSkuBindSkuInfo{},
|
||||
}
|
||||
nameMap[vv.ID] = skuBindInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range nameMap {
|
||||
var skuBindInfoList []*StoreSkuBindInfo
|
||||
skuBindInfoResult := &StoreSkuBindInfo{
|
||||
NameID: v.NameID,
|
||||
UnitPrice: v.UnitPrice,
|
||||
IsFocus: 1,
|
||||
}
|
||||
var skuBindSkuList []*StoreSkuBindSkuInfo
|
||||
skuMap := make(map[int]int)
|
||||
skuList, _ := dao.GetSkus(db, nil, []int{v.NameID}, nil, nil)
|
||||
if len(v.Skus) != len(skuList) {
|
||||
for _, skus := range v.Skus {
|
||||
skuMap[skus.SkuID] = 1
|
||||
}
|
||||
for _, vv := range skuList {
|
||||
if skuMap[vv.ID] != 1 {
|
||||
continue
|
||||
}
|
||||
skuBindSkuList = append(skuBindSkuList, &StoreSkuBindSkuInfo{
|
||||
SkuID: vv.ID,
|
||||
IsSale: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
skuBindInfoList = append(skuBindInfoList, skuBindInfoResult)
|
||||
if isSync {
|
||||
UpdateStoreSkus(ctx, v.StoreID, skuBindInfoList, true, true)
|
||||
} else {
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v.StoreID}, skuBindInfoList, false)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
func UpdateStoreSkuNamePrice(ctx *jxcontext.Context, storeID, nameID, unitPrice int, isAsync bool) (hint string, err error) {
|
||||
// db := dao.GetDB()
|
||||
// skuList, err := dao.GetSkus(db, nil, []int{nameID}, nil, nil)
|
||||
|
||||
9
business/jxstore/event/event.go
Normal file
9
business/jxstore/event/event.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package event
|
||||
|
||||
func AddOperateEvent() {
|
||||
|
||||
}
|
||||
|
||||
func AddOperateEventDetail() {
|
||||
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func Init() {
|
||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, true)
|
||||
}, ChangeStoreSkuSaleStatusList)
|
||||
ScheduleTimerFunc("BeginSavePriceRefer", func() {
|
||||
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil)
|
||||
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil, true, true)
|
||||
}, priceReferTimeList)
|
||||
ScheduleTimerFunc("CreateStorePriceScore", func() {
|
||||
cms.CreateStorePriceScore(jxcontext.AdminCtx)
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -14,6 +15,14 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
type tStoreSkuBindAndSkuName struct {
|
||||
CityCode int
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
NameID int `orm:"column(name_id)"`
|
||||
UnitPrice int
|
||||
UnitPriceList []int
|
||||
}
|
||||
|
||||
func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) {
|
||||
db := dao.GetDB()
|
||||
fromDateParm := utils.Str2Time(fromDate)
|
||||
@@ -44,7 +53,7 @@ func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs
|
||||
if snapDate != "" {
|
||||
snapDateParam = utils.Str2Time(snapDate)
|
||||
}
|
||||
priceReferSnapshot, totalCount, err := dao.GetPriceReferSnapshot(db, cityCodes, skuIDs, snapDateParam, offset, pageSize)
|
||||
priceReferSnapshot, totalCount, err := dao.GetPriceReferSnapshot(db, cityCodes, skuIDs, 0, snapDateParam, offset, pageSize)
|
||||
pagedInfo = &model.PagedInfo{
|
||||
Data: priceReferSnapshot,
|
||||
TotalCount: totalCount,
|
||||
@@ -52,33 +61,179 @@ func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs
|
||||
return
|
||||
}
|
||||
|
||||
func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err error) {
|
||||
func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var priceReferSnapshotList []*model.PriceReferSnapshot
|
||||
db := dao.GetDB()
|
||||
snapshotAt := utils.Time2Date(time.Now().AddDate(0, 0, -1))
|
||||
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)
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
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.DeletePriceReferHistory(db, utils.Time2Date(snapshotAt.AddDate(0, 0, -7)))
|
||||
priceReferSnapshotDelete := &model.PriceReferSnapshot{SnapshotAt: snapshotAt}
|
||||
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.PriceReferSnapshot)
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
v.SnapshotAt = snapshotAt
|
||||
err = dao.CreateEntity(db, v)
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("生成价格统计", tasksch.NewParallelConfig(), ctx, taskFunc, priceReferSnapshot)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
_, err = taskParallel.GetResult(0)
|
||||
dao.Commit(db)
|
||||
}
|
||||
case 1:
|
||||
priceReferSnapshotList, err = dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, snapshotAt)
|
||||
var (
|
||||
citySkuMap = make(map[int]map[int][]int)
|
||||
resultMap = make(map[int]map[int]*model.PriceReferSnapshot)
|
||||
)
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
for _, v := range storeList {
|
||||
var tList []*tStoreSkuBindAndSkuName
|
||||
sql := `
|
||||
SELECT DISTINCT b.city_code, a.store_id, Round(a.unit_price/IF(b.pay_percentage < 50 , 70, b.pay_percentage) * 100) AS unit_price, c.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN store b ON b.id = a.store_id AND b.deleted_at = ? AND b.status != ?
|
||||
JOIN sku c ON c.id = a.sku_id
|
||||
WHERE a.store_id = ?
|
||||
AND c.name_id NOT IN(
|
||||
SELECT b.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ?
|
||||
WHERE a.deleted_at = ?
|
||||
AND a.store_id = ?
|
||||
AND b.name_id NOT IN(SELECT DISTINCT b.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ?
|
||||
WHERE a.deleted_at = ?
|
||||
AND a.store_id = ?
|
||||
AND a.status = ?)
|
||||
)
|
||||
AND a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
v.ID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
v.ID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
v.ID,
|
||||
model.StoreSkuBindStatusNormal,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
dao.GetRows(db, &tList, sql, sqlParams...)
|
||||
skuNameMap := make(map[int][]int)
|
||||
if len(tList) > 0 {
|
||||
for _, vv := range tList {
|
||||
skuNameMap[vv.NameID] = append(skuNameMap[vv.NameID], vv.UnitPrice)
|
||||
}
|
||||
if citySkuMap[v.CityCode] != nil {
|
||||
for nameID, unitPriceList := range skuNameMap {
|
||||
if citySkuMap[v.CityCode][nameID] != nil {
|
||||
citySkuMap[v.CityCode][nameID] = append(citySkuMap[v.CityCode][nameID], unitPriceList...)
|
||||
} else {
|
||||
citySkuMap[v.CityCode][nameID] = unitPriceList
|
||||
}
|
||||
}
|
||||
} else {
|
||||
citySkuMap[v.CityCode] = skuNameMap
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
priceReferSnapshotDeleteHis := &model.PriceReferSnapshot{SnapshotAt: snapshotAt.AddDate(0, -1, 0)}
|
||||
priceReferSnapshotDelete := &model.PriceReferSnapshot{SnapshotAt: snapshotAt}
|
||||
dao.DeleteEntity(db, priceReferSnapshotDeleteHis, "SnapshotAt")
|
||||
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
||||
for _, v := range priceReferSnapshot {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
v.SnapshotAt = snapshotAt
|
||||
if err = dao.CreateEntity(db, v); err != nil {
|
||||
return err
|
||||
for k1, v := range citySkuMap {
|
||||
skuNameMap := make(map[int]*model.PriceReferSnapshot)
|
||||
for k2, _ := range v {
|
||||
var midUnitPrice int
|
||||
var avgUnitPrice int
|
||||
sort.Ints(v[k2])
|
||||
if len(v[k2])%2 == 0 {
|
||||
midUnitPrice = v[k2][len(v[k2])/2-1]
|
||||
} else {
|
||||
midUnitPrice = v[k2][len(v[k2])/2]
|
||||
}
|
||||
for _, vv := range v[k2] {
|
||||
avgUnitPrice += vv
|
||||
}
|
||||
skuNameMap[k2] = &model.PriceReferSnapshot{
|
||||
MidUnitPrice: midUnitPrice,
|
||||
MaxUnitPrice: v[k2][len(v[k2])-1],
|
||||
MinUnitPrice: v[k2][0],
|
||||
AvgUnitPrice: avgUnitPrice / len(v[k2]),
|
||||
}
|
||||
}
|
||||
resultMap[k1] = skuNameMap
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if len(priceReferSnapshotList) > 0 {
|
||||
for _, v := range priceReferSnapshotList {
|
||||
if resultMap[v.CityCode][v.NameID] != nil {
|
||||
v.MidUnitPrice = resultMap[v.CityCode][v.NameID].MidUnitPrice
|
||||
v.MaxUnitPrice = resultMap[v.CityCode][v.NameID].MaxUnitPrice
|
||||
v.AvgUnitPrice = resultMap[v.CityCode][v.NameID].AvgUnitPrice
|
||||
v.MinUnitPrice = resultMap[v.CityCode][v.NameID].MinUnitPrice
|
||||
dao.UpdateEntity(db, v, "MidUnitPrice", "MaxUnitPrice", "MinUnitPrice", "AvgUnitPrice")
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
case 2:
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if len(priceReferSnapshotList) > 0 {
|
||||
for _, v := range priceReferSnapshotList {
|
||||
result, _ := dao.GetPriceReferPrice(db, v.CityCode, v.SkuID, snapshotAt)
|
||||
v.MaxPrice = result.MaxPrice
|
||||
v.MinPrice = result.MinPrice
|
||||
v.AvgPrice = result.AvgPrice
|
||||
v.MidPrice = result.MidPrice
|
||||
dao.UpdateEntity(db, v, "MidPrice", "MaxPrice", "MinPrice", "AvgPrice")
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
dao.Commit(db)
|
||||
globals.SugarLogger.Debugf("CreatePriceRefer")
|
||||
return result, err
|
||||
}
|
||||
return err
|
||||
taskSeq := tasksch.NewSeqTask2("生成每日价格统计", ctx, isContinueWhenError, taskSeqFunc, 3)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user