从银豹上拉标品到京西
This commit is contained in:
@@ -4054,3 +4054,144 @@ func RefreshMatterStock(ctx *jxcontext.Context, skuID int) (err error) {
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{666666}, skuBindInfos, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateSkusAndFocusFromYb(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
vendorID = model.VendorIDYB
|
||||
db = dao.GetDB()
|
||||
)
|
||||
storeMaps, err := dao.GetStoresMapList2(db, []int{vendorID}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", false)
|
||||
handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
task := tasksch.NewParallelTask("银豹平台拉取标品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
store, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID)
|
||||
var (
|
||||
pricePercentagePack []*model.PricePercentageItem
|
||||
)
|
||||
localSkuList, err := dao.GetStoreSkus2(db, vendorID, storeMap.StoreID, nil, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localSkuMap := make(map[string]*dao.StoreSkuSyncInfo)
|
||||
for _, v := range localSkuList {
|
||||
localSkuMap[v.VendorSkuID] = v
|
||||
}
|
||||
remoteSkuList, err := handler.GetStoreSkusFullInfo(ctx, task, storeMap.StoreID, storeMap.VendorStoreID, nil)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
for _, v := range remoteSkuList {
|
||||
//长度大于7就可能是标品,非标品一般是7位,前三位是yb_store_prefix后4位是yb_name_suffix
|
||||
if len(v.YbBarCode) > 7 {
|
||||
if localSkuMap[v.SkuList[0].VendorSkuID] == nil {
|
||||
skuNames, err := dao.GetSkuNames(db, nil, []string{v.YbBarCode}, "")
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
//表示我们商品库中没有这个upc商品,如果有就直接关注上
|
||||
if len(skuNames) == 0 {
|
||||
//我们商品库中有这个商品,但是upc没有填,则尝试用upc去查一下
|
||||
productInfos, err := GetJdUpcCodeByName(ctx, "", v.YbBarCode)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
//表示用upc也没有找到这个商品,则再尝试用银豹上的名字去查
|
||||
if len(productInfos) == 0 {
|
||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, v.Name)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
if len(skuNames2) > 1 {
|
||||
return retVal, fmt.Errorf("此商品名在京西库中查询出了大于1个商品,[%v]", v.Name)
|
||||
}
|
||||
//表示查到了,需要把upc更新上去,没查到就要新建(//TODO新建不起,没得规格这些)
|
||||
if len(skuNames2) == 1 {
|
||||
skuNames2[0].Upc = &v.YbBarCode
|
||||
dao.UpdateEntity(db, skuNames2[0], "Upc")
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames2[0].ID, pricePercentagePack)
|
||||
}
|
||||
} else {
|
||||
productInfo := productInfos[0]
|
||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, productInfo.Name)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
if len(skuNames2) > 1 {
|
||||
return retVal, fmt.Errorf("此商品名在京西库中查询出了大于1个商品,[%v]", productInfo.Name)
|
||||
}
|
||||
//表示查到了,需要把upc更新上去,没查到就要新建
|
||||
if len(skuNames2) == 1 && (productInfo.SpecQuality == skuNames2[0].SpecQuality && productInfo.SpecUnit == skuNames2[0].SpecUnit) {
|
||||
skuNames2[0].Upc = &v.YbBarCode
|
||||
dao.UpdateEntity(db, skuNames2[0], "Upc")
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames2[0].ID, pricePercentagePack)
|
||||
} else {
|
||||
skuNameExt := &model.SkuNameExt{
|
||||
SkuName: model.SkuName{
|
||||
Name: productInfo.Name,
|
||||
Upc: &productInfo.UpcCode,
|
||||
Status: model.SkuStatusNormal,
|
||||
CategoryID: 175,
|
||||
IsGlobal: model.NO,
|
||||
Unit: productInfo.Unit,
|
||||
},
|
||||
Skus: []*model.SkuWithVendor{
|
||||
&model.SkuWithVendor{},
|
||||
},
|
||||
Places: []int{510100}, //默认成都
|
||||
}
|
||||
if len(v.SkuList) > 0 {
|
||||
skuNameExt.Price = int(v.SkuList[0].VendorPrice)
|
||||
skuNameExt.Skus[0].SpecQuality = productInfo.SpecQuality
|
||||
skuNameExt.Skus[0].SpecUnit = productInfo.SpecUnit
|
||||
skuNameExt.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
||||
skuNameExt.Skus[0].Status = model.SkuStatusNormal
|
||||
}
|
||||
if len(v.PictureList) > 0 {
|
||||
skuNameExt.Img = v.PictureList[0]
|
||||
}
|
||||
outSkuNameExt, err := AddSkuName(ctx, skuNameExt, ctx.GetUserName())
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, outSkuNameExt.ID, pricePercentagePack)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames[0].ID, pricePercentagePack)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, storeMaps)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func buildStoreSkuBindInfosAndFocus(ctx *jxcontext.Context, db *dao.DaoDB, store *dao.StoreDetail, v *partner.SkuNameInfo, nameID int, pricePercentagePack []*model.PricePercentageItem) (err error) {
|
||||
skus, _ := dao.GetSkus(db, nil, []int{nameID}, nil, nil, nil)
|
||||
err = jxutils.Strings2Objs(store.PricePercentagePackStr, &pricePercentagePack)
|
||||
price := jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, int(v.SkuList[0].VendorPrice))
|
||||
skuBind := &model.StoreSkuBind{
|
||||
StoreID: store.ID,
|
||||
UnitPrice: price,
|
||||
Price: price,
|
||||
Status: model.StoreSkuBindStatusNormal,
|
||||
YbID: utils.Str2Int64(v.SkuList[0].VendorSkuID),
|
||||
YbPrice: int(v.SkuList[0].VendorPrice),
|
||||
YbSyncStatus: 0,
|
||||
}
|
||||
if len(skus) > 0 {
|
||||
skuBind.SkuID = skus[0].ID
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(skuBind, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, skuBind)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -248,7 +248,10 @@ func Init() {
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "jd2StorePageCookie", model.ConfigTypeCookie, ""); err == nil {
|
||||
jd2StorePageCookie = configs[0].Value
|
||||
}
|
||||
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "yinbaoCookie", model.ConfigTypeCookie, ""); err == nil {
|
||||
yinbaoCookie := configs[0].Value
|
||||
api.YinBaoAPI.SetCookie(".POSPALAUTH30220", yinbaoCookie)
|
||||
}
|
||||
if globals.Jd2OrgCode != "" {
|
||||
api.Jd2API.SetJdCookie(jd2StorePageCookie)
|
||||
}
|
||||
@@ -268,9 +271,9 @@ func Init() {
|
||||
func syncStoreSku() {
|
||||
syncFlag := 0
|
||||
// syncFlag := model.SyncFlagPriceMask
|
||||
// if (time.Now().Unix()/24*3600)%10 == 0 {
|
||||
// syncFlag |= model.SyncFlagSaleMask
|
||||
// }
|
||||
if (time.Now().Unix()/24*3600)%10 == 0 {
|
||||
syncFlag |= model.SyncFlagSaleMask
|
||||
}
|
||||
task := tasksch.NewParallelTask("同步京西与平台数据", nil, jxcontext.AdminCtx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
|
||||
@@ -153,7 +153,7 @@ func GetStoreSkuSalesInfo(ctx *jxcontext.Context, storeID int) (outStoreSkuSales
|
||||
storeSkuSales.SkuImage = storeSkuInfo.Img
|
||||
storeSkuSales.SkuPrice = jxutils.IntPrice2StandardCurrencyString(int64(storeSkuInfo.Skus[0].BindPrice))
|
||||
} else if skuAndNameInfo != nil {
|
||||
skuNameList, err := dao.GetSkuNames(db, []int{skuAndNameInfo.NameID})
|
||||
skuNameList, err := dao.GetSkuNames(db, []int{skuAndNameInfo.NameID}, nil, "")
|
||||
prefix := ""
|
||||
if err == nil && len(skuNameList) > 0 {
|
||||
storeSkuSales.SkuImage = skuNameList[0].Img
|
||||
|
||||
Reference in New Issue
Block a user