Merge remote-tracking branch 'origin/mark' into su

This commit is contained in:
苏尹岚
2019-11-14 11:45:32 +08:00
11 changed files with 322 additions and 49 deletions

View File

@@ -354,7 +354,11 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
vendorStoreMap[v.VendorID] = append(vendorStoreMap[v.VendorID], v.StoreID)
}
for vendorID, storeIDs := range vendorStoreMap {
dao.SetStoreSkuSyncStatus(db, vendorID, storeIDs, nil, model.SyncFlagPriceMask)
if vendorID != model.VendorIDJX {
dao.SetStoreSkuSyncStatus(db, vendorID, storeIDs, nil, model.SyncFlagPriceMask)
} else {
ReCalculateJxPrice(ctx, storeIDs)
}
}
// for _, v := range storeMapList {
// if _, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, &model.StoreSkuBind{}, nil, ctx.GetUserName(), map[string]interface{}{

View File

@@ -66,12 +66,16 @@ type StoreSkuExt struct {
JdPrice int `json:"jdPrice"`
EbaiPrice int `json:"ebaiPrice"`
MtwmPrice int `json:"mtwmPrice"`
// WscPrice int `json:"wscPrice"`
JxPrice int `json:"jxPrice"`
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
ActPrice int `json:"actPrice"`
EarningPrice int `json:"earningPrice"`
ActPrice int `json:"actPrice"`
ActID int `orm:"column(act_id)" json:"actID"`
EarningPrice int `json:"earningPrice"`
EarningActID int `orm:"column(earning_act_id)" json:"earningActID"`
RealEarningPrice int `json:"realEarningPrice"`
Count int `json:"count"`
@@ -198,7 +202,8 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
sql += `
JOIN (
SELECT t2.store_id, t2.sku_id,
MIN(IF(t3.actual_act_price = 0, NULL, t3.actual_act_price)) actual_act_price, MIN(IF(t2.earning_price = 0, NULL, t2.earning_price)) earning_price /*non-zero min value*/
MIN(IF(t3.actual_act_price <= 0, NULL, t3.actual_act_price)) actual_act_price, /*non-zero min value*/
MIN(IF(t2.earning_price <= 0, NULL, t2.earning_price)) earning_price /*non-zero min value*/
FROM act t1
JOIN act_store_sku t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
JOIN act_store_sku_map t3 ON t3.bind_id = t2.id AND t3.act_id = t1.id AND (t3.sync_status & ? = 0 OR t1.type = ?)
@@ -443,7 +448,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
t4.sub_store_id, t4.price bind_price, IF(t4.unit_price IS NOT NULL, t4.unit_price, t1.price) unit_price, t4.status store_sku_status, t4.auto_sale_at,
t4.ebai_id, t4.mtwm_id,
t4.jd_sync_status, t4.ebai_sync_status, t4.mtwm_sync_status,
t4.jd_price, t4.ebai_price, t4.mtwm_price
t4.jd_price, t4.ebai_price, t4.mtwm_price, t4.jx_price
` + sql
var tmpList []*tGetStoresSkusInfo
beginTime := time.Now()
@@ -486,8 +491,12 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
if true { //!(offset == 0 && pageSize == model.UnlimitedPageSize) {
storeIDs, skuIDs = GetStoreAndSkuIDsFromInfo(skuNamesInfo)
}
actVendorID := -1
if params["actVendorID"] != nil {
actVendorID = int(utils.Interface2Int64WithDefault(params["actVendorID"], -1))
}
beginTime := time.Now()
err = updateActPrice4StoreSkuNameNew(db, storeIDs, skuIDs, skuNamesInfo)
err = updateActPrice4StoreSkuNameNew(db, storeIDs, skuIDs, skuNamesInfo, actVendorID)
globals.SugarLogger.Debugf("GetStoresSkusNew updateActPrice4StoreSkuName:%v", time.Now().Sub(beginTime))
if !isFocus {
err = updateUnitPrice4StoreSkuNameNew(db, skuNamesInfo)
@@ -534,11 +543,15 @@ func updateUnitPrice4StoreSkuNameNew(db *dao.DaoDB, skuNamesInfo *StoreSkuNamesI
}
// skuIDs为空会导致性能极低所以要skuIDs必须有值
func updateActPrice4StoreSkuNameNew(db *dao.DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo) (err error) {
func updateActPrice4StoreSkuNameNew(db *dao.DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo, actVendorID int) (err error) {
if len(skuIDs) == 0 {
return nil
}
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, nil, storeIDs, skuIDs, time.Now(), time.Now())
var vendorIDs []int
if actVendorID >= 0 {
vendorIDs = []int{actVendorID}
}
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, vendorIDs, storeIDs, skuIDs, time.Now(), time.Now())
if err != nil {
globals.SugarLogger.Errorf("updateActPrice4StoreSkuNameNew can not get sku promotion info for error:%v", err)
return err
@@ -551,9 +564,11 @@ func updateActPrice4StoreSkuNameNew(db *dao.DaoDB, storeIDs, skuIDs []int, skuNa
for _, v := range skuName.Skus2 {
if actStoreSku := actStoreSkuMap4Act.GetActStoreSku(skuName.StoreID, v.SkuID, -1); actStoreSku != nil {
v.ActPrice = int(actStoreSku.ActualActPrice)
v.ActID = actStoreSku.ActID
}
if actStoreSku := actStoreSkuMap4EarningPrice.GetActStoreSku(skuName.StoreID, v.SkuID, -1); actStoreSku != nil {
v.EarningPrice = int(actStoreSku.EarningPrice)
v.EarningActID = actStoreSku.ActID
}
v.RealEarningPrice = v.EarningPrice
@@ -924,6 +939,12 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
}
}()
for _, storeID := range storeIDs {
// todo 可以考虑在需要更新价格再获取
storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeID, model.VendorIDJX)
if err != nil {
dao.Rollback(db)
return nil, err
}
for _, skuBindInfo := range skuBindInfos {
// 关注且没有给价时需要尝试从store_sku_bind中得到已有的单价
needGetExistingUnitPrice := skuBindInfo.UnitPrice == 0 && skuBindInfo.IsFocus == 1
@@ -1001,6 +1022,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
Price: jxutils.CaculateSkuPrice(unitPrice, v.SpecQuality, v.SpecUnit, v.SkuNameUnit),
Status: model.StoreSkuBindStatusDontSale, // 缺省不可售?
}
skuBind.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), skuBind.Price)
if tmpStatus := getSkuSaleStatus(inSkuBind, skuBindInfo); tmpStatus != model.StoreSkuBindStatusNA {
skuBind.Status = tmpStatus
}
@@ -1048,9 +1070,11 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
if skuBindInfo.UnitPrice != 0 && isCanChangePrice { // 这里是否需要加此条件限制
skuBind.UnitPrice = unitPrice
skuBind.Price = jxutils.CaculateSkuPrice(unitPrice, v.SpecQuality, v.SpecUnit, v.SkuNameUnit)
skuBind.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), skuBind.Price)
setStoreSkuBindStatus(skuBind, model.SyncFlagPriceMask)
updateFieldMap["UnitPrice"] = 1
updateFieldMap["Price"] = 1
updateFieldMap["JxPrice"] = 1
}
// todo 这里应该是不需处理这个信息的吧?
// if inSkuBind != nil && inSkuBind.EbaiID != 0 {
@@ -1267,6 +1291,7 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
SET t1.last_operator = ?,
t1.updated_at = ?,
t1.price = t1.price * ? / 100,
t1.jx_price = t1.jx_price * ? / 100,
t1.unit_price = t1.unit_price * ? / 100,
t1.jd_sync_status = t1.jd_sync_status | ?,
t1.mtwm_sync_status = t1.mtwm_sync_status | ?,
@@ -1281,6 +1306,7 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
now,
pricePercentage,
pricePercentage,
pricePercentage,
model.SyncFlagPriceMask,
model.SyncFlagPriceMask,
model.SyncFlagPriceMask,
@@ -1307,13 +1333,14 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
JOIN sku t2 ON t1.sku_id = t2.id/* AND t2.deleted_at = ?*/
JOIN sku_name t3 ON t2.name_id = t3.id/* AND t2.deleted_at = ?*/
LEFT JOIN sku_category t4 ON t3.category_id = t4.id AND t2.deleted_at = ?
SET t1.deleted_at = ?,
t1.updated_at = ?,
t1.last_operator = ?,
t1.status = ?,
t1.jd_sync_status = IF((t1.jd_sync_status & ?) <> 0, 0, ?),
t1.mtwm_sync_status = IF((t1.mtwm_sync_status & ?) <> 0, 0, ?),
t1.ebai_sync_status = IF((t1.ebai_sync_status & ?) <> 0, 0, ?)
SET
t1.deleted_at = ?,
t1.updated_at = ?,
t1.last_operator = ?,
t1.status = ?,
t1.jd_sync_status = IF((t1.jd_sync_status & ?) <> 0, 0, ?),
t1.mtwm_sync_status = IF((t1.mtwm_sync_status & ?) <> 0, 0, ?),
t1.ebai_sync_status = IF((t1.ebai_sync_status & ?) <> 0, 0, ?)
WHERE t1.store_id = ? AND t1.deleted_at = ? AND t0.id IS NULL
`
sqlDeleteParams := []interface{}{
@@ -1356,10 +1383,12 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
JOIN sku t2 ON t1.sku_id = t2.id/* AND t2.deleted_at = ?*/
JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
LEFT JOIN sku_category t4 ON t3.category_id = t4.id AND t4.deleted_at = ?
SET t1.last_operator = ?,
SET
t1.last_operator = ?,
t1.updated_at = ?,
t1.sub_store_id = 0,
t1.price = IF(t0.price * ? / 100 > 0, t0.price * ? / 100, 1),
t1.jx_price = IF(t0.jx_price * ? / 100 > 0, t0.jx_price * ? / 100, 1),
t1.unit_price = IF(t0.unit_price * ? / 100 > 0, t0.unit_price * ? / 100, 1),
t1.status = IF(? = 0, t1.status, t0.status),
t1.jd_sync_status = t1.jd_sync_status | ?,
@@ -1379,6 +1408,8 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
pricePercentage,
pricePercentage,
pricePercentage,
pricePercentage,
pricePercentage,
isModifyStatus,
syncStatus,
syncStatus,
@@ -1397,10 +1428,11 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
// 添加toStore中不存在但fromStore存在的
sql = `
INSERT INTO store_sku_bind(created_at, updated_at, last_operator, deleted_at, store_id, sku_id, sub_store_id, price, unit_price, status,
INSERT INTO store_sku_bind(created_at, updated_at, last_operator, deleted_at, store_id, sku_id, sub_store_id, price, jx_price, unit_price, status,
jd_sync_status, ebai_sync_status, mtwm_sync_status)
SELECT ?, ?, ?, ?, ?,
t1.sku_id, 0, IF(t1.price * ? / 100 > 0, t1.price * ? / 100, 1), IF(t1.unit_price * ? / 100 > 0, t1.unit_price * ? / 100, 1),
t1.sku_id, 0,
IF(t1.price * ? / 100 > 0, t1.price * ? / 100, 1), IF(t1.jx_price * ? / 100 > 0, t1.jx_price * ? / 100, 1), IF(t1.unit_price * ? / 100 > 0, t1.unit_price * ? / 100, 1),
IF(? = 0, ?, t1.status), ?, ?, ?
FROM store_sku_bind t1
JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ?
@@ -1415,6 +1447,8 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
pricePercentage,
pricePercentage,
pricePercentage,
pricePercentage,
pricePercentage,
isModifyStatus,
model.SkuStatusDontSale,
model.SyncFlagNewMask,
@@ -2045,3 +2079,22 @@ func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int, isNeedSync bool) (
}
return err
}
func ReCalculateJxPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
db := dao.GetDB()
for _, storeID := range storeIDs {
if storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJX); err == nil {
if storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, nil); err == nil {
for _, skuBind := range storeSkuList {
skuBind.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), skuBind.Price)
dao.UpdateEntity(db, skuBind)
}
} else {
return err
}
} else {
return err
}
}
return err
}

View File

@@ -213,8 +213,7 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack model.PricePercentagePack, pricePercentage int) (outSku *dao.StoreSkuSyncInfo) {
if inSku.VendorPrice <= 0 { // 避免重新计算
pricePercentage2, priceAdd2 := jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage)
inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage2, priceAdd2))
inSku.VendorPrice = int64(jxutils.CaculatePriceByPricePack(pricePercentagePack, pricePercentage, int(inSku.Price)))
if inSku.VendorPrice <= 0 {
inSku.VendorPrice = 1 // 最少1分钱
}
@@ -348,7 +347,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))
if singleStoreHandler == nil {
sku.StoreSkuSyncStatus |= model.SyncFlagSaleMask | model.SyncFlagPriceMask
bareSku = storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
bareSku = storeSkuSyncInfo2Bare(sku)
stockList = append(stockList, bareSku)
priceList = append(priceList, bareSku)
if sku.MergedStatus == model.SkuStatusNormal {