1
This commit is contained in:
@@ -28,7 +28,6 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -215,15 +214,20 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
// 根据本地商品id获取线上商品是否存在,存在则只创建子商品
|
// 根据本地商品id获取线上商品是否存在,存在则只创建子商品
|
||||||
// 获取本地存储映射关系,获取本地主商品id是否存在
|
// 获取本地存储映射关系,获取本地主商品id是否存在
|
||||||
var mainProductId int64 = 0
|
var mainProductId int64 = 0
|
||||||
|
var mainOrderDetail *product_detail_response.ProductDetailData
|
||||||
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
|
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
|
||||||
mainOrderDetail, err := api.GetSkuDetailLocalID("", utils.Int2Str(storeSku.SkuID))
|
if len(localThing) != 0 {
|
||||||
if err != nil {
|
mainProductId = utils.Str2Int64(localThing[0].VendorThingID)
|
||||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
} else {
|
||||||
continue
|
mainOrderDetail, failedList = loadMainProductId(api, storeSku, storeID, syncType)
|
||||||
|
if len(failedList) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
mainProductId = mainOrderDetail.MainProductId
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(localThing) == 0 {
|
if len(localThing) == 0 {
|
||||||
if mainOrderDetail == nil || mainOrderDetail.ProductIdStr == "" {
|
if mainProductId == 0 {
|
||||||
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
|
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
|
||||||
if err != nil {
|
if err != nil {
|
||||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||||
@@ -247,18 +251,8 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
storeSku.VendorSonSkuID = utils.Int2Str(storeSku.SkuID) // 还没同步子商品
|
storeSku.VendorSonSkuID = utils.Int2Str(storeSku.SkuID) // 还没同步子商品
|
||||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("只创建了主商品,没创建子商品"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("只创建了主商品,没创建子商品"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||||
} else {
|
} else {
|
||||||
if mainOrderDetail.MainProductId != 0 {
|
|
||||||
mainProductId = mainOrderDetail.MainProductId
|
|
||||||
} else {
|
|
||||||
mainProductId = mainOrderDetail.ProductId
|
|
||||||
}
|
|
||||||
// 本地不存在,线上存在.直接创建子商品保存本地同步记录
|
// 本地不存在,线上存在.直接创建子商品保存本地同步记录
|
||||||
var childrenProductId int64 = 0
|
var childrenProductId int64 = 0
|
||||||
if mainOrderDetail.CheckStatus != tiktokShop.SkuCheckStatusPass && mainOrderDetail.CheckStatus != tiktokShop.SkuCheckStatusPassNotPutOn {
|
|
||||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, fmt.Errorf("主商品审核中或审核失败:[%d]", storeSku.SkuID), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainProductId), storeDetail.VendorOrgCode, "线上存在本地不存在", model.ThingTypeSku, 0); err != nil {
|
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)
|
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||||
}
|
}
|
||||||
@@ -289,45 +283,45 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 线上本地都存在,但是线上审核不成功,就去更新主商品
|
// 线上本地都存在,但是线上审核不成功,就去更新主商品
|
||||||
if mainOrderDetail.CheckStatus != tiktokShop.SkuCheckStatusPass && mainOrderDetail.CheckStatus != tiktokShop.SkuCheckStatusPassNotPutOn {
|
//if mainOrderDetail.CheckStatus == tiktokShop.SkuCheckStatusProhibit || mainOrderDetail.CheckStatus == tiktokShop.SkuCheckStatusNotPass {
|
||||||
// 更新主商品,在同步到子门店,考虑审核时间
|
// // 更新主商品,在同步到子门店,考虑审核时间
|
||||||
updateParam := &product_editV2_request.ProductEditV2Param{
|
// updateParam := &product_editV2_request.ProductEditV2Param{
|
||||||
PayType: tiktokShop.TiktokPayType1,
|
// PayType: tiktokShop.TiktokPayType1,
|
||||||
ReduceType: tiktokShop.SkuReduceTypePayMakeOrder,
|
// ReduceType: tiktokShop.SkuReduceTypePayMakeOrder,
|
||||||
Weight: utils.Int2Float64(storeSku.Weight),
|
// Weight: utils.Int2Float64(storeSku.Weight),
|
||||||
DeliveryDelayDay: tiktokShop.DeliveryDelayDayToDay,
|
// DeliveryDelayDay: tiktokShop.DeliveryDelayDayToDay,
|
||||||
PresellType: tiktokShop.SendGoodsTypeNow,
|
// PresellType: tiktokShop.SendGoodsTypeNow,
|
||||||
Supply7dayReturn: 0,
|
// Supply7dayReturn: 0,
|
||||||
Mobile: storeDetail.Tel1,
|
// Mobile: storeDetail.Tel1,
|
||||||
Commit: true,
|
// Commit: true,
|
||||||
Specs: "重量|" + utils.Float64ToStr(float64(storeSku.SpecQuality)) + storeSku.SpecUnit,
|
// Specs: "重量|" + utils.Float64ToStr(float64(storeSku.SpecQuality)) + storeSku.SpecUnit,
|
||||||
NeedRechargeMode: false,
|
// NeedRechargeMode: false,
|
||||||
SellChannel: []int64{0},
|
// SellChannel: []int64{0},
|
||||||
StartSaleType: 0,
|
// StartSaleType: 0,
|
||||||
PickupMethod: "0",
|
// PickupMethod: "0",
|
||||||
CategoryLeafId: param.CategoryLeafId,
|
// CategoryLeafId: param.CategoryLeafId,
|
||||||
Name: param.Name,
|
// Name: param.Name,
|
||||||
ProductFormatNew: param.ProductFormatNew,
|
// ProductFormatNew: param.ProductFormatNew,
|
||||||
}
|
// }
|
||||||
updateParam.Pic = img
|
// updateParam.Pic = img
|
||||||
updateParam.Description = detailImg
|
// updateParam.Description = detailImg
|
||||||
updateParam.WeightUnit = tiktokShop.WeightUint_G
|
// updateParam.WeightUnit = tiktokShop.WeightUint_G
|
||||||
updateParam.StandardBrandId = param.StandardBrandId // 默认品牌京西菜市
|
// updateParam.StandardBrandId = param.StandardBrandId // 默认品牌京西菜市
|
||||||
updateParam.ProductId = mainOrderDetail.ProductId
|
// updateParam.ProductId = mainOrderDetail.ProductId
|
||||||
updateParam.MainProductId = mainProductId
|
// updateParam.MainProductId = mainProductId
|
||||||
updateParam.SpecPrices = param.SpecPrices
|
// updateParam.SpecPrices = param.SpecPrices
|
||||||
//updateParam.StoreId = utils.Str2Int64(vendorStoreID)
|
// //updateParam.StoreId = utils.Str2Int64(vendorStoreID)
|
||||||
if err := api.EditStoreCommodity(updateParam); err != nil {
|
// if err := api.EditStoreCommodity(updateParam); err != nil {
|
||||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
// failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||||
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
|
// storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
|
||||||
} else {
|
// } else {
|
||||||
localThing[0].UpdatedAt = time.Now()
|
// localThing[0].UpdatedAt = time.Now()
|
||||||
localThing[0].SyncStatus = 0
|
// localThing[0].SyncStatus = 0
|
||||||
localThing[0].ThingType = model.ThingTypeSku
|
// localThing[0].ThingType = model.ThingTypeSku
|
||||||
dao.UpdateThingMap(localThing[0])
|
// dao.UpdateThingMap(localThing[0])
|
||||||
}
|
// }
|
||||||
continue
|
// continue
|
||||||
}
|
//}
|
||||||
|
|
||||||
// 主商品存在,直接同步子商品
|
// 主商品存在,直接同步子商品
|
||||||
childrenProductId, err := api.CreateSubProduct(utils.Str2Int64(localThing[0].VendorThingID), utils.Str2Int64(vendorStoreID))
|
childrenProductId, err := api.CreateSubProduct(utils.Str2Int64(localThing[0].VendorThingID), utils.Str2Int64(vendorStoreID))
|
||||||
@@ -404,17 +398,12 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
if storeSku.VendorMainId == "" {
|
if storeSku.VendorMainId == "" {
|
||||||
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
|
localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode)
|
||||||
if len(localThing) == 0 || localThing == nil {
|
if len(localThing) == 0 || localThing == nil {
|
||||||
mainOrderDetail, err := api.GetSkuDetailLocalID("", utils.Int2Str(storeSku.SkuID))
|
mainOrderDetail, failedList2 := loadMainProductId(api, storeSku, storeID, syncType)
|
||||||
if err != nil {
|
if len(failedList2) > 0 {
|
||||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
failedList = append(failedList, failedList2...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if mainOrderDetail.MainProductId != 0 {
|
mainIdInt = mainOrderDetail.MainProductId
|
||||||
mainIdInt = mainOrderDetail.MainProductId
|
|
||||||
} else {
|
|
||||||
mainIdInt = mainOrderDetail.ProductId
|
|
||||||
}
|
|
||||||
|
|
||||||
storeSku.VendorMainId = utils.Int64ToStr(mainIdInt)
|
storeSku.VendorMainId = utils.Int64ToStr(mainIdInt)
|
||||||
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainIdInt), storeDetail.VendorOrgCode, "更新发现不存在", model.ThingTypeSku, 0); err != nil {
|
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)
|
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||||
@@ -448,6 +437,30 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
return failedList, err
|
return failedList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadMainProductId(api *tiktokShop.API, storeSku *dao.StoreSkuSyncInfo, storeID int, syncType string) (mainOrderDetail *product_detail_response.ProductDetailData, failedList []*partner.StoreSkuInfoWithErr) {
|
||||||
|
// 这有可能获取的值主商品也有可能是子商品,我们需要的是主商品id和状态
|
||||||
|
mainOrderDetail, err := api.GetSkuDetailLocalID("", utils.Int2Str(storeSku.SkuID))
|
||||||
|
if err != nil {
|
||||||
|
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if mainOrderDetail.MainProductId != 0 { // 子商品时,获取主商品id和状态
|
||||||
|
mainOrderDetail, err = api.GetSkuDetail(utils.Int64ToStr(mainOrderDetail.MainProductId), "")
|
||||||
|
if err != nil {
|
||||||
|
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if mainOrderDetail == nil || mainOrderDetail.Status == 2 { // 主商品为空或已删除状态时,需要创建
|
||||||
|
mainOrderDetail.MainProductId = 0
|
||||||
|
} else {
|
||||||
|
mainOrderDetail.MainProductId = mainOrderDetail.ProductId
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mainOrderDetail.MainProductId = mainOrderDetail.ProductId // 主商品
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func checkNameLenght(name string) string {
|
func checkNameLenght(name string) string {
|
||||||
var chinesLen int // 中文
|
var chinesLen int // 中文
|
||||||
var punctZh int // 中文标点
|
var punctZh int // 中文标点
|
||||||
|
|||||||
Reference in New Issue
Block a user