京东商城建商品开测

This commit is contained in:
苏尹岚
2020-05-13 09:43:27 +08:00
parent 7b05c7b87a
commit 5f901f8531
11 changed files with 243 additions and 34 deletions

View File

@@ -1146,7 +1146,7 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
storeMap.Status = model.StoreStatusOpened
storeMap.DeliveryType = model.StoreDeliveryTypeByStore
storeMap.SyncStatus = 0
if vendorID != model.VendorIDJX && vendorID != model.VendorIDYB {
if vendorID != model.VendorIDJX && vendorID != model.VendorIDYB && vendorID != model.VendorIDJDShop {
if storeMap.VendorOrgCode == "" {
return nil, fmt.Errorf("必须指定平台分账号信息")
}
@@ -1170,6 +1170,8 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
if err != nil {
return nil, err
}
} else if vendorID == model.VendorIDJDShop {
storeMap.SyncStatus = model.SyncFlagNewMask //京东商城要去建店
}
if err == nil {
dao.WrapAddIDCULDEntity(storeMap, userName)

View File

@@ -229,7 +229,7 @@ func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs
var failedList []*partner.StoreSkuInfoWithErr
handler := v.GetStoreHandler(loopMapInfo.VendorID)
if handler != nil {
if len(loopMapInfo.StoreMapList) > 1 {
if len(loopMapInfo.StoreMapList) > 0 {
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
var resultList []interface{}
@@ -238,29 +238,52 @@ func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs
if len(loopMapInfo.StoreMapList) > 1 {
db2 = dao.GetDB()
}
if err = handler.UpdateStore(db2, storeMap.StoreID, userName); err == nil {
storeMap.SyncStatus = 0
_, err = dao.UpdateEntity(db2, storeMap, model.FieldSyncStatus)
resultList = append(resultList, 1)
if model.IsSyncStatusNew(storeMap.SyncStatus) {
if err = handler.CreateStore2(db2, storeMap.StoreID, userName); err == nil {
resultList = append(resultList, 1)
} else {
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "创建门店")
}
} else if model.IsSyncStatusDelete(storeMap.SyncStatus) {
if err = handler.DeleteStore(db2, storeMap.StoreID, userName); err == nil {
resultList = append(resultList, 1)
} else {
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "删除门店")
}
} else {
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "同步门店")
if err = handler.UpdateStore(db2, storeMap.StoreID, userName); err == nil {
resultList = append(resultList, 1)
} else {
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "更新门店")
}
}
if err == nil {
storeMap.SyncStatus = 0
_, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
}
return resultList, err
}, loopMapInfo.StoreMapList)
t.AddChild(loopStoreTask).Run()
resultList, err = loopStoreTask.GetResult(0)
} else {
storeMap := loopMapInfo.StoreMapList[0]
if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil {
storeMap.SyncStatus = 0
_, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
} else {
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "同步门店")
}
if err == nil {
resultList = []interface{}{1}
}
}
// else {
// storeMap := loopMapInfo.StoreMapList[0]
// if model.IsSyncStatusNew(storeMap.SyncStatus) {
// } else if model.IsSyncStatusDelete(storeMap.SyncStatus) {
// } else {
// if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil {
// storeMap.SyncStatus = 0
// _, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
// } else {
// failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "更新门店")
// }
// }
// if err == nil {
// resultList = []interface{}{1}
// }
// }
err = partner.AddVendorInfo2Err(err, loopMapInfo.VendorID)
}
if len(failedList) > 0 {

View File

@@ -398,9 +398,9 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
formalizeStoreSkuList(skus)
//京东商城的商品名规则不同
//name空格comment约xxg
if vendorID == model.VendorIDJDShop {
formalizeStoreSkuListForJds(skus)
}
// if vendorID == model.VendorIDJDShop {
// formalizeStoreSkuListForJds(skus)
// }
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
@@ -576,6 +576,14 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
api.YinBaoAPI.SetCookie(".POSPALAUTH30220", yinbaoCookie)
}
}
//如果平台是京东商城则按商品skuname创建
if vendorID == model.VendorIDJDShop {
if len(createList) > 0 {
rList := changeList2Jds(createList)
createList = createList[:]
createList = rList
}
}
task := tasksch.NewParallelTask("syncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError2), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
step := batchItemList[0].(int)
@@ -1346,3 +1354,26 @@ func changeList2Yb(list1 []*dao.StoreSkuSyncInfo, list2 []*partner.StoreSkuInfo)
}
return rList1, rList2
}
func changeList2Jds(list []*dao.StoreSkuSyncInfo) (rList []*dao.StoreSkuSyncInfo) {
var (
skuNameMap = make(map[int][]*dao.StoreSkuSyncInfo)
)
for _, v := range list {
skuNameMap[v.NameID] = append(skuNameMap[v.NameID], v)
}
for k, v := range skuNameMap {
storeSku := &dao.StoreSkuSyncInfo{
StoreSkuSyncInfoJds: v,
}
storeSku.NameID = k
storeSku.Name = v[0].Name
storeSku.VendorCatID = v[0].VendorCatID
storeSku.VendorVendorCatID = v[0].VendorVendorCatID
storeSku.UnitPrice = v[0].UnitPrice
storeSku.Img = v[0].Img
storeSku.Img2 = v[0].Img2
rList = append(rList, storeSku)
}
return rList
}

