This commit is contained in:
邹宗楠
2022-12-14 16:35:38 +08:00
parent fc5a93a21d
commit 1d3f68c103
3 changed files with 104 additions and 181 deletions

View File

@@ -1,7 +1,6 @@
package tiktok_store
import (
"errors"
"fmt"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
product_listV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_listV2/request"
@@ -76,62 +75,6 @@ func (p *PurchaseHandler) IsErrCategoryNotExist(err error) (isNotExist bool) {
}
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
//level := 1
//if storeCat.ParentCatName != "" {
// level = 2
//}
//originName := ""
//catName := storeCat.Name
//catCode := storeCat.ID
//
//subCatName := ""
//subCatCode := 0
//if storeCat.CatSyncStatus&model.SyncFlagNewMask == 0 {
// // 修改一级分类
// originName = storeCat.VendorCatID
//}
//if level == 2 { // 二级分类
// // 创建二级分类
// originName = storeCat.ParentVendorCatID
// catName = storeCat.ParentCatName
// catCode = storeCat.ParentID
// subCatName = storeCat.Name
// subCatCode = storeCat.ID
// if storeCat.CatSyncStatus&model.SyncFlagNewMask == 0 {
// // 修改二级分类
// originName = storeCat.VendorCatID
// catName = storeCat.Name
// catCode = storeCat.ID
// subCatName = ""
// subCatCode = 0
// }
//}
//if catName == "" {
// panic("catName is empty")
//}
//catName = utils.FilterEmoji(catName)
//subCatName = utils.FilterEmoji(subCatName)
// vendorStoreID, originName, catCode, catName, subCatCode, subCatName, storeCat.Seq)
//if globals.EnableMtwmStoreWrite {
// // err = api.MtwmAPI.RetailCatUpdate2(vendorStoreID, tryCatName2Code(originName), originName, catCode2Str(catCode), catName, catCode2Str(subCatCode), subCatName, storeCat.Seq)
// param4Update := &mtwmapi.Param4UpdateCat{
// CategoryCodeOrigin: tryCatName2Code(originName),
// CategoryNameOrigin: originName,
// CategoryCode: catCode2Str(catCode),
// SecondaryCategoryCode: catCode2Str(subCatCode),
// SecondaryCategoryName: subCatName,
// Sequence: storeCat.Seq,
// }
// err = getAPI(storeCat.VendorOrgCode, storeID, vendorStoreID).RetailCatUpdate(vendorStoreID, catName, param4Update)
// if storeCat.CatSyncStatus&model.SyncFlagNewMask == 0 && p.IsErrCategoryNotExist(err) && originName != "" { // 修改分类名,但分类不存在
// storeCat.CatSyncStatus |= model.SyncFlagNewMask
// err = p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat)
// }
//}
//if err == nil {
// // storeCat.VendorCatID = utils.FilterEmoji(storeCat.Name)
// storeCat.VendorCatID = utils.Int2Str(storeCat.ID)
//}
return err
}
@@ -140,23 +83,6 @@ func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID in
}
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) {
//if false {
// if globals.EnableMtwmStoreWrite {
// err = getAPI(getStoreVendorOrgCode(storeID), storeID, vendorStoreID).RetailCatDelete(vendorStoreID, tryCatName2Code(vendorCatID), vendorCatID)
// }
//} else {
// var catCodes []string
// if catCode := tryCatName2Code(vendorCatID); catCode != "" {
// catCodes = []string{catCode}
// }
// if globals.EnableMtwmStoreWrite {
// if level == 1 {
// err = getAPI(getStoreVendorOrgCode(storeID), storeID, vendorStoreID).RetailCatSkuBatchDelete2(ctx.GetTrackInfo(), vendorStoreID, catCodes, []string{vendorCatID}, nil, nil, nil)
// } else {
// err = getAPI(getStoreVendorOrgCode(storeID), storeID, vendorStoreID).RetailCatSkuBatchDelete2(ctx.GetTrackInfo(), vendorStoreID, nil, nil, catCodes, []string{vendorCatID}, nil)
// }
// }
//}
return err
}
@@ -181,22 +107,12 @@ func (p *PurchaseHandler) IsErrSkuNotExist(err error) (isNotExist bool) {
// }
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
failedList, err = p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, false)
// if err == nil && vendorStoreID == specialStoreID {
// for i := 0; i < 2; i++ {
// p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, duplicateStoreSkuList(storeSkuList, i+1), true)
// }
// }
return failedList, err
}
// CreateStoreSkus 门店创建商品
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
failedList, err = p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, true)
//if err == nil && vendorStoreID == specialStoreID {
// for i := 0; i < 2; i++ {
// p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, duplicateStoreSkuList(storeSkuList, i+1), true)
// }
//}
return failedList, err
}
@@ -207,7 +123,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v
continue
}
if err = getAPI(storeSkuList[0].VendorOrgCode, storeID, vendorStoreID).DeleteStoreCommodity(utils.Str2Int64(v.VendorSkuID)); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "删除商品")...)
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "删除商品")...)
}
dao.DeleteThingToTiktokMapList(model.VendorIDDD, v.VendorMainId)
}
@@ -224,16 +140,16 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
if status == model.SkuStatusNormal { // 下架
for _, v := range storeSkuList {
// 子品商品id获取skuId
childrenSku, err := api.GetSkuDetail(v.VendorSkuID, "")
if err != nil {
return nil, err
}
if len(childrenSku.SpecPrices) <= 0 {
return nil, errors.New("子品商品详情获取失败")
}
//childrenSku, err := api.GetSkuDetail(v.VendorSkuID, "")
//if err != nil {
// return nil, err
//}
//if len(childrenSku.SpecPrices) <= 0 {
// return nil, errors.New("子品商品详情获取失败")
//}
param := &sku_syncStock_request.SkuSyncStockParam{
SkuId: childrenSku.SpecPrices[0].SkuId,
//SkuId: childrenSku.SpecPrices[0].SkuId,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
IdempotentId: "",
@@ -241,23 +157,22 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
OutWarehouseId: vendorStoreID,
}
if err := api.UpdateSkuStock(param); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("下架架商品异常,添加固定库存.%s", utils.Format4Output(param, false)))...)
} else {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("下架商品异常,添加固定库存.%s", utils.Format4Output(param, false)))...)
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("架商品,库存值最大化.%s", utils.Format4Output(param, false)))...)
}
}
} else { // 上架
for _, v := range storeSkuList {
// 子品商品id获取skuId
childrenSku, err := api.GetSkuDetail(v.VendorSkuID, "")
if err != nil {
return nil, err
}
if len(childrenSku.SpecPrices) <= 0 {
return nil, errors.New("子品商品详情获取失败")
}
//childrenSku, err := api.GetSkuDetail(v.VendorSkuID, "")
//if err != nil {
// return nil, err
//}
//if len(childrenSku.SpecPrices) <= 0 {
// return nil, errors.New("子品商品详情获取失败")
//}
param := &sku_syncStock_request.SkuSyncStockParam{
SkuId: childrenSku.SpecPrices[0].SkuId,
//SkuId: childrenSku.SpecPrices[0].SkuId,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
IdempotentId: "",
@@ -265,9 +180,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
OutWarehouseId: vendorStoreID,
}
if err := api.UpdateSkuStock(param); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("架商品异常,添加固定库存.%s", utils.Format4Output(param, false)))...)
} else {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("上架商品正常,添加固定库存.%s", utils.Format4Output(param, false)))...)
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("架商品,库存值为0失败.%s", utils.Format4Output(param, false)))...)
}
}
}
@@ -282,20 +195,20 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
api := getAPI(vendorOrgCode, storeID, vendorStoreID)
for _, v := range storeSkuList {
// 更新主品 (暂不支持渠道主商品)
// 更新子品价格
err = api.EditPrice(&sku_editPrice_request.SkuEditPriceParam{
Price: v.VendorPrice,
SkuId: utils.Str2Int64(v.VendorSkuAttrId),
ProductId: utils.Str2Int64(v.VendorMainId),
Price: v.VendorPrice,
//SkuId: utils.Str2Int64(v.VendorSkuAttrId),
ProductId: utils.Str2Int64(v.VendorSkuID),
})
if err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "更新主品价格异常")...)
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "同步子品价格异常")...)
}
// 更新子品
if _, err := api.BatchApplyStoreProductPrice(utils.Str2Int64(v.VendorMainId)); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "同步子品价格异常")...)
}
//if _, err := api.BatchApplyStoreProductPrice(utils.Str2Int64(v.VendorMainId)); err != nil {
// failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "同步子品价格异常")...)
//}
//err = api.EditPrice(&sku_editPrice_request.SkuEditPriceParam{
// Price: v.VendorPrice,
// SkuId: utils.Str2Int64(v.VendorSonSkuID),
@@ -308,9 +221,9 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg
//}
}
if len(failedList) > 0 {
err = nil
}
//if len(failedList) > 0 {
// err = nil
//}
return failedList, err
}
@@ -318,22 +231,25 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
tiktokApi := getAPI(storeSkuList[0].VendorOrgCode, storeID, vendorStoreID)
for _, v := range storeSkuList {
err := tiktokApi.UpdateSkuStock(&sku_syncStock_request.SkuSyncStockParam{
SkuId: utils.Str2Int64(v.VendorSkuAttrId),
stockNum := &sku_syncStock_request.SkuSyncStockParam{
//SkuId: utils.Str2Int64(v.VendorSkuAttrId),
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
IdempotentId: "",
StockNum: int64(v.Stock),
OutWarehouseId: vendorStoreID,
})
if err != nil {
}
if stockNum.StockNum == 0 {
stockNum.StockNum = 99999
}
if err := tiktokApi.UpdateSkuStock(stockNum); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "更新库存错误")...)
} else {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "更新库存正常")...)
}
}
return p.UpdateStoreSkusPrice(ctx, vendorOrgCode, storeID, vendorStoreID, storeSkuList)
return failedList, err
//return p.UpdateStoreSkusPrice(ctx, vendorOrgCode, storeID, vendorStoreID, storeSkuList)
}
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (skuNameList []*partner.SkuNameInfo, err error) {