Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop
This commit is contained in:
@@ -496,6 +496,7 @@ func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, v
|
||||
//
|
||||
func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag int, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8
|
||||
globals.SugarLogger.Debugf("============2")
|
||||
|
||||
funcParam := func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||
|
||||
@@ -103,6 +103,7 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
|
||||
}
|
||||
}
|
||||
if model.IsSyncStatusDelete(catInfo.CatSyncStatus) { // 删除 4
|
||||
globals.SugarLogger.Debugf("============5:删除")
|
||||
if model.IsSyncStatusDelete(catInfo.CatSyncStatus) && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) {
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level)
|
||||
if err != nil && handler.IsErrCategoryNotExist(err) {
|
||||
@@ -112,6 +113,7 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
|
||||
}
|
||||
}
|
||||
} else if model.IsSyncStatusNew(catInfo.CatSyncStatus) { // 新增 2
|
||||
globals.SugarLogger.Debugf("============6:新增")
|
||||
err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo)
|
||||
if err != nil && handler.IsErrCategoryExist(err) {
|
||||
if cat, err2 := handler.GetStoreCategory(ctx, storeID, vendorStoreID, catInfo.Name); err2 == nil {
|
||||
@@ -129,6 +131,7 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
|
||||
// }
|
||||
}
|
||||
} else if model.IsSyncStatusUpdate(catInfo.CatSyncStatus) { // 修改 1
|
||||
globals.SugarLogger.Debugf("============7:修改")
|
||||
err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo)
|
||||
if err == nil {
|
||||
updateFields = append(updateFields, idFieldName)
|
||||
@@ -173,6 +176,7 @@ func SyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
|
||||
}
|
||||
|
||||
func SyncStoreSkuNew2(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag int, vendorID, storeID int, vendorStoreID, vendorOrgCode string, nameIDs, skuIDs, excludeSkuIDs []int, useVendorPriceDirectly, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("============4")
|
||||
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
if singleStoreHandler != nil { // 本地创建商品分类
|
||||
if err = CreateStoreCategoryByStoreSku(ctx, vendorID, storeID, vendorStoreID, nameIDs, skuIDs); err != nil {
|
||||
@@ -275,6 +279,9 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
|
||||
if inSku.VendorSkuAttrId != "" {
|
||||
outSku.VendorSkuAttrId = inSku.VendorSkuAttrId
|
||||
}
|
||||
if inSku.VendorSonSkuID != "" {
|
||||
outSku.VendorSonSkuID = inSku.VendorSonSkuID
|
||||
}
|
||||
return outSku
|
||||
}
|
||||
|
||||
@@ -375,6 +382,9 @@ func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item
|
||||
if sku.VendorSkuAttrId != "" {
|
||||
kvs["VendorSkuAttrId"] = sku.VendorSkuAttrId
|
||||
}
|
||||
if sku.VendorSonSkuID != "" {
|
||||
kvs["VendorSonSkuID"] = sku.VendorSonSkuID
|
||||
}
|
||||
storeSku := &model.StoreSkuBind{}
|
||||
storeSku.ID = sku.BindID
|
||||
item = &dao.KVUpdateItem{
|
||||
@@ -671,6 +681,14 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
|
||||
// }
|
||||
}
|
||||
|
||||
globals.SugarLogger.Debugf("============createList := %s", utils.Format4Output(createList, false))
|
||||
globals.SugarLogger.Debugf("============updateList := %s", utils.Format4Output(updateList, false))
|
||||
globals.SugarLogger.Debugf("============deleteList := %s", utils.Format4Output(deleteList, false))
|
||||
globals.SugarLogger.Debugf("============stockList := %s", utils.Format4Output(stockList, false))
|
||||
globals.SugarLogger.Debugf("============onlineList := %s", utils.Format4Output(onlineList, false))
|
||||
globals.SugarLogger.Debugf("============offlineList := %s", utils.Format4Output(offlineList, false))
|
||||
globals.SugarLogger.Debugf("============priceList := %s", utils.Format4Output(priceList, false))
|
||||
|
||||
task := tasksch.NewParallelTask("syncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError2), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
|
||||
@@ -75,9 +75,10 @@ type StoreSkuSyncInfo struct {
|
||||
// 平台相关的store sku信息
|
||||
StoreSkuStatus int // 库存状态
|
||||
SkuSyncStatus int8 // 锁定状态
|
||||
VendorSkuID string `orm:"column(vendor_sku_id)"`
|
||||
VendorSkuAttrId string `orm:"column(vendor_sku_attr_id)"`
|
||||
VendorMainId string `orm:"column(vendor_main_id)"`
|
||||
VendorSkuID string `orm:"column(vendor_sku_id)"` // 子商品id
|
||||
VendorSonSkuID string `orm:"column(vendor_son_sku_id)"` // 子商品skuid
|
||||
VendorSkuAttrId string `orm:"column(vendor_sku_attr_id)"` // 主商品skuid
|
||||
VendorMainId string `orm:"column(vendor_main_id)"` // 主商品id
|
||||
JdsWareID int64 `orm:"column(jds_ware_id)" json:"jdsWareID"`
|
||||
BindDeletedAt time.Time `orm:"type(datetime)" json:"bindDeletedAt"`
|
||||
|
||||
@@ -566,7 +567,7 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo
|
||||
SELECT
|
||||
t14.vendor_id, t14.vendor_org_code,
|
||||
t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status,
|
||||
%s vendor_sku_id, t1.%s_sync_status sku_sync_status, t1.%s_price vendor_price, t1.%s_lock_time lock_time,t1.vendor_sku_attr_id,t1.vendor_main_id,
|
||||
%s vendor_sku_id, t1.%s_sync_status sku_sync_status, t1.%s_price vendor_price, t1.%s_lock_time lock_time,t1.vendor_son_sku_id,t1.vendor_sku_attr_id,t1.vendor_main_id,
|
||||
t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end, t1.jds_ware_id, t1.stock, t1.mt_ladder_box_price,
|
||||
t2.*,
|
||||
t3.id name_id, t3.prefix, t3.name, t3.unit, t3.upc, t3.status name_status, t3.category_id name_category_id, t3.yb_name_suffix,t3.tiktok_attribute,
|
||||
@@ -793,6 +794,7 @@ func GetStoreSkuPriceAndWeight(db *DaoDB, vendorStoreID string, vendorID int, ve
|
||||
|
||||
// 这个函数之前是要设置没有删除或同步标志不为0的,会导致将同步标志不为0且删除了的把标志去掉,现在改为只设置没有删除的
|
||||
func SetStoreSkuSyncStatus(db *DaoDB, vendorID int, storeIDs []int, skuIDs []int, syncStatus int) (num int64, err error) {
|
||||
globals.SugarLogger.Debugf("============3")
|
||||
isSingleStorePF := model.MultiStoresVendorMap[vendorID] != 1
|
||||
fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
|
||||
sql := `
|
||||
|
||||
@@ -115,13 +115,14 @@ type StoreSkuBind struct {
|
||||
// ElmID int64 `orm:"column(elm_id);index"`
|
||||
MtwmID int64 `orm:"column(mtwm_id);index"`
|
||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||
DdID int64 `orm:"column(dd_id);index"` // 子品主商品id
|
||||
YbID int64 `orm:"column(yb_id);index"`
|
||||
JdsID int64 `orm:"column(jds_id);index"`
|
||||
JdsWareID int64 `orm:"column(jds_ware_id)"`
|
||||
//GmID string `orm:"column(gm_id)"`
|
||||
// WscID int64 `orm:"column(wsc_id);index"` // 表示微盟skuId
|
||||
// WscID2 int64 `orm:"column(wsc_id2);index"` // 表示微盟goodsId
|
||||
DdID int64 `orm:"column(dd_id);index"` // 子品主商品id
|
||||
VendorSonSkuID string `orm:"column(vendor_son_sku_id)"` // 子商品skuid
|
||||
VendorSkuAttrId string `orm:"column(vendor_sku_attr_id)"` // 抖音需要,主品skuid
|
||||
VendorMainId string `orm:"column(vendor_Main_id)"` // 抖音需要,商品主id
|
||||
|
||||
|
||||
@@ -56,8 +56,9 @@ type StoreSkuInfo struct {
|
||||
SpecUnit string `json:"specUnit"`
|
||||
SpecQuality float32 `json:"specQuality"`
|
||||
|
||||
VendorMainId string `json:"vendorMainId"`
|
||||
VendorSkuAttrId string `json:"vendorSkuAttrId"`
|
||||
VendorMainId string `json:"vendorMainId"` // 主商品id
|
||||
VendorSkuAttrId string `json:"vendorSkuAttrId"` //主商品sku_id
|
||||
VendorSonSkuID string `json:"vendorSonSkuID"` // 子商品skuid
|
||||
}
|
||||
|
||||
type StoreSkuInfoWithErr struct {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -117,10 +116,8 @@ func (c *PurchaseHandler) onAfsOrderMsg(msgId string, msg interface{}) (retVal *
|
||||
}
|
||||
if msgId == tiktokShop.CallbackUpdateRefundOrderMsgTagId {
|
||||
_, err = dao.DeleteEntity(dao.GetDB(), afsOrder, "VendorOrderID", "VendorID")
|
||||
globals.SugarLogger.Debugf("err1============== %s", err.Error())
|
||||
afsOrder.Skus[0].VendorOrderID = afsOrder.VendorOrderID
|
||||
_, err = dao.DeleteEntity(dao.GetDB(), afsOrder.Skus[0], "VendorOrderID")
|
||||
globals.SugarLogger.Debugf("err2============== %s", err.Error())
|
||||
}
|
||||
err = partner.CurOrderManager.OnAfsOrderNew(afsOrder, orderStatus)
|
||||
}
|
||||
|
||||
@@ -281,33 +281,22 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
|
||||
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
api := getAPI(vendorOrgCode, storeID, vendorStoreID)
|
||||
for _, v := range storeSkuList {
|
||||
//param := &product_editV2_request.ProductEditV2Param{}
|
||||
//param.ProductId = utils.Str2Int64(v.VendorSkuID)
|
||||
//param.Specs = "净重|" + fmt.Sprintf("%f", v.SpecQuality) + v.SpecUnit
|
||||
//
|
||||
//skuSize := make([]*tiktokShop.SpecDetailList, 0, 0)
|
||||
//detail1 := strings.Split(param.Specs, "^")
|
||||
//name1 := strings.Split(strings.Split(detail1[0], "|")[1], ",")
|
||||
//for i := 0; i < len(name1); i++ {
|
||||
// sku := &tiktokShop.SpecDetailList{
|
||||
// SpecDetailName1: name1[i],
|
||||
// StockNum: v.Stock,
|
||||
// Price: int(v.VendorPrice),
|
||||
// Code: utils.Int2Str(v.SkuID),
|
||||
// StepStockNum: 0,
|
||||
// SupplierID: "",
|
||||
// OuterSkuID: utils.Int2Str(v.NameID),
|
||||
// DeliveryInfos: []*tiktokShop.DeliveryInfos{
|
||||
// {InfoType: "weight", InfoUnit: v.SpecUnit, InfoValue: fmt.Sprintf("%f", v.SpecQuality)},
|
||||
// },
|
||||
// }
|
||||
// skuSize = append(skuSize, sku)
|
||||
//}
|
||||
//data, _ := json.Marshal(skuSize)
|
||||
//param.SpecPrices = string(data)
|
||||
err := api.EditPrice(&sku_editPrice_request.SkuEditPriceParam{
|
||||
// 更新主品
|
||||
err = api.EditPrice(&sku_editPrice_request.SkuEditPriceParam{
|
||||
Price: v.VendorPrice,
|
||||
SkuId: utils.Str2Int64(v.VendorSkuAttrId),
|
||||
ProductId: utils.Str2Int64(v.VendorMainId),
|
||||
})
|
||||
if err != nil {
|
||||
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "更新主品价格异常")...)
|
||||
} else {
|
||||
failedList = append(failedList, putils.GetErrMsg2FailedSingleList(v, err, storeID, model.VendorChineseNames[model.VendorIDDD], "更新主品价格正常")...)
|
||||
}
|
||||
|
||||
// 更新子品
|
||||
err = api.EditPrice(&sku_editPrice_request.SkuEditPriceParam{
|
||||
Price: v.VendorPrice,
|
||||
SkuId: utils.Str2Int64(v.VendorSonSkuID),
|
||||
ProductId: utils.Str2Int64(v.VendorSkuID),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -152,7 +152,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
param.Pic = img
|
||||
// 商品详情图
|
||||
if storeSku.DescImg == "" {
|
||||
param.Description = img
|
||||
param.Description = strings.Split(img, ",")[0]
|
||||
} else {
|
||||
img2, err := GetTiktokImgList(utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg)
|
||||
if err != nil {
|
||||
@@ -275,6 +275,11 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
|
||||
continue
|
||||
}
|
||||
var attrId2 []string
|
||||
for _, v := range tiktokResultChildren.Sku {
|
||||
attrId2 = append(attrId2, utils.Int64ToStr(v.SkuId))
|
||||
}
|
||||
storeSku.VendorSonSkuID = strings.Join(attrId2, ",") // 属性id skuID
|
||||
storeSku.VendorSkuID = utils.Int64ToStr(tiktokResultChildren.ProductId) // 子商品主id
|
||||
storeSku.VendorMainId = utils.Int64ToStr(tiktokResultProductId) // 商品主id
|
||||
}
|
||||
@@ -307,11 +312,15 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
}
|
||||
param.Pic = img
|
||||
// 商品详情图
|
||||
img2, err := GetTiktokImgList(utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if storeSku.DescImg == "" {
|
||||
param.Description = strings.Split(img, ",")[0]
|
||||
} else {
|
||||
img2, err := GetTiktokImgList(utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
param.Description = img2
|
||||
}
|
||||
param.Description = img2
|
||||
|
||||
// weight_unit 目前抖音只支持g和kg两种
|
||||
switch storeSku.Unit {
|
||||
@@ -321,16 +330,41 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
param.WeightUnit = tiktokShop.WeightUint_G
|
||||
}
|
||||
|
||||
// spec_prices
|
||||
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, utils.Str2Int64(storeSku.VendorSkuID), storeSku)
|
||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
||||
// 获取商品的属性
|
||||
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": 789194134, "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
|
||||
}
|
||||
|
||||
// 获取品牌
|
||||
//brandID, err := api.GetSkuBrand(param.CategoryLeafId)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//param.StandardBrandId = brandID
|
||||
param.StandardBrandId = 789194134 // 默认品牌京西菜市
|
||||
|
||||
//tiktokResult, err := api.EditStoreCommodity(param) // 创建主商品
|
||||
//if err != nil {
|
||||
@@ -356,7 +390,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
|
||||
continue
|
||||
}
|
||||
storeSku.VendorSkuID = storeSku.VendorSkuID
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/panjf2000/ants"
|
||||
"io"
|
||||
"sync"
|
||||
@@ -38,6 +39,7 @@ func (c *SyncController) SyncStoresSkus() {
|
||||
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs, params.VendorIDs, &vendorIDs); err != nil {
|
||||
return retVal, "", err
|
||||
}
|
||||
globals.SugarLogger.Debugf("============1")
|
||||
retVal, err = cms.CurVendorSync.SyncStoresSkus(params.Ctx, nil, 0, db, vendorIDs, storeIDs, skuIDs, params.IsForce, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user