From 20dde2d1135e97319908d50a85c6eb02bfc09e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 8 Nov 2022 14:36:41 +0800 Subject: [PATCH] 1 --- business/model/dao/sku.go | 4 +++ .../purchase/tiktok_store/store_sku2_utils.go | 35 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/business/model/dao/sku.go b/business/model/dao/sku.go index 676d511d4..2c0033b68 100644 --- a/business/model/dao/sku.go +++ b/business/model/dao/sku.go @@ -167,6 +167,10 @@ func GetSkus(db *DaoDB, skuIDs, nameIDs, statuss, catIDs []int, eclpIDs []string return nil, err } +func UpdateSkuNameTiktokAttr(db *DaoDB, id int64, attr string) { + sql := ` UPDATE sku_name SET tiktok_attribute = ? WHERE id = ? ` + ExecuteSQL(db, sql, []interface{}{attr, id}...) +} func GetSkuNames(db *DaoDB, nameIDs []int, upcs []string, name string, isExd bool) (skuNameList []*model.SkuName, err error) { sql := ` SELECT t1.* diff --git a/business/partner/purchase/tiktok_store/store_sku2_utils.go b/business/partner/purchase/tiktok_store/store_sku2_utils.go index 6942182db..b3cc81924 100644 --- a/business/partner/purchase/tiktok_store/store_sku2_utils.go +++ b/business/partner/purchase/tiktok_store/store_sku2_utils.go @@ -171,14 +171,44 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI // spec_prices param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku) - param.ProductFormatNew = storeSku.TiktokAttribute + // 获取商品的属性 + if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" { + categoryList, err := api.GetCatePropertyV2(param.CategoryLeafId) + if err != nil { + return nil, err + } + categoryMap := make(map[string][]map[string]interface{}) + for _, v := range categoryList.Data.Data { + if v.Required == model.YES { + options := make([]map[string]interface{}, 0) + if v.PropertyName == "品牌" { + options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 297375059, "diy_type": v.DiyType}) + categoryMap[utils.Int64ToStr(v.PropertyId)] = options + } else if v.PropertyName == "产地" { + options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 13850, "diy_type": v.DiyType}) + categoryMap[utils.Int64ToStr(v.PropertyId)] = options + } else if len(options) == 0 { + options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 0, "diy_type": v.DiyType}) + categoryMap[utils.Int64ToStr(v.PropertyId)] = options + } else { + options = append(options, map[string]interface{}{"name": v.PropertyName, "value": v.Options[0].Value, "diy_type": v.DiyType}) + categoryMap[utils.Int64ToStr(v.PropertyId)] = options + } + } + continue + } + param.ProductFormatNew = utils.Format4Output(categoryMap, false) + dao.UpdateSkuNameTiktokAttr(dao.GetDB(), int64(storeSku.NameID), param.ProductFormatNew) + } else { + param.ProductFormatNew = storeSku.TiktokAttribute + } // 获取品牌 //param.StandardBrandId, err = api.GetSkuBrand(param.CategoryLeafId) //if err != nil { // return nil, err //} - param.StandardBrandId = 596120136 // 默认品牌 + param.StandardBrandId = 297375059 // 默认品牌 // 根据本地商品id获取线上商品是否存在,存在则只创建子商品 var tiktokResultProductId int64 = 0 @@ -247,7 +277,6 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI } storeSku.VendorSkuID = utils.Int64ToStr(tiktokResultChildren.ProductId) // 子商品主id storeSku.VendorMainId = utils.Int64ToStr(tiktokResultProductId) // 商品主id - } } else { syncType = "更新商品"