Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop

This commit is contained in:
richboo111
2022-12-28 15:31:19 +08:00

View File

@@ -215,19 +215,13 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
// 获取本地存储映射关系,获取本地主商品id是否存在
var mainProductId int64 = 0
var mainOrderDetail *product_detail_response.ProductDetailData
globals.SugarLogger.Debugf("=======storesku %s", utils.Format4Output(storeSku, false))
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
globals.SugarLogger.Debugf("============1")
globals.SugarLogger.Debugf("=======localThing %s", utils.Format4Output(len(localThing), false))
if len(localThing) != 0 {
mainProductId = utils.Str2Int64(localThing[0].VendorThingID)
} else {
globals.SugarLogger.Debugf("============1.5")
mainOrderDetail = loadMainProductId(api, storeSku)
globals.SugarLogger.Debugf("=======mainOrderDetail loadMainProductId %s", utils.Format4Output(mainOrderDetail, false))
mainProductId = mainOrderDetail.MainProductId
}
globals.SugarLogger.Debugf("============2")
if len(localThing) == 0 {
if mainProductId == 0 {
@@ -236,11 +230,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(tiktokResult.ProductId), storeDetail.VendorOrgCode, "本地不存在,线上也不存在", model.ThingTypeSku, 0); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
}
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))
@@ -256,9 +246,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
} else {
// 本地不存在,线上存在.直接创建子商品保存本地同步记录
var childrenProductId int64 = 0
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainProductId), storeDetail.VendorOrgCode, "线上存在本地不存在", model.ThingTypeSku, 0); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
}
dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainProductId), storeDetail.VendorOrgCode, "线上存在本地不存在", model.ThingTypeSku, 0)
childrenProductId, err = api.CreateSubProduct(mainProductId, utils.Str2Int64(vendorStoreID))
if err != nil {
@@ -408,9 +396,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
mainIdInt = mainOrderDetail.MainProductId
storeSku.VendorMainId = utils.Int64ToStr(mainIdInt)
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainIdInt), storeDetail.VendorOrgCode, "更新发现不存在", model.ThingTypeSku, 0); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
}
dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainIdInt), storeDetail.VendorOrgCode, "更新发现不存在", model.ThingTypeSku, 0)
} else {
storeSku.VendorMainId = localThing[0].VendorThingID
mainIdInt = utils.Str2Int64(localThing[0].VendorThingID)
@@ -444,34 +430,27 @@ func loadMainProductId(api *tiktokShop.API, storeSku *dao.StoreSkuSyncInfo) *pro
// 这有可能获取的值主商品也有可能是子商品,我们需要的是主商品id和状态
var mainOrderDetail = &product_detail_response.ProductDetailData{}
mainOrderDetailSkuId, err := api.GetSkuDetailLocalID("", utils.Int2Str(storeSku.SkuID))
globals.SugarLogger.Debugf("=loadMainProductId==1 %s", utils.Format4Output(mainOrderDetailSkuId, false))
if err != nil || mainOrderDetailSkuId == nil {
mainOrderDetail.MainProductId = 0
globals.SugarLogger.Debugf("=loadMainProductId==2 %s", utils.Format4Output(mainOrderDetailSkuId, false))
return mainOrderDetail
}
globals.SugarLogger.Debugf("=loadMainProductId==3 %s", utils.Format4Output(mainOrderDetailSkuId, false))
if mainOrderDetailSkuId.MainProductId != 0 { // 查询出来是子商品
mainOrderDetail.MainProductId = mainOrderDetailSkuId.MainProductId
} else { // 查询出来是主商品
mainOrderDetail.MainProductId = mainOrderDetailSkuId.ProductId
globals.SugarLogger.Debugf("=loadMainProductId==4 %s", utils.Format4Output(mainOrderDetailSkuId, false))
return mainOrderDetail
}
if mainOrderDetail.MainProductId != 0 { // 子商品时,获取主商品id和状态
mainOrderDetailProductId, err := api.GetSkuDetail(utils.Int64ToStr(mainOrderDetail.MainProductId), "")
globals.SugarLogger.Debugf("=loadMainProductId==5 %s", utils.Format4Output(mainOrderDetailProductId, false))
if err != nil || mainOrderDetailProductId == nil {
mainOrderDetail.MainProductId = 0
globals.SugarLogger.Debugf("=loadMainProductId==6 %s", utils.Format4Output(mainOrderDetail, false))
return mainOrderDetail
}
mainOrderDetail.MainProductId = mainOrderDetailProductId.ProductId
} else {
mainOrderDetail.MainProductId = mainOrderDetail.ProductId // 主商品
}
globals.SugarLogger.Debugf("=loadMainProductId==7 %s", utils.Format4Output(mainOrderDetail, false))
return mainOrderDetail
}