diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index cad008e9e..64cdd9969 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -7,11 +7,13 @@ import ( ) const ( - FuncCreateStoreSkus = 1 - FuncDeleteStoreSkus = 2 - FuncUpdateStoreSkusStatus = 3 - FuncUpdateStoreSkusPrice = 4 - FuncUpdateStoreSkus = 5 + FuncUpdateStoreSkusStock = 1 + FuncUpdateStoreSkusStatus = 2 + FuncUpdateStoreSkusPrice = 3 + + FuncCreateStoreSkus = 6 + FuncUpdateStoreSkus = 7 + FuncDeleteStoreSkus = 8 ) type BareStoreSkuInfo struct { @@ -20,6 +22,7 @@ type BareStoreSkuInfo struct { NameID int `json:"nameID,omitempty"` VendorNameID string `json:"vendorNameID,omitempty"` + Stock int `json:"stock,omitempty"` Price int64 `json:"price,omitempty"` Status int `json:"status,omitempty"` } @@ -65,8 +68,7 @@ type BareCategoryInfo struct { type IPurchasePlatformStoreSkuHandler interface { GetStoreSkusBatchSize(funcID int) int - CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) - DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error) + UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error) } @@ -74,9 +76,12 @@ type IPurchasePlatformStoreSkuHandler interface { type ISingleStoreStoreSkuHandler interface { IPurchasePlatformStoreSkuHandler + CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) + UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) + DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error) + ReadStoreCategory(ctx *jxcontext.Context, vendorStoreID string) (cats []*BareCategoryInfo, err error) CreateStoreSkuCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) UpdateStoreSkuCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) DeleteStoreSkuCategory(ctx *jxcontext.Context, vendorStoreID, vendorCatID string) (err error) - UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) } diff --git a/business/partner/purchase/jd/store_sku2.go b/business/partner/purchase/jd/store_sku2.go index 73ecfb0a6..90ecf6776 100644 --- a/business/partner/purchase/jd/store_sku2.go +++ b/business/partner/purchase/jd/store_sku2.go @@ -12,6 +12,14 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) +func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) { + switch funcID { + case partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice: + batchSize = jdapi.MaxStoreSkuBatchSize + } + return batchSize +} + func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) { var batchSkuInfoList []*jdapi.BaseStockCenterRequest batchSkuList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList() @@ -64,3 +72,49 @@ func jdStoreSkuStatus2Jx(jdStoreSkuStatus int) (jxSkuStatus int) { } return jxSkuStatus } + +func jxStoreSkuStatus2Jd(jxStoreSkuStatus int) (isSale bool) { + return jxStoreSkuStatus == model.SkuStatusNormal +} + +func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) { + var skuStockList []*jdapi.SkuStock + for _, v := range storeSkuList { + skuStockList = append(skuStockList, &jdapi.SkuStock{ + OutSkuId: utils.Int2Str(v.SkuID), + StockQty: v.Stock, + }) + } + if globals.EnableJdStoreWrite { + _, err = api.JdAPI.BatchUpdateCurrentQtys("", vendorStoreID, skuStockList, ctx.GetUserName()) + } + return err +} + +func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) { + var skuVendibilityList []*jdapi.StockVendibility + for _, v := range storeSkuList { + skuVendibilityList = append(skuVendibilityList, &jdapi.StockVendibility{ + OutSkuId: utils.Int2Str(v.SkuID), + DoSale: jxStoreSkuStatus2Jd(v.Status), + }) + } + if globals.EnableJdStoreWrite { + _, err = api.JdAPI.BatchUpdateVendibility("", vendorStoreID, skuVendibilityList, ctx.GetUserName()) + } + return err +} + +func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) { + var skuPriceInfoList []*jdapi.SkuPriceInfo + for _, v := range storeSkuList { + skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{ + OutSkuId: utils.Int2Str(v.SkuID), + Price: int(v.Price), + }) + } + if globals.EnableJdStoreWrite { + _, err = api.JdAPI.UpdateVendorStationPrice("", vendorStoreID, skuPriceInfoList) + } + return err +}