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

This commit is contained in:
Rosy-zhudan
2019-07-29 08:55:54 +08:00
22 changed files with 177 additions and 92 deletions

View File

@@ -813,7 +813,10 @@ func UpdateSku(ctx *jxcontext.Context, skuID int, payload map[string]interface{}
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
dao.Begin(db)
defer func() {
dao.Rollback(db)
if r := recover(); r != nil {
dao.Rollback(db)
panic(r)
}
}()
maskValue := model.SyncFlagModifiedMask
if valid["specQuality"] != nil || valid["specUnit"] != nil {
@@ -827,21 +830,57 @@ func UpdateSku(ctx *jxcontext.Context, skuID int, payload map[string]interface{}
SET t1.spec_quality = t2.spec_quality,
t1.spec_unit = t2.spec_unit
WHERE t1.deleted_at = ? AND t2.id = ? AND t1.unit <> ?
`, utils.DefaultTimeValue, skuID, model.SpecialUnit); err != nil {
return 0, err
}
if _, err = SetStoreSkuSyncStatus2(db, nil, CurVendorSync.SingleStoreVendorIDs, []int{skuID}, model.SyncFlagModifiedMask); err == nil {
dao.Commit(db)
_, err = CurVendorSync.SyncSku(ctx, db, -1, sku.ID, false, false, userName)
`, utils.DefaultTimeValue, skuID, model.SpecialUnit); err == nil {
if _, err = SetStoreSkuSyncStatus2(db, nil, CurVendorSync.SingleStoreVendorIDs, []int{skuID}, model.SyncFlagModifiedMask); err == nil {
if maskValue&model.SyncFlagSpecMask != 0 {
err = refreshStoreSkuPrice(ctx, db, skuID)
}
}
}
} else {
err = ErrEntityNotExist
}
}
if err == nil {
dao.Commit(db)
_, err = CurVendorSync.SyncSku(ctx, db, -1, sku.ID, false, false, userName)
} else {
dao.Rollback(db)
}
}
return num, err
}
func refreshStoreSkuPrice(ctx *jxcontext.Context, db *dao.DaoDB, skuID int) (err error) {
dao.Begin(db)
defer func() {
if r := recover(); r != nil || err != nil {
dao.Rollback(db)
if r != nil {
panic(r)
}
}
}()
for vendorID := range partner.PurchasePlatformHandlers {
storeSkuList, err := dao.GetStoreSkus2(db, vendorID, 0, []int{skuID}, false)
if err == nil {
for _, v := range storeSkuList {
v.Price = int64(jxutils.CaculateSkuPrice(int(v.UnitPrice), v.SpecQuality, v.SpecUnit, v.Unit))
storeSku := &model.StoreSkuBind{}
storeSku.ID = v.BindID
if _, err = dao.UpdateEntityLogically(db, storeSku, map[string]interface{}{
"Price": v.Price,
dao.GetSyncStatusStructField(model.VendorNames[vendorID]): v.StoreSkuSyncStatus | model.SyncFlagPriceMask,
}, ctx.GetUserName(), nil); err != nil {
return err
}
}
}
}
dao.Commit(db)
return err
}
func DeleteSku(ctx *jxcontext.Context, skuID int, userName string) (num int64, err error) {
db := dao.GetDB()
dao.Begin(db)

View File

@@ -352,7 +352,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
successList = batchedStoreSkuList
}
if len(successList) > 0 {
_, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagDeletedMask)
updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagDeletedMask)
}
return nil, err
}, ctx, task, deleteList, 1 /*singleStoreHandler.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus)*/, isContinueWhenError)
@@ -376,7 +376,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
successList = batchedStoreSkuList
}
if len(successList) > 0 {
_, err = updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagNewMask)
updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagNewMask)
}
return nil, err
}, ctx, task, createList, 1 /*singleStoreHandler.GetStoreSkusBatchSize(partner.FuncCreateStoreSkus)*/, isContinueWhenError)
@@ -389,7 +389,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
successList = batchedStoreSkuList
}
if len(successList) > 0 {
_, err = updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagModifiedMask)
updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagModifiedMask)
}
return nil, err
}, ctx, task, updateList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkus), isContinueWhenError)
@@ -403,7 +403,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
successList = batchedStoreSkuList
}
if k == 0 && len(successList) > 0 {
_, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagModifiedMask) // ?
updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagModifiedMask) // ?
}
return nil, err
}, ctx, task, list, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStock), isContinueWhenError)
@@ -423,7 +423,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
successList = batchedStoreSkuList
}
if len(successList) > 0 {
_, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagSaleMask)
updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagSaleMask)
}
return nil, err
}, ctx, task, statusList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStatus), isContinueWhenError)
@@ -436,7 +436,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
successList = batchedStoreSkuList
}
if len(successList) > 0 {
_, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagPriceMask)
updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagPriceMask)
}
return nil, err
}, ctx, task, priceList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusPrice), isContinueWhenError)

