从银豹上拉标品到京西
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
|
||||
|
||||
@@ -121,7 +121,7 @@ func GetSkus(db *DaoDB, skuIDs, nameIDs, statuss, catIDs []int, eclpIDs []string
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetSkuNames(db *DaoDB, nameIDs []int) (skuNameList []*model.SkuName, err error) {
|
||||
func GetSkuNames(db *DaoDB, nameIDs []int, upcs []string, name string) (skuNameList []*model.SkuName, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM sku_name t1
|
||||
@@ -134,6 +134,14 @@ func GetSkuNames(db *DaoDB, nameIDs []int) (skuNameList []*model.SkuName, err er
|
||||
sql += " AND t1.id IN (" + GenQuestionMarks(len(nameIDs)) + ")"
|
||||
sqlParams = append(sqlParams, nameIDs)
|
||||
}
|
||||
if len(upcs) > 0 {
|
||||
sql += " AND t1.upc IN (" + GenQuestionMarks(len(upcs)) + ")"
|
||||
sqlParams = append(sqlParams, upcs)
|
||||
}
|
||||
if name != "" {
|
||||
sql += " AND t1.name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+name+"%")
|
||||
}
|
||||
if err = GetRows(db, &skuNameList, sql, sqlParams...); err == nil {
|
||||
return skuNameList, nil
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ type SkuNameInfo struct {
|
||||
VendorCatIDList []string
|
||||
PictureList []string
|
||||
Status int `json:"status,omitempty"`
|
||||
YbBarCode string
|
||||
SkuList []*SkuInfo
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
|
||||
if storeSkuList != nil {
|
||||
if len(storeSkuList) == 1 {
|
||||
storeSku := storeSkuList[0]
|
||||
result, err := api.YinBaoAPI.QueryProductByBarcode(utils.Int2Str(storeSku.SkuID))
|
||||
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(utils.Int2Str(storeSku.SkuID))
|
||||
result, err := api.YinBaoAPI.QueryProductByBarcode(storeSku.VendorSkuID)
|
||||
resultp, err := getProductImages(vendorStoreID, storeSku.VendorSkuID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -79,14 +79,14 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
|
||||
} else {
|
||||
var barcodes []string
|
||||
for _, v := range storeSkuList {
|
||||
barcodes = append(barcodes, utils.Int2Str(v.SkuID))
|
||||
barcodes = append(barcodes, v.VendorSkuID)
|
||||
}
|
||||
results, err := api.YinBaoAPI.QueryProductByBarcodes(barcodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range results {
|
||||
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
|
||||
resultp, err := getProductImages(vendorStoreID, v.Barcode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
|
||||
}
|
||||
if result.PostBackParameter.ParameterType == yinbaoapi.PageMaxID {
|
||||
for _, v := range result.Result {
|
||||
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
|
||||
resultp, err := getProductImages(vendorStoreID, v.Barcode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -113,12 +113,33 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loopPages(result.PostBackParameter.ParameterType, result.PostBackParameter.ParameterValue, skuNameList)
|
||||
loopPages(result.PostBackParameter.ParameterType, result.PostBackParameter.ParameterValue, skuNameList, vendorStoreID)
|
||||
}
|
||||
}
|
||||
return skuNameList, err
|
||||
}
|
||||
|
||||
func getProductImages(vendorStoreID, barCode string) (findProductResult *yinbaoapi.FindProductResult, err error) {
|
||||
for {
|
||||
ybSkuID, err := api.YinBaoAPI.LoadProductsByPage(vendorStoreID, barCode)
|
||||
findProductResult, err = api.YinBaoAPI.FindProduct(ybSkuID)
|
||||
if err == nil {
|
||||
break
|
||||
} else {
|
||||
if yinbaoapi.IsErrCookie(err) {
|
||||
err = cms.ChangeYbCookie()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
findProductResult, err = getProductImages(vendorStoreID, barCode)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return findProductResult, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
if globals.EnableYbStoreWrite {
|
||||
for _, v := range storeSkuList {
|
||||
@@ -322,28 +343,27 @@ func ybSkuStatus2Jx(ybStatus int) (jxSkuStatus int) {
|
||||
return jxSkuStatus
|
||||
}
|
||||
|
||||
func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp []*yinbaoapi.QueryProductImagesByBarcodeResult) (skuName *partner.SkuNameInfo) {
|
||||
func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp *yinbaoapi.FindProductResult) (skuName *partner.SkuNameInfo) {
|
||||
var picList []string
|
||||
if result == nil {
|
||||
globals.SugarLogger.Warnf("vendorSku2Jx, strange result:%s", utils.Format4Output(result, true))
|
||||
return nil
|
||||
}
|
||||
if len(resultp) > 0 {
|
||||
for _, v := range resultp {
|
||||
picList = append(picList, v.ImageURL)
|
||||
if len(resultp.Productimages) > 0 {
|
||||
for _, v := range resultp.Productimages {
|
||||
picList = append(picList, yinbaoapi.ImageUrl+v.Path)
|
||||
}
|
||||
}
|
||||
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(result.Name)
|
||||
skuID := int(utils.Str2Int64WithDefault(result.Barcode, 0))
|
||||
skuName = &partner.SkuNameInfo{
|
||||
Prefix: prefix,
|
||||
Name: name,
|
||||
Unit: unit,
|
||||
Prefix: prefix,
|
||||
Name: name,
|
||||
Unit: unit,
|
||||
YbBarCode: result.Barcode,
|
||||
SkuList: []*partner.SkuInfo{
|
||||
&partner.SkuInfo{
|
||||
StoreSkuInfo: partner.StoreSkuInfo{
|
||||
VendorSkuID: utils.Int64ToStr(result.UID),
|
||||
SkuID: skuID,
|
||||
Stock: int(utils.Float64TwoInt64(result.Stock)),
|
||||
VendorPrice: jxutils.StandardPrice2Int(result.SellPrice),
|
||||
Status: ybSkuStatus2Jx(result.Enable),
|
||||
@@ -360,7 +380,7 @@ func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp []*yinb
|
||||
return skuName
|
||||
}
|
||||
|
||||
func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuNameInfo) (err error) {
|
||||
func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuNameInfo, vendorStoreID string) (err error) {
|
||||
var postBackParameter = &yinbaoapi.PostBackParameter{
|
||||
ParameterType: parameterType,
|
||||
ParameterValue: parameterValue,
|
||||
@@ -370,7 +390,7 @@ func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuN
|
||||
return err
|
||||
}
|
||||
for _, v := range resultPages.Result {
|
||||
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
|
||||
resultp, err := getProductImages(vendorStoreID, v.Barcode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -381,7 +401,7 @@ func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuN
|
||||
}
|
||||
}
|
||||
if resultPages.PostBackParameter.ParameterType != yinbaoapi.PageMaxID {
|
||||
err = loopPages(resultPages.PostBackParameter.ParameterType, resultPages.PostBackParameter.ParameterValue, skuNameList)
|
||||
err = loopPages(resultPages.PostBackParameter.ParameterType, resultPages.PostBackParameter.ParameterValue, skuNameList, vendorStoreID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -198,6 +198,9 @@ weixinSecret = "6bbbed1443cc062c20a015a64c07a531"
|
||||
weixinMiniAppID2 = "wx4b5930c13f8b1170"
|
||||
weixinMiniSecret2 = "2a57228a716ce991a52739f0ff41111d"
|
||||
|
||||
yinbaoAppKey = "682628966212343269"
|
||||
yinbaoAppID = "18C0E0867E467DBC26EFF5E957B02EC4"
|
||||
|
||||
wxpayNotifyURL = "http://callback.jxc4.com/wxpay/msg/"
|
||||
|
||||
tonglianPayAppID = "00183083"
|
||||
|
||||
@@ -760,3 +760,18 @@ func (c *StoreSkuController) RefreshMatterStock() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 从银豹上拉取标品到京西创建
|
||||
// @Description 从银豹上拉取标品到京西创建
|
||||
// @Param token header string false "认证token"
|
||||
// @Param isAsync formData bool false "是否异步,缺省是同步"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CreateSkusAndFocusFromYb [post]
|
||||
func (c *StoreSkuController) CreateSkusAndFocusFromYb() {
|
||||
c.callCreateSkusAndFocusFromYb(func(params *tStoreSkuCreateSkusAndFocusFromYbParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.CreateSkusAndFocusFromYb(params.Ctx, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1827,6 +1827,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateSkusAndFocusFromYb",
|
||||
Router: `/CreateSkusAndFocusFromYb`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "FocusStoreSkusByExcel",
|
||||
|
||||
Reference in New Issue
Block a user