京东商城同步修改,关注可售修改
This commit is contained in:
@@ -1175,7 +1175,22 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if vendorID == model.VendorIDJDShop {
|
} else if vendorID == model.VendorIDJDShop {
|
||||||
|
if storeMap.VendorStoreID == "" {
|
||||||
storeMap.SyncStatus = model.SyncFlagNewMask //京东商城要去建店
|
storeMap.SyncStatus = model.SyncFlagNewMask //京东商城要去建店
|
||||||
|
} else {
|
||||||
|
if handler := CurVendorSync.GetStoreHandler(vendorID); handler != nil {
|
||||||
|
store, err2 := handler.ReadStore(ctx, vendorOrgCode, storeMap.VendorStoreID)
|
||||||
|
if err = err2; err == nil || storeMap.IsSync == 0 {
|
||||||
|
if store != nil {
|
||||||
|
storeMap.Status = store.Status
|
||||||
|
}
|
||||||
|
err = nil
|
||||||
|
storeMap.SyncStatus = model.SyncFlagModifiedMask | model.SyncFlagStoreName | model.SyncFlagStoreAddress
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = ErrCanNotFindVendor
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
storeMapList, err := dao.GetStoresMapList2(db, []int{vendorID}, []int{storeID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", true)
|
storeMapList, err := dao.GetStoresMapList2(db, []int{vendorID}, []int{storeID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", true)
|
||||||
if len(storeMapList) > 0 {
|
if len(storeMapList) > 0 {
|
||||||
|
|||||||
@@ -853,7 +853,7 @@ func UpdateStoresSkus(ctx *jxcontext.Context, causeFlag int, storeIDs []int, sku
|
|||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError, isFos bool) (hint string, err error) {
|
||||||
// if len(skuBindInfos) > maxStoreNameBind {
|
// if len(skuBindInfos) > maxStoreNameBind {
|
||||||
// return "", fmt.Errorf("门店商品信息大于%d", maxStoreNameBind)
|
// return "", fmt.Errorf("门店商品信息大于%d", maxStoreNameBind)
|
||||||
// }
|
// }
|
||||||
@@ -892,7 +892,7 @@ func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, sk
|
|||||||
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
|
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
|
||||||
if num > 0 {
|
if num > 0 {
|
||||||
skuIDs := jxutils.IntMap2List(skuIDMap)
|
skuIDs := jxutils.IntMap2List(skuIDMap)
|
||||||
hint, err = CurVendorSync.SyncStoresSkus(ctx, parentTask, 0, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
hint, err = CurVendorSync.SyncStoresSkus(ctx, parentTask, 0, db, nil, storeIDs, skuIDs, isFos, isAsync, isContinueWhenError)
|
||||||
}
|
}
|
||||||
if num == 0 || !isAsync || hint == "" {
|
if num == 0 || !isAsync || hint == "" {
|
||||||
hint = utils.Int64ToStr(num)
|
hint = utils.Int64ToStr(num)
|
||||||
@@ -3111,7 +3111,7 @@ func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync,
|
|||||||
for _, v := range result1 {
|
for _, v := range result1 {
|
||||||
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
||||||
}
|
}
|
||||||
UpdateStoresSkusByBind(ctx, task, skuBindInfos, true, true)
|
UpdateStoresSkusByBind(ctx, task, skuBindInfos, true, true, false)
|
||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -3206,7 +3206,7 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuBindInfos []*StoreSkuBindInf
|
|||||||
for _, v := range result1 {
|
for _, v := range result1 {
|
||||||
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
||||||
}
|
}
|
||||||
hint, err = UpdateStoresSkusByBind(ctx, task, skuBindInfos, isAsync, isContinueWhenError)
|
hint, err = UpdateStoresSkusByBind(ctx, task, skuBindInfos, isAsync, isContinueWhenError, true)
|
||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -3302,7 +3302,7 @@ func AutoFocusStoreSkusForTopSkus(ctx *jxcontext.Context, isAsync, isContinueWhe
|
|||||||
for _, v := range result1 {
|
for _, v := range result1 {
|
||||||
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
||||||
}
|
}
|
||||||
hint, err = UpdateStoresSkusByBind(ctx, nil, skuBindInfos, isAsync, isContinueWhenError)
|
hint, err = UpdateStoresSkusByBind(ctx, nil, skuBindInfos, isAsync, isContinueWhenError, false)
|
||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -3797,7 +3797,7 @@ func RefreshJxPriceByVendor(ctx *jxcontext.Context, jdStoreSkus []*JdStoreSkus,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
_, err = UpdateStoresSkusByBind(ctx, nil, param, isAsync, isContinueWhenError)
|
_, err = UpdateStoresSkusByBind(ctx, nil, param, isAsync, isContinueWhenError, false)
|
||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -3880,7 +3880,7 @@ func RefreshJxPriceByVendor2(ctx *jxcontext.Context, storeIDs []int, vendorID in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
_, err = UpdateStoresSkusByBind(ctx, nil, param, isAsync, isContinueWhenError)
|
_, err = UpdateStoresSkusByBind(ctx, nil, param, isAsync, isContinueWhenError, false)
|
||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -4132,7 +4132,7 @@ func CreateSkusAndFocusFromWx(ctx *jxcontext.Context, productInfo *jdapi.Product
|
|||||||
IsSale: 1,
|
IsSale: 1,
|
||||||
}
|
}
|
||||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||||
_, err := UpdateStoresSkusByBind(ctx, nil, skuBindInfos, true, true)
|
_, err := UpdateStoresSkusByBind(ctx, nil, skuBindInfos, true, true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package jdshop
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -15,6 +16,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (storeDetail *dao.StoreDetail, err error) {
|
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (storeDetail *dao.StoreDetail, err error) {
|
||||||
|
result, err := api.JdShopAPI.NewInfoList(utils.Str2Int64(vendorStoreID))
|
||||||
|
storeDetail.VendorStoreID = vendorStoreID
|
||||||
|
storeDetail.Status = JdsStatus2jxStatus(result.StoreStatus)
|
||||||
|
result2, err := api.JdShopAPI.QueryEntityStore(utils.Str2Int64(vendorStoreID))
|
||||||
|
storeDetail.ID = utils.Str2Int(result2.ExStoreID)
|
||||||
|
storeDetail.Name = result2.StoreName
|
||||||
|
storeDetail.Address = result2.Address
|
||||||
|
storeDetail.Tel1 = result2.Phone
|
||||||
|
storeDetail.DistrictCode = result2.AddrCode
|
||||||
|
zbs := strings.Split(result2.Coordinate, ",")
|
||||||
|
storeDetail.Lat = jxutils.StandardCoordinate2Int(utils.Str2Float64(zbs[0]))
|
||||||
|
storeDetail.Lng = jxutils.StandardCoordinate2Int(utils.Str2Float64(zbs[1]))
|
||||||
return storeDetail, err
|
return storeDetail, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +93,11 @@ func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
|
func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
|
||||||
|
// store, err := dao.GetStoreDetail(db, storeID, model.VendorIDJDShop)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// err = api.JdShopAPI.DeleteStoresByID(utils.Str2Int64(store.VendorStoreID))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,3 +148,14 @@ func jxStatus2JdsStatus(status int) (result int) {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JdsStatus2jxStatus(status int) (result int) {
|
||||||
|
if status == jdshopapi.JdsStoreStatusOnline {
|
||||||
|
result = model.StoreStatusOpened
|
||||||
|
} else if status == jdshopapi.JdsStoreStatusRest {
|
||||||
|
result = model.StoreStatusClosed
|
||||||
|
} else {
|
||||||
|
result = model.StoreStatusDisabled
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v
|
|||||||
WareID: v.JdsWareID,
|
WareID: v.JdsWareID,
|
||||||
Title: name,
|
Title: name,
|
||||||
VenderID: jdshopapi.VenderID,
|
VenderID: jdshopapi.VenderID,
|
||||||
|
PromiseID: jdshopapi.JdsPromiseID,
|
||||||
// Weight: v.Weight,
|
// Weight: v.Weight,
|
||||||
}
|
}
|
||||||
err = api.JdShopAPI.UpdateWare(updateWareParam)
|
err = api.JdShopAPI.UpdateWare(updateWareParam)
|
||||||
@@ -333,11 +334,12 @@ func buildCreateWareParam(storeSku *dao.StoreSkuSyncInfo) (createSkuParamWare *j
|
|||||||
Weight: 0.5,
|
Weight: 0.5,
|
||||||
JdPrice: jxutils.IntPrice2Standard(storeSku.UnitPrice),
|
JdPrice: jxutils.IntPrice2Standard(storeSku.UnitPrice),
|
||||||
// MarketPrice: jxutils.IntPrice2Standard(storeSku.UnitPrice),
|
// MarketPrice: jxutils.IntPrice2Standard(storeSku.UnitPrice),
|
||||||
|
PromiseID: jdshopapi.JdsPromiseID,
|
||||||
}
|
}
|
||||||
|
|
||||||
//上传京东图片
|
//上传京东图片
|
||||||
//规则,有两张就传两张,没有就重复传一张
|
//规则,有两张就传两张,没有就重复传一张
|
||||||
pic1, err := uploadImg(storeSku.Img, storeSku.Name, "1")
|
pic1, err := uploadImg(storeSku.Img, name, "1")
|
||||||
img1 := &jdshopapi.CreateSkuParamImages{
|
img1 := &jdshopapi.CreateSkuParamImages{
|
||||||
ColorID: "0000000000",
|
ColorID: "0000000000",
|
||||||
ImgIndex: 1,
|
ImgIndex: 1,
|
||||||
@@ -350,7 +352,7 @@ func buildCreateWareParam(storeSku *dao.StoreSkuSyncInfo) (createSkuParamWare *j
|
|||||||
if storeSku.Img2 == "" {
|
if storeSku.Img2 == "" {
|
||||||
img2.ImgURL = pic1
|
img2.ImgURL = pic1
|
||||||
} else {
|
} else {
|
||||||
pic2, err2 := uploadImg(storeSku.Img, storeSku.Name, "2")
|
pic2, err2 := uploadImg(storeSku.Img, name, "2")
|
||||||
err = err2
|
err = err2
|
||||||
img2.ImgURL = pic2
|
img2.ImgURL = pic2
|
||||||
}
|
}
|
||||||
@@ -361,7 +363,7 @@ func buildCreateWareParam(storeSku *dao.StoreSkuSyncInfo) (createSkuParamWare *j
|
|||||||
//商品详情拼接
|
//商品详情拼接
|
||||||
var desc string
|
var desc string
|
||||||
if storeSku.DescImg != "" {
|
if storeSku.DescImg != "" {
|
||||||
pic3, err2 := uploadImg(storeSku.DescImg, storeSku.Name, "desc")
|
pic3, err2 := uploadImg(storeSku.DescImg, name, "desc")
|
||||||
err = err2
|
err = err2
|
||||||
desc = `<p><img src="` + jdshopapi.JdsImgURL + pic3 + `" style="width: auto; height: auto; max-width: 100%;"><br></p><p><br></p>`
|
desc = `<p><img src="` + jdshopapi.JdsImgURL + pic3 + `" style="width: auto; height: auto; max-width: 100%;"><br></p><p><br></p>`
|
||||||
} else {
|
} else {
|
||||||
@@ -460,7 +462,7 @@ func buildCreateWareParam(storeSku *dao.StoreSkuSyncInfo) (createSkuParamWare *j
|
|||||||
attrsPropSku = append(attrsPropSku, attrSku)
|
attrsPropSku = append(attrsPropSku, attrSku)
|
||||||
sku := &jdshopapi.CreateSkuParamSkus{
|
sku := &jdshopapi.CreateSkuParamSkus{
|
||||||
JdPrice: jxutils.IntPrice2Standard(v.VendorPrice),
|
JdPrice: jxutils.IntPrice2Standard(v.VendorPrice),
|
||||||
StockNum: 9999,
|
// StockNum: 9999,
|
||||||
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
||||||
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
||||||
OuterID: utils.Int2Str(v.SkuID),
|
OuterID: utils.Int2Str(v.SkuID),
|
||||||
@@ -471,12 +473,22 @@ func buildCreateWareParam(storeSku *dao.StoreSkuSyncInfo) (createSkuParamWare *j
|
|||||||
if v.VendorPrice > vendorPrice {
|
if v.VendorPrice > vendorPrice {
|
||||||
vendorPrice = v.VendorPrice
|
vendorPrice = v.VendorPrice
|
||||||
}
|
}
|
||||||
|
if v.Status == model.SkuStatusNormal {
|
||||||
|
sku.StockNum = 9999
|
||||||
|
} else {
|
||||||
|
sku.StockNum = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
createSkuParamWare.MarketPrice = jxutils.IntPrice2Standard(vendorPrice)
|
createSkuParamWare.MarketPrice = jxutils.IntPrice2Standard(vendorPrice)
|
||||||
return createSkuParamWare, createSkuParamSkus, err
|
return createSkuParamWare, createSkuParamSkus, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//京东商城上传图片,若平台上已经有了这个图就直接拿来用了
|
||||||
func uploadImg(img, name, index string) (imgURL string, err error) {
|
func uploadImg(img, name, index string) (imgURL string, err error) {
|
||||||
|
result, err := api.JdShopAPI.QueryPicture(name + index)
|
||||||
|
if len(result) > 0 {
|
||||||
|
imgURL = result[0].PictureURL
|
||||||
|
} else {
|
||||||
data, _, err := jxutils.DownloadFileByURL(img)
|
data, _, err := jxutils.DownloadFileByURL(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return imgURL, err
|
return imgURL, err
|
||||||
@@ -485,7 +497,9 @@ func uploadImg(img, name, index string) (imgURL string, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return imgURL, err
|
return imgURL, err
|
||||||
}
|
}
|
||||||
return uploadResult.PictureURL, err
|
imgURL = uploadResult.PictureURL
|
||||||
|
}
|
||||||
|
return imgURL, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterSensitiveWord(name string) (result string) {
|
func filterSensitiveWord(name string) (result string) {
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ func (c *StoreSkuController) UpdateStoresSkusByBind() {
|
|||||||
if err = jxutils.Strings2Objs(params.Payload, &skuBindInfos); err != nil {
|
if err = jxutils.Strings2Objs(params.Payload, &skuBindInfos); err != nil {
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
}
|
}
|
||||||
retVal, err = cms.UpdateStoresSkusByBind(params.Ctx, nil, skuBindInfos, params.IsAsync, params.IsContinueWhenError)
|
retVal, err = cms.UpdateStoresSkusByBind(params.Ctx, nil, skuBindInfos, params.IsAsync, params.IsContinueWhenError, false)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user