From baf83d0ad09d7685b273006ebee12808b9bc87b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 18 Aug 2020 17:00:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=BB=B7=E5=AE=9E=E9=99=85=E4=B8=8A?= =?UTF-8?q?=E6=98=AF=E6=94=B9=E6=B4=BB=E5=8A=A8=E4=BB=B7=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 84 +++++++++++++++++---------------- business/model/act.go | 2 + business/model/dao/act.go | 2 +- business/model/dao/store_sku.go | 4 +- 4 files changed, 48 insertions(+), 44 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 168d00e11..fb021953f 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -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) diff --git a/business/model/act.go b/business/model/act.go index b8d266c27..d2ae8e770 100644 --- a/business/model/act.go +++ b/business/model/act.go @@ -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 { diff --git a/business/model/dao/act.go b/business/model/dao/act.go index 3ed92ef4c..df9d2ff64 100644 --- a/business/model/dao/act.go +++ b/business/model/dao/act.go @@ -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 diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 40b8dfa9c..f75733cdd 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -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)