View File

@@ -457,7 +457,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, vendorID int, isIDJd bool, isAsyn
modifyPrices2[k] = v.(*jdapi.SkuPriceInfo)
}
if globals.EnableJdStoreWrite {
if _, err = api.JdAPI.UpdateVendorStationPrice(utils.Int2Str(storeID), "", modifyPrices2); err != nil {
if _, err = api.JdAPI.UpdateVendorStationPrice(ctx.GetTrackInfo(), utils.Int2Str(storeID), "", modifyPrices2); err != nil {
return nil, err
}
}
@@ -783,7 +783,7 @@ func RefreshJdStoreSkuStock(promotionID int, skuIDs []int) (err error) {
promotionItem := v.(*tPromotionItemInfo)
if promotionItem.JdStoreID != stationNo {
// globals.SugarLogger.Debugf("RefreshJdStoreSkuStock BatchUpdateCurrentQtys stationNo:%s, stockList:%s", stationNo, utils.Format4Output(stockList, false))
_, err = api.JdAPI.BatchUpdateCurrentQtys("", stationNo, stockList, userName)
_, err = api.JdAPI.BatchUpdateCurrentQtys("", "", stationNo, stockList, userName)
if err != nil {
globals.SugarLogger.Warnf("RefreshJdStoreSkuStock BatchUpdateCurrentQtys failed with error:%v", err)
}
@@ -796,7 +796,7 @@ func RefreshJdStoreSkuStock(promotionID int, skuIDs []int) (err error) {
})
}
// globals.SugarLogger.Debugf("RefreshJdStoreSkuStock BatchUpdateCurrentQtys stationNo:%s, stockList:%s", stationNo, utils.Format4Output(stockList, false))
_, err = api.JdAPI.BatchUpdateCurrentQtys("", stationNo, stockList, userName)
_, err = api.JdAPI.BatchUpdateCurrentQtys("", "", stationNo, stockList, userName)
if err != nil {
globals.SugarLogger.Warnf("RefreshJdStoreSkuStock BatchUpdateCurrentQtys failed with error:%v", err)
}
@@ -952,7 +952,7 @@ func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackRe
OutSkuId: utils.Int2Str(sku.ID),
DoSale: true,
}
_, err = api.JdAPI.BatchUpdateVendibility("", msg.StationNo, []*jdapi.StockVendibility{
_, err = api.JdAPI.BatchUpdateVendibility("", "", msg.StationNo, []*jdapi.StockVendibility{
vendibility,
}, userName)
}
@@ -961,7 +961,7 @@ func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackRe
OutSkuId: utils.Int2Str(sku.ID),
StockQty: model.MaxStoreSkuStockQty,
}
_, err = api.JdAPI.BatchUpdateCurrentQtys("", msg.StationNo, []*jdapi.SkuStock{
_, err = api.JdAPI.BatchUpdateCurrentQtys("", "", msg.StationNo, []*jdapi.SkuStock{
stock,
}, userName)
}