This commit is contained in:
邹宗楠
2023-01-06 13:37:41 +08:00
parent 21bf72af71
commit a1584a6d72
4 changed files with 63 additions and 7 deletions

View File

@@ -1037,7 +1037,6 @@ func GetOrders(db *DaoDB, ids []int64, isIncludeSku, isIncludeFake bool, fromDat
if len(vendorIDs) > 0 {
sqlWhere += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
sqlParams = append(sqlParams, vendorIDs)
//globals.SugarLogger.Debugf("sqlParams vendorIDs================%d", vendorIDs)
}
}
if userID != "" {

View File

@@ -45,8 +45,21 @@ func CreateThingMap(thingId int64, vendorThingID, appOrgCode, err string, thingT
return CreateEntity(GetDB(), thingMap)
}
func UpdateThingMap(thingMap *model.ThingMap) error {
_, err := UpdateEntity(GetDB(), thingMap, "ID")
func UpdateThingMap(db *DaoDB, syncStatus int8, vendorThingId string, thingId int, vendorId int, vendorOrgCode string) error {
sql := `
UPDATE thing_map t1
SET t1.sync_status = ?,t1.vendor_thing_id = ?
WHERE t1.deleted_at = ? AND t1.thing_id = ? AND t1.vendor_id = ? AND t1.vendor_org_code = ?
`
sqlParams := []interface{}{
syncStatus,
vendorThingId,
utils.DefaultTimeValue,
thingId,
vendorId,
vendorOrgCode,
}
_, err := ExecuteSQL(db, sql, sqlParams...)
return err
}
@@ -65,7 +78,6 @@ func GetThingToTiktokMapList(db *DaoDB, vendorId int, thingId int64, vendorOrgCo
}
err = GetRows(db, &cats, sql, sqlParams...)
return cats, err
}

View File

@@ -9,6 +9,12 @@ const (
ThingTypeOrder = 6 // 同步订单
)
const (
ThingTypeSyncSuccess = 0 // 主商品创建成功
ThingTypeSyncFail = 2 // 主商品创建失败
ThingTypeSyncing = 3 // 主商品创建中
)
type ThingMap struct {
ModelIDCULD

View File

@@ -28,6 +28,7 @@ import (
"git.rosy.net.cn/jx-callback/globals"
"math/rand"
"strings"
"time"
"unicode"
)
@@ -147,7 +148,10 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
if len(localThing) == 0 {
//if mainProductId == 0 {
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(time.Now().Unix()), storeDetail.VendorOrgCode, "本地不存在,线上也不存在", model.ThingTypeSku, model.ThingTypeSyncing); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
param, failedList2 := makeMainProductSku(db, api, storeSku, storeDetail, storeID, vendorStoreID, syncType)
if len(failedList2) != 0 {
failedList = append(failedList, failedList2...)
@@ -155,10 +159,15 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
}
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
if err != nil {
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(tiktokResult.ProductId), storeDetail.VendorOrgCode, "本地不存在,线上也不存在", model.ThingTypeSku, 0)
var attrId []string
for _, v := range tiktokResult.Sku {
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
@@ -171,7 +180,37 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
storeSku.VendorSonSkuID = utils.Int2Str(storeSku.SkuID) // 还没同步子商品
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("只创建了主商品,没创建子商品"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
} else {
} else if localThing[0].SyncStatus == model.ThingTypeSyncFail { // 同步失败在重新创建
param, failedList2 := makeMainProductSku(db, api, storeSku, storeDetail, storeID, vendorStoreID, syncType)
if len(failedList2) != 0 {
failedList = append(failedList, failedList2...)
continue
}
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
if err != nil {
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
continue
}
var attrId []string
for _, v := range tiktokResult.Sku {
attrId = append(attrId, utils.Int64ToStr(v.SkuId))
}
mainProductId = tiktokResult.ProductId
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
storeSku.VendorMainId = utils.Int64ToStr(tiktokResult.ProductId)
storeSku.VendorSkuAttrId = strings.Join(attrId, ",") // 属性id skuID
storeSku.VendorSonSkuID = utils.Int2Str(storeSku.SkuID) // 还没同步子商品
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("只创建了主商品,没创建子商品"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
} else if localThing[0].SyncStatus == model.ThingTypeSyncing {
continue
} else if localThing[0].SyncStatus == model.ThingTypeSyncSuccess {
// 主商品存在,直接同步子商品
childrenProductId, err := api.CreateSubProduct(utils.Str2Int64(localThing[0].VendorThingID), utils.Str2Int64(vendorStoreID))
if err != nil && strings.Contains(err.Error(), "2010004") { // 2010004:主商品非在线审核通过状态,不允许绑定子商品