View File

@@ -43,8 +43,9 @@ type SkuStoreCatInfo struct {
}
type StoreSkuSyncInfo struct {
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
StoreSkuSyncInfoJds []*StoreSkuSyncInfo
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
// 平台无关的store sku信息
BindID int `orm:"column(bind_id)"` // 换名的原因是与Sku.ID同名区别

View File

@@ -147,6 +147,8 @@ type IPurchasePlatformHandler interface {
// Store
ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (store *dao.StoreDetail, err error)
UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error)
CreateStore2(db *dao.DaoDB, storeID int, userName string) (err error)
DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error)
GetStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string) (storeStatus int, err error)
UpdateStoreCustomID(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string, storeID int64) (err error)

View File

@@ -534,3 +534,11 @@ func (c *PurchaseHandler) GetShopIDsByPage() (vendorStoreIDs []string, err error
}
return vendorStoreIDs, err
}
func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}
func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}

View File

@@ -498,3 +498,11 @@ func (c *PurchaseHandler) UpdateStoreCustomID(ctx *jxcontext.Context, vendorOrgC
}
return err
}
func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}
func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}

View File

@@ -1,9 +1,12 @@
package jdshop
import (
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals/api"
)
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (storeDetail *dao.StoreDetail, err error) {
@@ -15,6 +18,22 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
return err
}
func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName string) (err error) {
store, err := dao.GetStoreDetail(db, storeID, model.VendorIDJDShop)
if err != nil {
return err
}
createEntityStoreParam := &jdshopapi.CreateEntityStoreParam{
Name: store.Name,
}
err = api.JdShopAPI.CreateEntityStore(createEntityStoreParam)
return err
}
func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}
func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
return hint, err
}

View File

