This commit is contained in:
邹宗楠
2022-10-27 15:07:09 +08:00
parent 8f42a925a9
commit 5a4fe56de7
3 changed files with 72 additions and 33 deletions

View File

@@ -2,6 +2,7 @@ package cms
import ( import (
"fmt" "fmt"
"git.rosy.net.cn/jx-callback/business/partner/purchase/tiktok_store"
"strings" "strings"
"time" "time"
@@ -331,18 +332,19 @@ func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*mode
return err return err
} }
func OnCreateThing2Tiktok(ctx *jxcontext.Context, db *dao.DaoDB, appOrgCode string, vendorThingList map[string]int64, thingType, syncFlag int8, vendorFlag bool) (err error) { func OnCreateThing2Tiktok(ctx *jxcontext.Context, db *dao.DaoDB, appOrgCode string, vendorThingList []*tiktok_store.TiktokIdAndLocalSkuId, thingType, syncFlag int8, vendorFlag bool) (err error) {
if thingType == model.ThingTypeSkuName { if thingType == model.ThingTypeSkuName {
return nil return nil
} }
errList := errlist.New() errList := errlist.New()
for k, v := range vendorThingList { for _, v := range vendorThingList {
thingMap := &model.ThingMap{ thingMap := &model.ThingMap{
ThingID: v, ThingID: v.LocalSkuId,
ThingType: thingType, ThingType: thingType,
VendorID: model.VendorIDDD, VendorID: model.VendorIDDD,
VendorOrgCode: appOrgCode, VendorOrgCode: appOrgCode,
VendorThingID: k, VendorThingID: v.MainId,
Remark: v.SkuAttrId,
} }
if thingType == model.ThingTypeCategory && !vendorFlag { if thingType == model.ThingTypeCategory && !vendorFlag {
syncFlag = 0 syncFlag = 0

View File

@@ -27,6 +27,37 @@ func GetThingMapList(db *DaoDB, thingType int, vendorIDs, thingIDs []int, vendor
return cats, err return cats, err
} }
func CreateThingMap(thingId int64, vendorThingID, appOrgCode, skuAttrId string) error {
thingMap := &model.ThingMap{
ThingID: thingId,
ThingType: model.ThingTypeSku,
VendorID: model.VendorIDDD,
VendorOrgCode: appOrgCode,
VendorThingID: vendorThingID,
Remark: skuAttrId,
SyncStatus: 0,
}
WrapAddIDCULDEntity(thingMap, "jxadmin")
return CreateEntity(GetDB(), thingMap)
}
// GetThingToTiktokMapList 抖店获取同步类型
func GetThingToTiktokMapList(db *DaoDB, vendorId int, thingId int64) (cats []*model.ThingMap, err error) {
sql := `
SELECT t1.*
FROM thing_map t1
WHERE thing_id = ? AND vendor_id = ? t1.deleted_at = ?
`
sqlParams := []interface{}{
vendorId, thingId,
utils.DefaultTimeValue,
}
err = GetRows(db, &cats, sql, sqlParams...)
return cats, err
}
func GetThingMapMap(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (thingMapMap map[int64][]*model.ThingMap, err error) { func GetThingMapMap(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (thingMapMap map[int64][]*model.ThingMap, err error) {
thingMapList, err := GetThingMapList(db, thingType, vendorIDs, thingIDs, nil) thingMapList, err := GetThingMapList(db, thingType, vendorIDs, thingIDs, nil)
if err == nil { if err == nil {

View File

@@ -37,12 +37,18 @@ type MainSku struct {
PageSize int64 `json:"pageSize"` PageSize int64 `json:"pageSize"`
} }
type TiktokIdAndLocalSkuId struct {
MainId string `json:"mainId"` // 商城商品主id
LocalSkuId int64 `json:"localSkuId"` // 本地商品id
SkuAttrId string `json:"skuAttrId"` // 主商品属性id
}
// QueryAllMainSkuList 获取商户账号总的商品,主商品条数. // QueryAllMainSkuList 获取商户账号总的商品,主商品条数.
func QueryAllMainSkuList(appOrgCode string, param *MainSku) (map[string]int64, error) { func QueryAllMainSkuList(appOrgCode string, param *MainSku) ([]*TiktokIdAndLocalSkuId, error) {
var ( var (
page int64 = 1 page int64 = 1
pageSize int64 = 100 pageSize int64 = 100
tiktokIdAndLocalSkuId = make(map[string]int64, 0) tiktokIdAndLocalSkuId = make([]*TiktokIdAndLocalSkuId, 0, 0)
api = getAPI(appOrgCode, 0, "") api = getAPI(appOrgCode, 0, "")
) )
if param.Page == 0 { if param.Page == 0 {
@@ -59,24 +65,26 @@ func QueryAllMainSkuList(appOrgCode string, param *MainSku) (map[string]int64, e
} }
for _, v := range mainSkuList.Data { for _, v := range mainSkuList.Data {
var localSkuId int64 = 0 var localSkuId int64 = 0
if v.OutProductId != 0 { skuDetail, err := api.GetSkuDetail(utils.Int64ToStr(v.ProductId), "")
localSkuId = v.ProductId if err != nil {
} else if v.OuterProductId != "" { localSkuId = 0
localSkuId = utils.Str2Int64(v.OuterProductId)
} else {
skuDetail, err := api.GetSkuDetail(utils.Int64ToStr(v.ProductId), "")
if err != nil {
localSkuId = 0
}
if skuDetail.OutProductId != 0 {
localSkuId = skuDetail.OutProductId
} else if skuDetail.OuterProductId != "" {
localSkuId = utils.Str2Int64(skuDetail.OuterProductId)
} else {
localSkuId = 0
}
} }
tiktokIdAndLocalSkuId[utils.Int64ToStr(v.ProductId)] = localSkuId if skuDetail.OutProductId != 0 {
localSkuId = skuDetail.OutProductId
} else if skuDetail.OuterProductId != "" {
localSkuId = utils.Str2Int64(skuDetail.OuterProductId)
}
var attrId []string
for _, v := range skuDetail.SpecPrices {
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
}
tiktokIdAndLocalSkuId = append(tiktokIdAndLocalSkuId, &TiktokIdAndLocalSkuId{
MainId: skuDetail.ProductIdStr,
LocalSkuId: localSkuId,
SkuAttrId: strings.Join(attrId, ","),
})
} }
if int64(len(mainSkuList.Data)) < pageSize { if int64(len(mainSkuList.Data)) < pageSize {
@@ -169,12 +177,13 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
//if err != nil { //if err != nil {
// return nil, err // return nil, err
//} //}
param.StandardBrandId = 596120136 param.StandardBrandId = 596120136 // 默认品牌
// 根据本地商品id获取线上商品是否存在,存在则只创建子商品 // 根据本地商品id获取线上商品是否存在,存在则只创建子商品
var tiktokResultProductId int64 = 0 var tiktokResultProductId int64 = 0
skuMain, err2 := api.GetSkuDetailLocalID("", param.OuterProductId) // 获取本地存储映射关系
if err2 != nil { // 线上不存在创建 localThing, _ := dao.GetThingToTiktokMapList(dao.GetDB(), model.VendorIDDD, int64(storeSku.SkuID))
if len(localThing) == 0 { // 线上不存在创建
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品 tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品
if err != nil { if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
@@ -187,14 +196,11 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
attrId = append(attrId, utils.Int64ToStr(v.SkuId)) attrId = append(attrId, utils.Int64ToStr(v.SkuId))
} }
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(tiktokResult.ProductId), storeDetail.VendorOrgCode, storeSku.VendorSkuAttrId)
} else { } else {
storeSku.VendorMainId = utils.Int64ToStr(skuMain.ProductId) storeSku.VendorMainId = localThing[0].VendorThingID
var attrId []string storeSku.VendorSkuAttrId = localThing[0].Remark // 属性id skuID
for _, v := range skuMain.SpecPrices { tiktokResultProductId = utils.Str2Int64(localThing[0].VendorThingID)
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
}
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
tiktokResultProductId = skuMain.ProductId
} }
// 创建子商品 // 创建子商品