改价实际上是改活动价?

This commit is contained in:
苏尹岚
2020-08-18 17:00:13 +08:00
parent 055bf5dc8a
commit baf83d0ad0
4 changed files with 48 additions and 44 deletions

View File

@@ -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)

View File

@@ -228,6 +228,8 @@ type ActStoreSku2 struct {
SpecQuality float32 `json:"-"`
SpecUnit string `json:"-"`
Comment string `json:"-"`
TrendType int `json:"trendType"` //折扣活动使用涨跌趋势1为涨2为跌0为不动
TrendPrcie int `json:"trendPrice"` //涨跌具体多少
}
type StoreSkuAct struct {

View File

@@ -83,7 +83,7 @@ func GetActStoreSkuVendorList(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
sql := fmt.Sprintf(`
SELECT SQL_CALC_FOUND_ROWS
t1.*,
t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status, t2.actual_act_price, t2.vendor_price,
t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status, t2.actual_act_price, t2.vendor_price, t2.trend_type, t2.trend_price,
t3.vendor_store_id,
CASE t2.vendor_id
WHEN 0 THEN

View File

@@ -1368,8 +1368,8 @@ func UpdateActPrice4StoreSkuNameNew(db *DaoDB, storeIDs, skuIDs []int, skuNamesI
v.ActID = actStoreSku.ActID
v.ActType = actStoreSku.Type
v.EarningPrice = int(jxutils.CaculateSkuEarningPrice(int64(v.BindPrice), int64(v.ActPrice), skuName.PayPercentage))
// v.TrendType = actStoreSku.TrendType
// v.TrendPrice = actStoreSku.TrendPrcie
v.TrendType = actStoreSku.TrendType
v.TrendPrice = actStoreSku.TrendPrcie
}
if actStoreSku := actStoreSkuMap4EarningPrice.GetActStoreSku(skuName.StoreID, v.SkuID, -1); actStoreSku != nil {
v.EarningPrice = int(actStoreSku.EarningPrice)