|
|
|
|
@@ -1528,14 +1528,15 @@ func ChangeJxPriceByDiscountAct(ctx *jxcontext.Context) {
|
|
|
|
|
ModelIDCULD: model.ModelIDCULD{
|
|
|
|
|
ID: actStoreSku2.MapID,
|
|
|
|
|
},
|
|
|
|
|
// ActID: actStoreSku2.ActID,
|
|
|
|
|
// OriginalPrice: actStoreSku2.OriginalPrice,
|
|
|
|
|
// StoreID: actStoreSku2.StoreID,
|
|
|
|
|
// SkuID: actStoreSku2.SkuID,
|
|
|
|
|
// TrendPrcie: actStoreSku2.TrendPrcie,
|
|
|
|
|
// TrendType: actStoreSku2.TrendType,
|
|
|
|
|
ActID: actStoreSku2.ActID,
|
|
|
|
|
StoreID: actStoreSku2.StoreID,
|
|
|
|
|
SkuID: actStoreSku2.SkuID,
|
|
|
|
|
TrendPrcie: actStoreSku2.TrendPrcie,
|
|
|
|
|
TrendType: actStoreSku2.TrendType,
|
|
|
|
|
ActualActPrice: actStoreSku2.ActualActPrice,
|
|
|
|
|
VendorPrice: actStoreSku2.VendorPrice,
|
|
|
|
|
}
|
|
|
|
|
storeSkus, _ := dao.GetStoresSkusInfo(db, []int{actStoreSku.StoreID}, []int{actStoreSku.SkuID})
|
|
|
|
|
storeSkus, _ := dao.GetStoresSkusInfo(db, []int{actStoreSkuMap.StoreID}, []int{actStoreSkuMap.SkuID})
|
|
|
|
|
if len(storeSkus) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
@@ -1550,7 +1551,7 @@ func ChangeJxPriceByDiscountAct(ctx *jxcontext.Context) {
|
|
|
|
|
if storeSku.Stock == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
actualStockOut, err = dao.GetOrderStoreSkusCount(db, actStoreSku.StoreID, actStoreSku.SkuID, time.Now().Add(-time.Minute*10), time.Now())
|
|
|
|
|
actualStockOut, err = dao.GetOrderStoreSkusCount(db, actStoreSkuMap.StoreID, actStoreSkuMap.SkuID, time.Now().Add(-time.Minute*10), time.Now())
|
|
|
|
|
dao.Begin(db)
|
|
|
|
|
defer func() {
|
|
|
|
|
if r := recover(); r != nil || err != nil {
|
|
|
|
|
@@ -1563,12 +1564,14 @@ func ChangeJxPriceByDiscountAct(ctx *jxcontext.Context) {
|
|
|
|
|
//第一档时间内
|
|
|
|
|
if (time.Now().Hour() >= 10 && time.Now().Hour() < 20) || (time.Now().Hour() == 20 && time.Now().Minute() < 1) {
|
|
|
|
|
pricePercentage = 0.02
|
|
|
|
|
actualPrice = utils.Float64TwoInt64(float64(actStoreSku.OriginalPrice) * pricePercentage)
|
|
|
|
|
if actStoreSku.TrendType == model.TrendTypeUp {
|
|
|
|
|
storeSku.JxPrice = storeSku.JxPrice + int(actualPrice)
|
|
|
|
|
} else if actStoreSku.TrendType == model.TrendTypeDown {
|
|
|
|
|
storeSku.JxPrice = storeSku.JxPrice - int(actualPrice)
|
|
|
|
|
stock := checkPriceDefendOrderByPrice(db, storeSku.StoreID, storeSku.SkuID, storeSku.Stock, storeSku.JxPrice)
|
|
|
|
|
actualPrice = utils.Float64TwoInt64(float64(actStoreSkuMap.VendorPrice) * pricePercentage)
|
|
|
|
|
if actStoreSkuMap.TrendType == model.TrendTypeUp {
|
|
|
|
|
actStoreSkuMap.ActualActPrice = actStoreSkuMap.ActualActPrice + actualPrice
|
|
|
|
|
// storeSku.JxPrice = storeSku.JxPrice + int(actualPrice)
|
|
|
|
|
} else if actStoreSkuMap.TrendType == model.TrendTypeDown {
|
|
|
|
|
actStoreSkuMap.ActualActPrice = actStoreSkuMap.ActualActPrice - actualPrice
|
|
|
|
|
// storeSku.JxPrice = storeSku.JxPrice - int(actualPrice)
|
|
|
|
|
stock := checkPriceDefendOrderByPrice(db, storeSku.StoreID, storeSku.SkuID, storeSku.Stock, int(actStoreSkuMap.ActualActPrice))
|
|
|
|
|
if stock != -1 {
|
|
|
|
|
storeSku.Stock = stock
|
|
|
|
|
if _, err = dao.UpdateEntity(db, storeSku, "Stock"); err != nil {
|
|
|
|
|
@@ -1576,56 +1579,56 @@ func ChangeJxPriceByDiscountAct(ctx *jxcontext.Context) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if storeSku.JxPrice >= int(actStoreSku.OriginalPrice) {
|
|
|
|
|
storeSku.JxPrice = int(actStoreSku.OriginalPrice)
|
|
|
|
|
if actStoreSkuMap.ActualActPrice >= actStoreSkuMap.VendorPrice {
|
|
|
|
|
actStoreSkuMap.ActualActPrice = actStoreSkuMap.VendorPrice
|
|
|
|
|
}
|
|
|
|
|
//判断活动的折扣类型是最低价还是最低折扣(第一档)
|
|
|
|
|
if act.DiscountType == model.ActDiscountTypePrice {
|
|
|
|
|
minJxPrice = int64(act.DiscountValue1)
|
|
|
|
|
} else if act.DiscountType == model.ActDiscountTypePercentage {
|
|
|
|
|
minJxPrice = actStoreSku.OriginalPrice * int64(act.DiscountValue1) / 100
|
|
|
|
|
minJxPrice = actStoreSkuMap.VendorPrice * int64(act.DiscountValue1) / 100
|
|
|
|
|
}
|
|
|
|
|
if storeSku.JxPrice <= int(minJxPrice) {
|
|
|
|
|
storeSku.JxPrice = int(minJxPrice)
|
|
|
|
|
}
|
|
|
|
|
if _, err = dao.UpdateEntity(db, storeSku, "JxPrice"); err != nil {
|
|
|
|
|
dao.Rollback(db)
|
|
|
|
|
if actStoreSkuMap.ActualActPrice <= minJxPrice {
|
|
|
|
|
actStoreSkuMap.ActualActPrice = minJxPrice
|
|
|
|
|
}
|
|
|
|
|
// if _, err = dao.UpdateEntity(db, actStoreSkuMap, "ActualActPrice"); err != nil {
|
|
|
|
|
// dao.Rollback(db)
|
|
|
|
|
// }
|
|
|
|
|
//C >= 2N 涨价趋势,最高涨价到无折扣
|
|
|
|
|
if actualStockOut >= 2*shouldStockOut {
|
|
|
|
|
actStoreSku.TrendType = model.TrendTypeUp
|
|
|
|
|
actStoreSkuMap.TrendType = model.TrendTypeUp
|
|
|
|
|
} else if actualStockOut < shouldStockOut/2 { //C <= N/2 降价趋势,最低降价到设置到最低折扣
|
|
|
|
|
actStoreSku.TrendType = model.TrendTypeDown
|
|
|
|
|
actStoreSkuMap.TrendType = model.TrendTypeDown
|
|
|
|
|
} else {
|
|
|
|
|
actStoreSku.TrendType = model.TrendTypeNothing
|
|
|
|
|
actStoreSkuMap.TrendType = model.TrendTypeNothing
|
|
|
|
|
}
|
|
|
|
|
actStoreSku.TrendPrcie = int(actualPrice)
|
|
|
|
|
if _, err = dao.UpdateEntity(db, actStoreSku, "TrendType", "TrendPrcie"); err != nil {
|
|
|
|
|
actStoreSkuMap.TrendPrcie = int(actualPrice)
|
|
|
|
|
if _, err = dao.UpdateEntity(db, actStoreSkuMap, "ActualActPrice", "TrendType", "TrendPrcie"); err != nil {
|
|
|
|
|
dao.Rollback(db)
|
|
|
|
|
}
|
|
|
|
|
} else { //第二档时间内
|
|
|
|
|
pricePercentage = 0.1
|
|
|
|
|
actualPrice = utils.Float64TwoInt64(float64(actStoreSku.OriginalPrice) * pricePercentage)
|
|
|
|
|
actualPrice = utils.Float64TwoInt64(float64(actStoreSkuMap.VendorPrice) * pricePercentage)
|
|
|
|
|
//判断活动的折扣类型是最低价还是最低折扣(第二档)
|
|
|
|
|
if act.DiscountType == model.ActDiscountTypePrice {
|
|
|
|
|
minJxPrice = int64(act.DiscountValue2)
|
|
|
|
|
} else if act.DiscountType == model.ActDiscountTypePercentage {
|
|
|
|
|
minJxPrice = actStoreSku.OriginalPrice * int64(act.DiscountValue2) / 100
|
|
|
|
|
minJxPrice = actStoreSkuMap.VendorPrice * int64(act.DiscountValue2) / 100
|
|
|
|
|
}
|
|
|
|
|
if storeSku.JxPrice == int(minJxPrice) {
|
|
|
|
|
actStoreSku.TrendType = model.TrendTypeNothing
|
|
|
|
|
if actStoreSkuMap.ActualActPrice == minJxPrice {
|
|
|
|
|
actStoreSkuMap.TrendType = model.TrendTypeNothing
|
|
|
|
|
} else {
|
|
|
|
|
actStoreSku.TrendType = model.TrendTypeDown
|
|
|
|
|
actStoreSkuMap.TrendType = model.TrendTypeDown
|
|
|
|
|
}
|
|
|
|
|
actStoreSku.TrendPrcie = int(actualPrice)
|
|
|
|
|
if _, err = dao.UpdateEntity(db, actStoreSku, "TrendType", "TrendPrcie"); err != nil {
|
|
|
|
|
dao.Rollback(db)
|
|
|
|
|
actStoreSkuMap.TrendPrcie = int(actualPrice)
|
|
|
|
|
// if _, err = dao.UpdateEntity(db, actStoreSkuMap, "TrendType", "TrendPrcie"); err != nil {
|
|
|
|
|
// dao.Rollback(db)
|
|
|
|
|
// }
|
|
|
|
|
actStoreSkuMap.ActualActPrice = actStoreSkuMap.ActualActPrice - actualPrice
|
|
|
|
|
if actStoreSkuMap.ActualActPrice <= minJxPrice {
|
|
|
|
|
actStoreSkuMap.ActualActPrice = minJxPrice
|
|
|
|
|
}
|
|
|
|
|
storeSku.JxPrice = storeSku.JxPrice - int(actualPrice)
|
|
|
|
|
if storeSku.JxPrice <= int(minJxPrice) {
|
|
|
|
|
storeSku.JxPrice = int(minJxPrice)
|
|
|
|
|
}
|
|
|
|
|
if _, err = dao.UpdateEntity(db, storeSku, "JxPrice"); err != nil {
|
|
|
|
|
if _, err = dao.UpdateEntity(db, actStoreSkuMap, "ActualActPrice", "TrendType", "TrendPrcie"); err != nil {
|
|
|
|
|
dao.Rollback(db)
|
|
|
|
|
}
|
|
|
|
|
//22:00 恢复库存为100
|
|
|
|
|
@@ -1634,7 +1637,6 @@ func ChangeJxPriceByDiscountAct(ctx *jxcontext.Context) {
|
|
|
|
|
if _, err = dao.UpdateEntity(db, storeSku, "Stock"); err != nil {
|
|
|
|
|
dao.Rollback(db)
|
|
|
|
|
}
|
|
|
|
|
// dao.SetStoreSkuSyncStatus(db, model.VendorIDJD, []int{storeSku.StoreID}, []int{storeSku.SkuID}, model.SyncFlagStockMask)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dao.Commit(db)
|
|
|
|
|
|