1
This commit is contained in:
@@ -2,6 +2,7 @@ package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/tiktok_store"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -331,18 +332,19 @@ func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*mode
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
errList := errlist.New()
|
||||
for k, v := range vendorThingList {
|
||||
for _, v := range vendorThingList {
|
||||
thingMap := &model.ThingMap{
|
||||
ThingID: v,
|
||||
ThingID: v.LocalSkuId,
|
||||
ThingType: thingType,
|
||||
VendorID: model.VendorIDDD,
|
||||
VendorOrgCode: appOrgCode,
|
||||
VendorThingID: k,
|
||||
VendorThingID: v.MainId,
|
||||
Remark: v.SkuAttrId,
|
||||
}
|
||||
if thingType == model.ThingTypeCategory && !vendorFlag {
|
||||
syncFlag = 0
|
||||
|
||||
@@ -27,6 +27,37 @@ func GetThingMapList(db *DaoDB, thingType int, vendorIDs, thingIDs []int, vendor
|
||||
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) {
|
||||
thingMapList, err := GetThingMapList(db, thingType, vendorIDs, thingIDs, nil)
|
||||
if err == nil {
|
||||
|
||||
@@ -37,12 +37,18 @@ type MainSku struct {
|
||||
PageSize int64 `json:"pageSize"`
|
||||
}
|
||||
|
||||
type TiktokIdAndLocalSkuId struct {
|
||||
MainId string `json:"mainId"` // 商城商品主id
|
||||
LocalSkuId int64 `json:"localSkuId"` // 本地商品id
|
||||
SkuAttrId string `json:"skuAttrId"` // 主商品属性id
|
||||
}
|
||||
|
||||
// QueryAllMainSkuList 获取商户账号总的商品,主商品条数.
|
||||
func QueryAllMainSkuList(appOrgCode string, param *MainSku) (map[string]int64, error) {
|
||||
func QueryAllMainSkuList(appOrgCode string, param *MainSku) ([]*TiktokIdAndLocalSkuId, error) {
|
||||
var (
|
||||
page int64 = 1
|
||||
pageSize int64 = 100
|
||||
tiktokIdAndLocalSkuId = make(map[string]int64, 0)
|
||||
tiktokIdAndLocalSkuId = make([]*TiktokIdAndLocalSkuId, 0, 0)
|
||||
api = getAPI(appOrgCode, 0, "")
|
||||
)
|
||||
if param.Page == 0 {
|
||||
@@ -59,24 +65,26 @@ func QueryAllMainSkuList(appOrgCode string, param *MainSku) (map[string]int64, e
|
||||
}
|
||||
for _, v := range mainSkuList.Data {
|
||||
var localSkuId int64 = 0
|
||||
if v.OutProductId != 0 {
|
||||
localSkuId = v.ProductId
|
||||
} else if v.OuterProductId != "" {
|
||||
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
|
||||
}
|
||||
skuDetail, err := api.GetSkuDetail(utils.Int64ToStr(v.ProductId), "")
|
||||
if err != nil {
|
||||
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 {
|
||||
@@ -169,12 +177,13 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
param.StandardBrandId = 596120136
|
||||
param.StandardBrandId = 596120136 // 默认品牌
|
||||
|
||||
// 根据本地商品id获取线上商品是否存在,存在则只创建子商品
|
||||
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) // 创建主商品
|
||||
if err != nil {
|
||||
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))
|
||||
}
|
||||
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
|
||||
dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(tiktokResult.ProductId), storeDetail.VendorOrgCode, storeSku.VendorSkuAttrId)
|
||||
} else {
|
||||
storeSku.VendorMainId = utils.Int64ToStr(skuMain.ProductId)
|
||||
var attrId []string
|
||||
for _, v := range skuMain.SpecPrices {
|
||||
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
|
||||
}
|
||||
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
|
||||
tiktokResultProductId = skuMain.ProductId
|
||||
storeSku.VendorMainId = localThing[0].VendorThingID
|
||||
storeSku.VendorSkuAttrId = localThing[0].Remark // 属性id skuID
|
||||
tiktokResultProductId = utils.Str2Int64(localThing[0].VendorThingID)
|
||||
}
|
||||
|
||||
// 创建子商品
|
||||
|
||||
Reference in New Issue
Block a user