dyps update

This commit is contained in:
richboo111
2023-01-09 13:48:35 +08:00
22 changed files with 400 additions and 344 deletions

View File

@@ -40,7 +40,6 @@ func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackRes
//}
jxutils.CallMsgHandler(func() {
response = CurPurchaseHandler.onOrderMsg(msgId, orderId, msg)
globals.SugarLogger.Debugf("OnOrderMsg response====%s", utils.Format4Output(response, false))
}, jxutils.ComposeUniversalOrderID(orderId, model.VendorIDDD))
}
return response

View File

@@ -130,17 +130,15 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
if status == model.SkuStatusNormal { // 下架
for _, v := range storeSkuList {
// 子品商品id获取skuId
childrenSkuId, failedList := getProductSkuId4UpdateStock(api, v, storeID)
if len(failedList) > 0 {
continue
}
//childrenSkuId, failedList := getProductSkuId4UpdateStock(api, v, storeID)
//if len(failedList) > 0 {
// continue
//}
param := &sku_syncStock_request.SkuSyncStockParam{
SkuId: childrenSkuId,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
IdempotentId: "",
StockNum: 99999,
OutWarehouseId: vendorStoreID,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
StockNum: 99999,
OutSkuId: int64(v.SkuID),
}
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)))...)
@@ -149,18 +147,16 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
} else { // 上架
for _, v := range storeSkuList {
// 子品商品id获取skuId
childrenSkuId, failedList := getProductSkuId4UpdateStock(api, v, storeID)
if len(failedList) > 0 {
continue
}
//childrenSkuId, failedList := getProductSkuId4UpdateStock(api, v, storeID)
//if len(failedList) > 0 {
// continue
//}
param := &sku_syncStock_request.SkuSyncStockParam{
SkuId: childrenSkuId,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
IdempotentId: "",
StockNum: 0,
OutWarehouseId: vendorStoreID,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
StockNum: 0,
OutSkuId: int64(v.SkuID),
}
if err := api.UpdateSkuStock(param); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("下架商品,库存值为0失败.%s", utils.Format4Output(param, false)))...)
@@ -174,14 +170,11 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
// UpdateStoreSkusPrice 更新商品价格
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)
globals.SugarLogger.Debugf("看看走这儿了没,是不是更新 storeSkuList %s", utils.Format4Output(storeSkuList, false))
for _, v := range storeSkuList {
tiktokSkuId, failedList := getProductSkuId4UpdateStock(api, v, storeID)
if len(failedList) > 0 {
globals.SugarLogger.Debugf("看看走这儿了没,是不是更新 参数failedList1 %s", utils.Format4Output(failedList, false))
return failedList, err
}
globals.SugarLogger.Debugf("====SkuId:= %d,ProductId := %d ", tiktokSkuId, utils.Str2Int64(v.VendorMainId))
price := &sku_editPrice_request.SkuEditPriceParam{
Price: v.VendorPrice,
SkuId: tiktokSkuId,
@@ -191,9 +184,6 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg
if err = api.EditPrice(price); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "更新价格异常")...)
}
globals.SugarLogger.Debugf("看看走这儿了没,是不是更新 参数 %s", utils.Format4Output(price, false))
globals.SugarLogger.Debugf("看看走这儿了没,是不是更新 返回值 %s", utils.Format4Output(failedList, false))
globals.SugarLogger.Debugf("看看走这儿了没,是不是更新 结构体 %s", utils.Format4Output(v, false))
}
return failedList, err
}
@@ -203,18 +193,16 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrg
tiktokApi := getAPI(storeSkuList[0].VendorOrgCode, storeID, vendorStoreID)
for _, v := range storeSkuList {
// 子品商品id获取skuId
childrenSkuId, failedList := getProductSkuId4UpdateStock(tiktokApi, v, storeID)
if len(failedList) > 0 {
continue
}
//childrenSkuId, failedList := getProductSkuId4UpdateStock(tiktokApi, v, storeID)
//if len(failedList) > 0 {
// continue
//}
stockNum := &sku_syncStock_request.SkuSyncStockParam{
SkuId: childrenSkuId,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
IdempotentId: "",
StockNum: int64(v.Stock),
OutWarehouseId: vendorStoreID,
ProductId: utils.Str2Int64(v.VendorSkuID),
Incremental: false,
StockNum: int64(v.Stock),
OutSkuId: int64(v.SkuID),
}
if stockNum.StockNum == 0 {
stockNum.StockNum = 99999

View File

@@ -28,6 +28,7 @@ import (
"git.rosy.net.cn/jx-callback/globals"
"math/rand"
"strings"
"time"
"unicode"
)
@@ -136,80 +137,6 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
if storeSku.StoreSkuStatus != 1 { // 未可售的商品不参与修改
continue
}
param := &product_addV2_request.ProductAddV2Param{
Name: utils.LimitUTF8StringLen(storeSku.SkuName, 90),
PayType: tiktokShop.TiktokPayType1,
ReduceType: tiktokShop.SkuReduceTypePayMakeOrder,
Weight: utils.Int2Float64(storeSku.Weight),
DeliveryDelayDay: tiktokShop.DeliveryDelayDayToDay,
PresellType: tiktokShop.SendGoodsTypeNow,
Supply7dayReturn: 0, // 是否支持7天无理由0不支持1支持2支持拆封后不支持
Mobile: storeDetail.Tel1,
Commit: true,
Specs: "重量|" + utils.Float64ToStr(float64(storeSku.SpecQuality)) + storeSku.SpecUnit,
NeedRechargeMode: false,
SellChannel: []int64{0},
StartSaleType: 0,
PickupMethod: "0",
OuterProductId: utils.Int2Str(storeSku.SkuID), // 本地skuId为外部商品id
}
param.Name = checkNameLenght(param.Name)
// 获取上传图,商品轮播图
img, detailImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
param.Pic = img
param.Description = detailImg
// 部分商品没有所属的分类,直接跳过!
if storeSku.SkuVendorMapCatID != "" {
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
} else if len(param.Pic) != 0 { // 自动推导分类id
param.CategoryLeafId, err = api.GetRecommendCategory(strings.Split(img, "|"))
if param.CategoryLeafId == 0 || err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("当前商品本地未设置抖音分类/抖音推荐分类查询错误:"+err.Error()), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
}
// 这个情况是原有商品不存在和推荐查询不到类目id是,使用京西类目和抖音类目的绑定关系
// 但是不太实用,导致商品类目错误被暂停营业等
//if storeSku.VendorVendorCatID != 0 && param.CategoryLeafId == 0 {
// param.CategoryLeafId = storeSku.VendorVendorCatID
//}
// 是否支持七天无理由
if api.GetProductUpdateRule(param.CategoryLeafId) {
param.Supply7dayReturn = 1
} else {
param.Supply7dayReturn = 0
}
// weight_unit 目前抖音只支持g和kg两种
param.WeightUnit = tiktokShop.WeightUint_G
// spec_prices
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
// 获取商品的属性
if storeSku.TiktokAttribute != "" && storeSku.TiktokAttribute != "{}" {
param.ProductFormatNew = storeSku.TiktokAttribute
} else if storeSku.VendorSkuAttrId != "" && storeSku.VendorSkuAttrId != "{}" {
param.ProductFormatNew = storeSku.TiktokAttribute
} else {
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
}
param.StandardBrandId = 789194134 // 默认品牌京西菜市 596120136
param.FreightId, param.SaleLimitId, err = getFreightIdAndSaleLimitId(api, db, storeDetail, vendorStoreID)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
// 根据本地商品id获取线上商品是否存在,存在则只创建子商品
// 获取本地存储映射关系,获取本地主商品id是否存在
@@ -218,115 +145,133 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
if len(localThing) != 0 {
mainProductId = utils.Str2Int64(localThing[0].VendorThingID)
} else {
mainOrderDetail = loadMainProductId(api, storeSku)
mainProductId = mainOrderDetail.MainProductId
}
if len(localThing) == 0 {
if mainProductId == 0 {
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
if 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))
}
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 {
// 本地不存在,线上存在.直接创建子商品保存本地同步记录
var childrenProductId int64 = 0
dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainProductId), storeDetail.VendorOrgCode, "线上存在本地不存在", model.ThingTypeSku, 0)
childrenProductId, err = api.CreateSubProduct(mainProductId, utils.Str2Int64(vendorStoreID))
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
storeSku.VendorMainId = utils.Int64ToStr(mainProductId)
var attrId []string
for _, v := range mainOrderDetail.SpecPrices {
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
}
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
if childrenProductId > 0 {
storeSku.VendorSonSkuID = utils.Int64ToStr(childrenProductId) // (属性id skuID方案一)(自商品的商品id方案二)
storeSku.SkuSyncStatus = 0
storeSku.VendorSkuID = utils.Int64ToStr(childrenProductId) // 子商品主id
failedList = upDateChildrenPriceStockLaunch(api, storeSku, childrenProductId, vendorStoreID, syncType)
} else {
storeSku.VendorSonSkuID = utils.Int2Str(storeSku.SkuID) // (属性id skuID方案一)(自商品的商品id方案二)
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID) // 子商品主id
storeSku.SkuSyncStatus = model.SyncFlagNewMask
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("主商品创建了,子商品为创建"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
}
}
} else {
// 线上本地都存在,但是线上审核不成功,就去更新主商品
//if mainOrderDetail.CheckStatus == tiktokShop.SkuCheckStatusProhibit || mainOrderDetail.CheckStatus == tiktokShop.SkuCheckStatusNotPass {
// // 更新主商品,在同步到子门店,考虑审核时间
// updateParam := &product_editV2_request.ProductEditV2Param{
// PayType: tiktokShop.TiktokPayType1,
// ReduceType: tiktokShop.SkuReduceTypePayMakeOrder,
// Weight: utils.Int2Float64(storeSku.Weight),
// DeliveryDelayDay: tiktokShop.DeliveryDelayDayToDay,
// PresellType: tiktokShop.SendGoodsTypeNow,
// Supply7dayReturn: 0,
// Mobile: storeDetail.Tel1,
// Commit: true,
// Specs: "重量|" + utils.Float64ToStr(float64(storeSku.SpecQuality)) + storeSku.SpecUnit,
// NeedRechargeMode: false,
// SellChannel: []int64{0},
// StartSaleType: 0,
// PickupMethod: "0",
// CategoryLeafId: param.CategoryLeafId,
// Name: param.Name,
// ProductFormatNew: param.ProductFormatNew,
// }
// updateParam.Pic = img
// updateParam.Description = detailImg
// updateParam.WeightUnit = tiktokShop.WeightUint_G
// updateParam.StandardBrandId = param.StandardBrandId // 默认品牌京西菜市
// updateParam.ProductId = mainOrderDetail.ProductId
// updateParam.MainProductId = mainProductId
// updateParam.SpecPrices = param.SpecPrices
// //updateParam.StoreId = utils.Str2Int64(vendorStoreID)
// if err := api.EditStoreCommodity(updateParam); err != nil {
// failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
// storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
// } else {
// localThing[0].UpdatedAt = time.Now()
// localThing[0].SyncStatus = 0
// localThing[0].ThingType = model.ThingTypeSku
// dao.UpdateThingMap(localThing[0])
// }
// continue
//}
// 主商品存在,直接同步子商品
childrenProductId, err := api.CreateSubProduct(utils.Str2Int64(localThing[0].VendorThingID), utils.Str2Int64(vendorStoreID))
if err != nil || childrenProductId == 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...)
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)
storeSku.SkuSyncStatus = model.SyncFlagStoreSkuModifiedMask
storeSku.VendorSonSkuID = utils.Int64ToStr(childrenProductId) // (属性id skuID方案一)(自商品的商品id方案二)
storeSku.VendorSkuID = utils.Int64ToStr(childrenProductId) // 子商品主id
storeSku.VendorMainId = localThing[0].VendorThingID // 商品主id
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.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:主商品非在线审核通过状态,不允许绑定子商品
// 线上本地都存在,但是线上审核不成功,就去更新主商品
mainOrderDetail = loadMainProductId(api, storeSku, localThing[0].VendorThingID)
if mainOrderDetail.CheckStatus == tiktokShop.SkuCheckStatusProhibit || mainOrderDetail.CheckStatus == tiktokShop.SkuCheckStatusNotPass {
// 更新主商品,在同步到子门店,考虑审核时间
param, failedList2 := makeMainProductSku(db, api, storeSku, storeDetail, storeID, vendorStoreID, syncType)
if len(failedList2) != 0 {
failedList = append(failedList, failedList2...)
continue
}
updateParam := &product_editV2_request.ProductEditV2Param{
PayType: tiktokShop.TiktokPayType1,
ReduceType: tiktokShop.SkuReduceTypePayMakeOrder,
Weight: utils.Int2Float64(storeSku.Weight),
DeliveryDelayDay: tiktokShop.DeliveryDelayDayToDay,
PresellType: tiktokShop.SendGoodsTypeNow,
Supply7dayReturn: 0,
Mobile: storeDetail.Tel1,
Commit: true,
Specs: "重量|" + utils.Float64ToStr(float64(storeSku.SpecQuality)) + storeSku.SpecUnit,
NeedRechargeMode: false,
SellChannel: []int64{0},
StartSaleType: 0,
PickupMethod: "0",
CategoryLeafId: param.CategoryLeafId,
Name: param.Name,
ProductFormatNew: param.ProductFormatNew,
}
updateParam.Pic = param.Pic
updateParam.Description = param.Description
updateParam.WeightUnit = tiktokShop.WeightUint_G
updateParam.StandardBrandId = param.StandardBrandId // 默认品牌京西菜市
updateParam.ProductId = mainOrderDetail.ProductId
updateParam.MainProductId = mainProductId
updateParam.SpecPrices = param.SpecPrices
if err := api.EditStoreCommodity(updateParam); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
}
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("修改主品,主品审核中/失败,子商品未创建"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
}
if (err != nil || childrenProductId == 0) && !strings.Contains(err.Error(), "2010001") { // 2010001:重复创建渠道商品,就去更新
continue
//param := &superm_product_batchRedistributeStoreProduct_request.TaskParams{
// MainProductId: utils.Str2Int64(localThing[0].VendorThingID),
// AddStoreIds: []int64{utils.Str2Int64(vendorStoreID)},
// DelStoreIds: []int64{utils.Str2Int64(vendorStoreID)},
//}
//if _, err := api.BatchRedistributeStoreProduct(param); err != nil {
// failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
// continue
//}
}
// 同步价格,库存,上架
failedList = upDateChildrenPriceStockLaunch(api, storeSku, childrenProductId, vendorStoreID, syncType)
upDateChildrenPriceStockLaunch(api, storeSku, childrenProductId, vendorStoreID, syncType)
storeSku.VendorSonSkuID = utils.Int64ToStr(childrenProductId) // (属性id skuID方案一)(自商品的商品id方案二)
storeSku.VendorSkuID = utils.Int64ToStr(childrenProductId) // 子商品主id
storeSku.VendorMainId = localThing[0].VendorThingID // 商品主id
@@ -356,11 +301,6 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
StartSaleType: 0,
PickupMethod: "0",
}
if storeSku.SkuVendorMapCatID != "" {
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
} else {
param.CategoryLeafId = storeSku.VendorVendorCatID
}
param.Name = checkNameLenght(param.Name)
// 获取上传图,商品轮播图
@@ -373,6 +313,43 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
param.Description = detailImg
param.WeightUnit = tiktokShop.WeightUint_G
// 部分商品没有所属的分类,直接跳过!
if storeSku.SkuVendorMapCatID != "" {
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
} else if len(param.Pic) != 0 { // 自动推导分类id
param.CategoryLeafId, err = api.GetRecommendCategory(strings.Split(img, "|"))
if param.CategoryLeafId == 0 || err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("当前商品本地未设置抖音分类/抖音推荐分类查询错误:"+err.Error()), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
}
// 获取主商品id
var mainIdInt int64
if storeSku.VendorMainId == "" {
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
if len(localThing) == 0 || localThing == nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New(fmt.Sprintf("更新主品失败,请创建主品skuId[storeId:%d,skuId:%s]", storeID, storeSku.SkuID)), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
} else {
storeSku.VendorMainId = localThing[0].VendorThingID
mainIdInt = utils.Str2Int64(localThing[0].VendorThingID)
}
} else {
mainIdInt = utils.Str2Int64(storeSku.VendorMainId)
}
// 更新商品,主品如果名字和类目没变化,则更新子品价格!
mainProductDetail, err := api.GetSkuDetail(utils.Int64ToStr(mainIdInt), "")
if err != nil || mainProductDetail == nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
//if mainProductDetail.Name == param.Name && (mainProductDetail.CategoryDetail.ThirdCid == param.CategoryLeafId || mainProductDetail.CategoryDetail.FourthCid == param.CategoryLeafId) {
// upDateChildrenPriceStockLaunch(api, storeSku, utils.Str2Int64(storeSku.VendorSkuID), vendorStoreID, syncType)
// continue
//}
// 获取商品的属性
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
@@ -385,73 +362,111 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
// 获取品牌
param.StandardBrandId = 789194134 // 默认品牌京西菜市
var mainIdInt int64
if storeSku.VendorMainId == "" {
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
if len(localThing) == 0 || localThing == nil {
mainOrderDetail := loadMainProductId(api, storeSku)
if mainOrderDetail.MainProductId == 0 {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("主商品获取失败"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
mainIdInt = mainOrderDetail.MainProductId
storeSku.VendorMainId = utils.Int64ToStr(mainIdInt)
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)
}
} else {
mainIdInt = utils.Str2Int64(storeSku.VendorMainId)
}
// 修改商品
param.ProductId = mainIdInt
param.MainProductId = mainIdInt
//param.StoreId = utils.Str2Int64(vendorStoreID)
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, param.MainProductId, storeSku)
if err := api.EditStoreCommodity(param); err != nil {
globals.SugarLogger.Debugf("====EditStoreCommodity===== %s", err.Error())
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
continue
}
// todo 更主品的同间考虑更新子品,子品的更新只能重新分配子品,在更新价格
//if storeSku.VendorSkuID != "" && len(storeSku.VendorSkuID) > 19 {
// failedList = upDateChildrenPriceStockLaunch(api, storeSku, utils.Str2Int64(storeSku.VendorSkuID), vendorStoreID, syncType)
//}
storeSku.StoreSkuStatus = 57 // 品库修改 售卖状态待同步 价格待同步
storeSku.SkuSyncStatus = 57 // 品库修改 售卖状态待同步 价格待同步
}
return
}
return failedList, err
}
func loadMainProductId(api *tiktokShop.API, storeSku *dao.StoreSkuSyncInfo) *product_detail_response.ProductDetailData {
// 这有可能获取的值主商品也有可能是子商品,我们需要的是主商品id和状态
var mainOrderDetail = &product_detail_response.ProductDetailData{}
mainOrderDetailSkuId, err := api.GetSkuDetailLocalID("", utils.Int2Str(storeSku.SkuID))
if err != nil || mainOrderDetailSkuId == nil {
mainOrderDetail.MainProductId = 0
return mainOrderDetail
func makeMainProductSku(db *dao.DaoDB, api *tiktokShop.API, storeSku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, storeID int, vendorStoreID, syncType string) (param *product_addV2_request.ProductAddV2Param, failedList []*partner.StoreSkuInfoWithErr) {
param = &product_addV2_request.ProductAddV2Param{
Name: utils.LimitUTF8StringLen(storeSku.SkuName, 90),
PayType: tiktokShop.TiktokPayType1,
ReduceType: tiktokShop.SkuReduceTypePayMakeOrder,
Weight: utils.Int2Float64(storeSku.Weight),
DeliveryDelayDay: tiktokShop.DeliveryDelayDayToDay,
PresellType: tiktokShop.SendGoodsTypeNow,
Supply7dayReturn: 0, // 是否支持7天无理由0不支持1支持2支持拆封后不支持
Mobile: storeDetail.Tel1,
Commit: true,
Specs: "重量|" + utils.Float64ToStr(float64(storeSku.SpecQuality)) + storeSku.SpecUnit,
NeedRechargeMode: false,
SellChannel: []int64{0},
StartSaleType: 0,
PickupMethod: "0",
OuterProductId: utils.Int2Str(storeSku.SkuID), // 本地skuId为外部商品id
}
if mainOrderDetailSkuId.MainProductId != 0 { // 查询出来是子商品
mainOrderDetail.MainProductId = mainOrderDetailSkuId.MainProductId
} else { // 查询出来是主商品
mainOrderDetail.MainProductId = mainOrderDetailSkuId.ProductId
return mainOrderDetail
param.Name = checkNameLenght(param.Name)
// 获取上传图,商品轮播图
img, detailImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
return
}
param.Pic = img
param.Description = detailImg
// 部分商品没有所属的分类,直接跳过!
if storeSku.SkuVendorMapCatID != "" {
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
} else if len(param.Pic) != 0 { // 自动推导分类id
param.CategoryLeafId, err = api.GetRecommendCategory(strings.Split(img, "|"))
if param.CategoryLeafId == 0 || err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("当前商品本地未设置抖音分类/抖音推荐分类查询错误:"+err.Error()), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
return
}
}
// 这个情况是原有商品不存在和推荐查询不到类目id是,使用京西类目和抖音类目的绑定关系
// 但是不太实用,导致商品类目错误被暂停营业等
//if storeSku.VendorVendorCatID != 0 && param.CategoryLeafId == 0 {
// param.CategoryLeafId = storeSku.VendorVendorCatID
//}
// 是否支持七天无理由
if api.GetProductUpdateRule(param.CategoryLeafId) {
param.Supply7dayReturn = 1
} else {
param.Supply7dayReturn = 0
}
if mainOrderDetail.MainProductId != 0 { // 子商品时,获取主商品id和状态
mainOrderDetailProductId, err := api.GetSkuDetail(utils.Int64ToStr(mainOrderDetail.MainProductId), "")
if err != nil || mainOrderDetailProductId == nil {
mainOrderDetail.MainProductId = 0
return mainOrderDetail
}
mainOrderDetail.MainProductId = mainOrderDetailProductId.ProductId
// weight_unit 目前抖音只支持g和kg两种
param.WeightUnit = tiktokShop.WeightUint_G
// spec_prices
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
// 获取商品的属性
if storeSku.TiktokAttribute != "" && storeSku.TiktokAttribute != "{}" {
param.ProductFormatNew = storeSku.TiktokAttribute
} else if storeSku.VendorSkuAttrId != "" && storeSku.VendorSkuAttrId != "{}" {
param.ProductFormatNew = storeSku.TiktokAttribute
} else {
mainOrderDetail.MainProductId = mainOrderDetail.ProductId // 主商品
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
return
}
}
return mainOrderDetail
param.StandardBrandId = 789194134 // 默认品牌京西菜市 596120136
param.FreightId, param.SaleLimitId, err = getFreightIdAndSaleLimitId(api, db, storeDetail, vendorStoreID)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
return
}
return
}
func loadMainProductId(api *tiktokShop.API, storeSku *dao.StoreSkuSyncInfo, mainProductId string) *product_detail_response.ProductDetailData {
// 这有可能获取的值主商品也有可能是子商品,我们需要的是主商品id和状态
mainOrderDetailProductId, err := api.GetSkuDetail(mainProductId, "")
if err != nil || mainOrderDetailProductId == nil {
mainOrderDetailProductId.MainProductId = 0
mainOrderDetailProductId.CheckStatus = 4
return mainOrderDetailProductId
}
return mainOrderDetailProductId
}
func checkNameLenght(name string) string {
@@ -516,14 +531,13 @@ func upDateChildrenPriceStockLaunch(api *tiktokShop.API, storeSku *dao.StoreSkuS
}); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeSku.StoreID, model.VendorChineseNames[model.VendorIDDD], syncType)
}
// 同步库存
paramStock := &sku_syncStock_request.SkuSyncStockParam{
SkuId: skuId,
ProductId: childrenProductId,
Incremental: false,
IdempotentId: "",
StockNum: int64(storeSku.Stock),
OutWarehouseId: vendorStoreID,
ProductId: childrenProductId,
Incremental: false,
StockNum: int64(storeSku.Stock),
OutSkuId: int64(storeSku.SkuID),
}
if paramStock.StockNum == 0 {
paramStock.StockNum = 99999
@@ -531,6 +545,7 @@ func upDateChildrenPriceStockLaunch(api *tiktokShop.API, storeSku *dao.StoreSkuS
if err := api.UpdateSkuStock(paramStock); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(storeSku, err, storeSku.StoreID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("子商品添加固定库存.%s", err.Error()))...)
}
// 上架
if err := api.LaunchProduct(childrenProductId); err != nil {
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(storeSku, err, storeSku.StoreID, model.VendorChineseNames[model.VendorIDDD], fmt.Sprintf("上架子商品异常.%s", err.Error()))...)
@@ -551,6 +566,7 @@ func getProductSkuID(api *tiktokShop.API, storeSku *dao.StoreSkuSyncInfo, syncTy
childrenDetail, err := api.GetSkuDetail(utils.Int64ToStr(productId), "")
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeSku.StoreID, model.VendorChineseNames[model.VendorIDDD], syncType)
return 0, failedList
}
for _, v := range childrenDetail.SpecPrices {
@@ -582,7 +598,6 @@ func getProductSkuId4UpdateStock(api *tiktokShop.API, skuInfo *partner.StoreSkuI
}
}
globals.SugarLogger.Debugf("=GetSkuDetail By childrenSku %s", utils.Format4Output(childrenSku, false))
for _, v := range childrenSku.SpecPrices {
tiktokSkuId = v.SkuId
skuInfo.VendorSonSkuID = utils.Int64ToStr(v.SkuId)
@@ -750,7 +765,6 @@ func GetDeliveryTemp(api *tiktokShop.API, vendorStoreID string, storeDetail *dao
StoreId: utils.Str2Int64(vendorStoreID),
FreightId: temp.TemplateId,
}); err != nil {
globals.SugarLogger.Debugf("BindFreightTemplate =err %s", err)
return 0, err
}
freightId = temp.TemplateId

