This commit is contained in:
邹宗楠
2023-01-06 13:37:41 +08:00
parent 21bf72af71
commit a1584a6d72
4 changed files with 63 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ import (
"git.rosy.net.cn/jx-callback/globals"
"math/rand"
"strings"
"time"
"unicode"
)
@@ -147,7 +148,10 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
if len(localThing) == 0 {
//if mainProductId == 0 {
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(time.Now().Unix()), storeDetail.VendorOrgCode, "本地不存在,线上也不存在", model.ThingTypeSku, model.ThingTypeSyncing); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
param, failedList2 := makeMainProductSku(db, api, storeSku, storeDetail, storeID, vendorStoreID, syncType)
if len(failedList2) != 0 {
failedList = append(failedList, failedList2...)
@@ -155,10 +159,15 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
if err != nil {
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(tiktokResult.ProductId), storeDetail.VendorOrgCode, "本地不存在,线上也不存在", model.ThingTypeSku, 0)
var attrId []string
for _, v := range tiktokResult.Sku {
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
@@ -171,7 +180,37 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
storeSku.VendorSonSkuID = utils.Int2Str(storeSku.SkuID) // 还没同步子商品
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("只创建了主商品,没创建子商品"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
} else {
} else if localThing[0].SyncStatus == model.ThingTypeSyncFail { // 同步失败在重新创建
param, failedList2 := makeMainProductSku(db, api, storeSku, storeDetail, storeID, vendorStoreID, syncType)
if len(failedList2) != 0 {
failedList = append(failedList, failedList2...)
continue
}
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
if err != nil {
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
var attrId []string
for _, v := range tiktokResult.Sku {
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
}
mainProductId = tiktokResult.ProductId
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
storeSku.VendorMainId = utils.Int64ToStr(tiktokResult.ProductId)
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
storeSku.VendorSonSkuID = utils.Int2Str(storeSku.SkuID) // 还没同步子商品
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("只创建了主商品,没创建子商品"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
} else if localThing[0].SyncStatus == model.ThingTypeSyncing {
continue
} else if localThing[0].SyncStatus == model.ThingTypeSyncSuccess {
// 主商品存在,直接同步子商品
childrenProductId, err := api.CreateSubProduct(utils.Str2Int64(localThing[0].VendorThingID), utils.Str2Int64(vendorStoreID))
if err != nil && strings.Contains(err.Error(), "2010004") { // 2010004:主商品非在线审核通过状态,不允许绑定子商品