From fd61639e7f2fee20d4143e7d15aa6f997d4bc432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 20 Dec 2022 17:28:13 +0800 Subject: [PATCH] 1 --- .../purchase/tiktok_store/store_sku2_utils.go | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/business/partner/purchase/tiktok_store/store_sku2_utils.go b/business/partner/purchase/tiktok_store/store_sku2_utils.go index ac7de8b7c..c72a1b4ec 100644 --- a/business/partner/purchase/tiktok_store/store_sku2_utils.go +++ b/business/partner/purchase/tiktok_store/store_sku2_utils.go @@ -29,6 +29,7 @@ import ( "math/rand" "strings" "time" + "unicode" ) type MainSku struct { @@ -156,7 +157,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI if len(param.Name) < 23 { // 中文字符一个汉字三个长度符号/数字/字母两个长度,商品名称不能大于 param.Name += "【同城配送】" } else if len(param.Name) > 90 { // 抖音最大60个字符,三十个汉字 - param.Name = param.Name[0:90] + param.Name = checkNameLenght(param.Name) } // 获取上传图,商品轮播图 @@ -367,7 +368,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI if len(param.Name) < 23 { // 中文字符一个汉字三个长度符号/数字/字母两个长度,商品名称不能大于 param.Name += "【同城配送】" } else if len(param.Name) > 90 { // 抖音最大60个字符,三十个汉字 - param.Name = param.Name[0:90] + param.Name = checkNameLenght(param.Name) } // 获取上传图,商品轮播图 @@ -410,6 +411,52 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI return failedList, err } +func checkNameLenght(name string) string { + var chinesLen int // 中文 + var punctZh int // 中文标点 + var punctEn int // 英文标点 + var punctAZ int // 字母 + var punctNum int // 字母 + var spance int // 空格 + for _, v := range name { + if unicode.Is(unicode.Han, v) { // 中文 + chinesLen++ + continue + } + if unicode.IsPunct(v) { + if v >= 1000 { // 中文字符 + fmt.Println(v) + punctZh++ + } else { + punctEn++ // 英文字符 + } + continue + } + if unicode.IsLetter(v) { // 字母 + punctAZ++ + continue + } + if unicode.IsNumber(v) { // 数字 + punctNum++ + continue + } + if unicode.IsSpace(v) { // 空格 + spance++ + continue + } + } + + maxLen := (chinesLen * 2) + (punctZh * 2) + punctEn + punctAZ + punctNum + spance + if maxLen > 60 { // 美团最多支持30个汉字长度 + index := strings.LastIndex(name, " ") + if index != 0 { + return name[0:index] + } else { + return name[0 : len(name)-(maxLen-60)*3] + } + } + return name +} func upDateChildrenPriceStockLaunch(api *tiktokShop.API, storeSku *dao.StoreSkuSyncInfo, childrenProductId int64, vendorStoreID, syncType string) (failedList []*partner.StoreSkuInfoWithErr) { skuId, failed := getProductSkuID(api, storeSku, syncType, childrenProductId) if skuId == 0 || len(failed) > 0 {