View File

@@ -270,11 +270,9 @@ func SpecialTreat(vendorOrgCode string, vendorStoreID, storeID, deliveryFeeDeduc
}
if bindFreightIDs == 0 { //1未查询到绑定信息不算错误
if freightTemplateID, err := CreateFreightTemplate(int(storeID)); err != nil || freightTemplateID == 0 || utils.IsNil(freightTemplateID) {
globals.SugarLogger.Debug("创建运费模板失败:", err)
errList.AddErr(fmt.Errorf("创建运费模板失败:%v", err))
} else { //绑定
if err = ShopBindStoreFreight(vendorOrgCode, vendorStoreID, freightTemplateID); err != nil {
globals.SugarLogger.Debugf("京西菜市门店:%d 平台门店:%d 绑定运费模板:%d 失败:%v", storeID, vendorStoreID, freightTemplateID, err)
errList.AddErr(fmt.Errorf("京西菜市门店:%d 平台门店:%d 绑定运费模板:%d 失败:%v", storeID, vendorStoreID, freightTemplateID, err))
} else {
FreightTemplate.TemplateID = freightTemplateID
@@ -319,7 +317,6 @@ func SpecialTreat(vendorOrgCode string, vendorStoreID, storeID, deliveryFeeDeduc
}
}
endErr := errList.GetErrListAsOne()
globals.SugarLogger.Debugf("SpecialTreat wrong information endErr: %s", endErr)
return endErr
}