@@ -2,6 +2,7 @@ package jdshop
import (
"regexp"
"time"
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
@@ -279,28 +280,126 @@ func buildCreateWareParam(storeSku *dao.StoreSkuSyncInfo) (createSkuParamWare *j
MobileDesc: " ",
Introduction: " ",
WareStatus: 8, //上架待审核
OuterID: utils.Int2Str(storeSku.SkuID),
OuterID: utils.Int2Str(storeSku.NameID),
VenderID: 0,
Is7ToReturn: 0, //不支持7天退货
Length: 100,
Width: 100,
Height: 100,
Weight: storeSku.Weight,
JdPrice: int(storeSku.VendorPrice),
MarketPrice: int(storeSku.Price),
Weight: 500,
JdPrice: int(storeSku.UnitPrice),
MarketPrice: int(storeSku.UnitPrice),
}
//上传京东图片 start
//规则,有两张就传两张,没有就重复传一张
data, _, err := jxutils.DownloadFileByURL(storeSku.Img)
if err != nil {
return createSkuParamWare, createSkuParamSkus, err
}
api.JdShopAPI.UploadPicture(data, 0, storeSku.Name)
for i := 1; i < 3; i++ {
img := &jdshopapi.CreateSkuParamImages{
ColorID: "0000000000",
ImgIndex: i,
ImgURL: "",
uploadResult, err := api.JdShopAPI.UploadPicture(data, 0, utils.Int64ToStr(time.Now().Unix())+storeSku.Name)
if err != nil {
return createSkuParamWare, createSkuParamSkus, err
}
img1 := &jdshopapi.CreateSkuParamImages{
ColorID: "0000000000",
ImgIndex: 1,
ImgURL: uploadResult.PictureURL,
}
img2 := &jdshopapi.CreateSkuParamImages{
ColorID: "0000000000",
ImgIndex: 2,
}
if storeSku.Img2 == "" {
img2.ImgURL = uploadResult.PictureURL
} else {
data2, _, err := jxutils.DownloadFileByURL(storeSku.Img2)
if err != nil {
return createSkuParamWare, createSkuParamSkus, err
}
images = append(images, img)
uploadResult2, err := api.JdShopAPI.UploadPicture(data2, 0, utils.Int64ToStr(time.Now().Unix())+storeSku.Name)
if err != nil {
return createSkuParamWare, createSkuParamSkus, err
}
img2.ImgURL = uploadResult2.PictureURL
}
images = append(images, img1)
images = append(images, img2)
createSkuParamWare.Images = images
//end
//设置商品属性值
var (
attrIDs = make(map[string]int) //贮存方式,净含量,保质期IDs
zctjValueID int64 //贮存条件冷藏0-4的id
attrsProp []*jdshopapi.CreateSkuParamAttrs
)
attrs, err := api.JdShopAPI.FindAttrs(int(storeSku.VendorVendorCatID))
for _, v := range attrs {
if v.Name == "保质期" {
attrIDs[v.Name] = v.ID
} else if v.Name == "贮存条件" {
attrIDs[v.Name] = v.ID
} else if v.Name == "净含量" {
attrIDs[v.Name] = v.ID
} else if v.Name == "规格" {
attrIDs[v.Name] = v.ID
}
}
values, _, err := api.JdShopAPI.FindValuesByAttrId(attrIDs["贮存条件"])
for _, v := range values {
if v.Name == "冷藏 0-4℃" {
zctjValueID = v.ID
}
}
attrZctj := &jdshopapi.CreateSkuParamAttrs{
AttrID: utils.Int2Str(attrIDs["贮存条件"]),
AttrValues: []string{utils.Int64ToStr(zctjValueID)},
}
attrJhl := &jdshopapi.CreateSkuParamAttrs{
AttrID: utils.Int2Str(attrIDs["净含量"]),
AttrValues: []string{"0.5"},
}
attrBzq := &jdshopapi.CreateSkuParamAttrs{
AttrID: utils.Int2Str(attrIDs["保质期"]),
AttrValues: []string{"5"},
}
attrsProp = append(attrsProp, attrZctj)
attrsProp = append(attrsProp, attrJhl)
attrsProp = append(attrsProp, attrBzq)
createSkuParamWare.MultiCateProps = attrsProp
//组合sku
var (
ggValueID int64 //规格的属性id
attrsPropSku []*jdshopapi.CreateSkuParamAttrs
)
valuesSku, maxNo, err := api.JdShopAPI.FindValuesByAttrId(attrIDs["规格"])
for _, v := range storeSku.StoreSkuSyncInfoJds {
specQuality := utils.Int2Str(storeSku.Weight) + storeSku.SpecUnit
for _, v := range valuesSku {
if v.Name == specQuality {
ggValueID = v.ID
}
}
if ggValueID == 0 { //说明没有建这个规格,要建上
catID, _ := api.JdShopAPI.SaveVenderAttrValue(specQuality, attrIDs["规格"], int(storeSku.VendorVendorCatID), maxNo+1)
ggValueID = catID
}
attrSku := &jdshopapi.CreateSkuParamAttrs{
AttrID: utils.Int2Str(attrIDs["规格"]),
AttrValues: []string{utils.Int64ToStr(ggValueID)},
}
attrsPropSku = append(attrsPropSku, attrSku)
sku := &jdshopapi.CreateSkuParamSkus{
JdPrice: int(v.VendorPrice),
StockNum: 9999,
Type: "com.jd.pop.ware.ic.api.domain.sku",
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
OuterID: utils.Int2Str(v.SkuID),
}
sku.SaleAttrs = attrsPropSku
createSkuParamSkus = append(createSkuParamSkus, sku)
}
return createSkuParamWare, createSkuParamSkus, err
}

View File

@@ -96,6 +96,14 @@ func (p *PurchaseHandler) CreateStore(db *dao.DaoDB, storeID int, userName strin
return p.UpdateStore(db, storeID, userName)
}
func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}
func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
var name string
if db == nil {

View File

@@ -15,6 +15,14 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
return err
}
func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}
func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
return err
}
func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
return hint, err
}