1
This commit is contained in:
@@ -1194,7 +1194,7 @@ func getJDCategoryLoadingLocalCategoryReflex(jdCategoryId, jdsCategoryID, ebaiCa
|
||||
if mtwmCategoryID == "" && cats[0].MtwmCategoryID != 0 {
|
||||
mtwmCategoryID = utils.Int64ToStr(cats[0].MtwmCategoryID)
|
||||
}
|
||||
if jxCategoryId == 0 {
|
||||
if jxCategoryId == 0 || jxCategoryId == 291 {
|
||||
jxCategoryId = cats[0].ID
|
||||
}
|
||||
}
|
||||
@@ -1260,30 +1260,54 @@ func updateOrCreateSkuVendorCategoryMap(db *dao.DaoDB, ctx *jxcontext.Context, n
|
||||
}
|
||||
} else {
|
||||
if payload["jdCategoryID"] != nil {
|
||||
jdCategoryId = payload["jdCategoryID"].(string)
|
||||
} else {
|
||||
jdCategoryId = getCategoryByName(payload["name"].(string))
|
||||
value, ok := payload["jdCategoryID"].(string)
|
||||
if ok && value != "" && value != "0" {
|
||||
jdCategoryId = payload["jdCategoryID"].(string)
|
||||
} else {
|
||||
jdCategoryId = getCategoryByName(payload["name"].(string))
|
||||
}
|
||||
}
|
||||
|
||||
if payload["jdsCategoryID"] != nil {
|
||||
jdsCategoryID = payload["jdsCategoryID"].(string)
|
||||
value, ok := payload["jdCategoryID"].(string)
|
||||
if ok && value != "" && value != "0" {
|
||||
jdsCategoryID = payload["jdsCategoryID"].(string)
|
||||
}
|
||||
}
|
||||
if payload["ebaiCategoryID"] != nil {
|
||||
ebaiCategoryID = payload["ebaiCategoryID"].(string)
|
||||
value, ok := payload["ebaiCategoryID"].(string)
|
||||
if ok && value != "" && value != "0" {
|
||||
ebaiCategoryID = payload["ebaiCategoryID"].(string)
|
||||
}
|
||||
}
|
||||
if payload["mtwmCategoryID"] != nil {
|
||||
mtwmCategoryID = payload["mtwmCategoryID"].(string)
|
||||
value, ok := payload["mtwmCategoryID"].(string)
|
||||
if ok && value != "" && value != "0" {
|
||||
mtwmCategoryID = payload["mtwmCategoryID"].(string)
|
||||
}
|
||||
}
|
||||
if payload["categoryID2"] != nil && !utils.IsNil(payload["categoryID2"]) {
|
||||
jxCategoryIDNumber, err := payload["categoryID2"].(json.Number).Int64()
|
||||
if err != nil {
|
||||
return false
|
||||
var jxCategoryIDNumber int64
|
||||
if value, ok := payload["categoryID2"].(string); ok && value != "" {
|
||||
jxCategoryIDNumber = utils.Str2Int64(value)
|
||||
}
|
||||
if value, ok := payload["categoryID2"].(int64); ok && value != 0 {
|
||||
jxCategoryIDNumber = value
|
||||
}
|
||||
if value, ok := payload["categoryID2"].(json.Number); ok && value != "" {
|
||||
jxCategoryIDNumber, _ = value.Int64()
|
||||
}
|
||||
jxCategoryID = int(jxCategoryIDNumber)
|
||||
} else if payload["categoryID"] != nil && !utils.IsNil(payload["categoryID"]) {
|
||||
jxCategoryIDNumber, err := payload["categoryID"].(json.Number).Int64()
|
||||
if err != nil {
|
||||
return false
|
||||
var jxCategoryIDNumber int64
|
||||
if value, ok := payload["categoryID"].(string); ok && value != "" {
|
||||
jxCategoryIDNumber = utils.Str2Int64(value)
|
||||
}
|
||||
if value, ok := payload["categoryID"].(int64); ok && value != 0 {
|
||||
jxCategoryIDNumber = value
|
||||
}
|
||||
if value, ok := payload["categoryID"].(json.Number); ok && value != "" {
|
||||
jxCategoryIDNumber, _ = value.Int64()
|
||||
}
|
||||
jxCategoryID = int(jxCategoryIDNumber)
|
||||
} else {
|
||||
@@ -1295,7 +1319,9 @@ func updateOrCreateSkuVendorCategoryMap(db *dao.DaoDB, ctx *jxcontext.Context, n
|
||||
}
|
||||
|
||||
if payload["ddCategoryID"] != nil {
|
||||
ddCategoryID = payload["ddCategoryID"].(string)
|
||||
if value, ok := payload["ddCategoryID"].(string); ok && value != "" {
|
||||
ddCategoryID = value
|
||||
}
|
||||
} else {
|
||||
ddCategoryID = getCategoryByImg(payload["descImg"].(string), payload["img"].(string), payload["img2"].(string), payload["img3"].(string), payload["img4"].(string), payload["img5"].(string))
|
||||
}
|
||||
@@ -1321,6 +1347,10 @@ func updateOrCreateSkuVendorCategoryMap(db *dao.DaoDB, ctx *jxcontext.Context, n
|
||||
updateOrCreate(model.VendorIDJD, nameID, jdCategoryId)
|
||||
flag = true
|
||||
}
|
||||
if jxCategoryID != 0 && jxCategoryID != 291 {
|
||||
dao.ExecuteSQL(dao.GetDB(), `UPDATE sku_name SET category_id = ? WHERE id = ?`, []interface{}{jxCategoryID, nameID}...)
|
||||
flag = true
|
||||
}
|
||||
|
||||
}
|
||||
return flag
|
||||
@@ -2331,18 +2361,34 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtwmCookieStr", model.ConfigTypeCookie, ""); err == nil {
|
||||
api.MtwmAPI.SetCookieWithStr(configs[0].Value)
|
||||
}
|
||||
result, err := api.MtwmAPI.GetStandardProductListWithCond(*skuName.Upc)
|
||||
if result != nil {
|
||||
productInfo.OriginalName = result.Name
|
||||
productInfo.OriginalSpec = result.Spec
|
||||
productInfo.Name = result.Name
|
||||
productInfo.SpecUnit = result.SpecUnit
|
||||
productInfo.Unit = result.Unit
|
||||
productInfo.SpecQuality = float32(result.SpecNew)
|
||||
productInfo.ImgList = strings.Split(result.Pic, ",")
|
||||
productInfo.Weight = float32(result.Weight)
|
||||
productInfo.BrandName = result.BrandNamePath
|
||||
|
||||
//result, err := api.MtwmAPI.GetStandardProductListWithCond(*skuName.Upc)
|
||||
//if result != nil {
|
||||
result, err := api.JdAPI.GetJdUpcCodeByName("", *skuName.Upc, 1, 5)
|
||||
if result != nil && len(result) != 0 {
|
||||
productInfo.OriginalName = result[0].OriginalName
|
||||
productInfo.OriginalSpec = result[0].OriginalSpec
|
||||
productInfo.Name = result[0].Name
|
||||
productInfo.SpecUnit = result[0].SpecUnit
|
||||
productInfo.Unit = result[0].Unit
|
||||
productInfo.SpecQuality = result[0].SpecQuality
|
||||
productInfo.ImgList = result[0].ImgList
|
||||
if result[0].Img != "" {
|
||||
productInfo.ImgList = append(productInfo.ImgList, productInfo.Img)
|
||||
}
|
||||
productInfo.Weight = result[0].Weight
|
||||
productInfo.BrandName = result[0].BrandName
|
||||
setImgs(skuName, productInfo.ImgList)
|
||||
// productInfo.OriginalName = result.Name
|
||||
// productInfo.OriginalSpec = result.Spec
|
||||
// productInfo.Name = result.Name
|
||||
// productInfo.SpecUnit = result.SpecUnit
|
||||
// productInfo.Unit = result.Unit
|
||||
// productInfo.SpecQuality = float32(result.SpecNew)
|
||||
// productInfo.ImgList = strings.Split(result.Pic, ",")
|
||||
// productInfo.Weight = float32(result.Weight)
|
||||
// productInfo.BrandName = result.BrandNamePath
|
||||
// setImgs(skuName, productInfo.ImgList)
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "美团cookie过期或者没查询到")}
|
||||
return retVal, err
|
||||
@@ -2505,16 +2551,48 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
skuName.Img5 = downloadURL
|
||||
}
|
||||
}
|
||||
|
||||
// 标品不存在规格是默认为包
|
||||
if (skuName.Unit == "份" && *skuName.Upc != "") || skuName.Unit == "" {
|
||||
skuName.Unit = "包"
|
||||
}
|
||||
if !isUpdate {
|
||||
_, err = AddSkuName(ctx, skuName, ctx.GetUserName())
|
||||
} else {
|
||||
var data []*model.SkuVendorCategoryMap
|
||||
err = dao.GetRows(db, &data, `SELECT * FROM sku_vendor_category_map WHERE name_id = ? AND deleted_at = ?`, []interface{}{sku.ID, utils.DefaultTimeValue}...)
|
||||
|
||||
sku.Name = skuName.Name
|
||||
sku.Img = skuName.Img
|
||||
sku.Img2 = skuName.Img2
|
||||
sku.Img3 = skuName.Img3
|
||||
sku.Img4 = skuName.Img4
|
||||
sku.Img5 = skuName.Img5
|
||||
dao.UpdateEntity(db, sku, "Name", "Img", "Img2", "Img3", "Img4", "Img5")
|
||||
sku.Unit = skuName.Unit
|
||||
dao.UpdateEntity(db, sku, "Name", "Img", "Img2", "Img3", "Img4", "Img5", "Unit")
|
||||
payload := make(map[string]interface{}, 0)
|
||||
payload["categoryID2"] = utils.Int2Str(sku.CategoryID)
|
||||
payload["categoryID"] = utils.Int2Str(sku.CategoryID)
|
||||
payload["descImg"] = sku.DescImg
|
||||
payload["img"] = sku.Img
|
||||
payload["img2"] = sku.Img2
|
||||
payload["img3"] = sku.Img3
|
||||
payload["img4"] = sku.Img4
|
||||
payload["img5"] = sku.Img5
|
||||
for _, d := range data {
|
||||
switch d.VendorID {
|
||||
case model.VendorIDJD:
|
||||
payload["jdCategoryID"] = d.VendorCategoryID
|
||||
case model.VendorIDMTWM:
|
||||
payload["mtwmCategoryID"] = d.VendorCategoryID
|
||||
case model.VendorIDJDShop:
|
||||
case model.VendorIDDD:
|
||||
payload["ddCategoryID"] = d.VendorCategoryID
|
||||
case model.VendorIDEBAI:
|
||||
payload["ebaiCategoryID"] = d.VendorCategoryID
|
||||
}
|
||||
}
|
||||
updateOrCreateSkuVendorCategoryMap(db, ctx, sku.ID, payload, nil, false)
|
||||
}
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
@@ -3303,7 +3381,7 @@ func setImgs2(v *model.SkuName, imgs []string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetSkuNamesNew(ctx *jxcontext.Context, keyword string, skuIDs, skuNameIDs []int, categoryID, status int, isBySku bool, offset, pageSize int) (skuNamesInfo *SkuNamesInfo, err error) {
|
||||
func GetSkuNamesNew(ctx *jxcontext.Context, keyword string, skuIDs, skuNameIDs []int, categoryID, status int, isBySku bool, offset, pageSize, bestSeller int) (skuNamesInfo *SkuNamesInfo, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
sql = ""
|
||||
@@ -3408,6 +3486,10 @@ func GetSkuNamesNew(ctx *jxcontext.Context, keyword string, skuIDs, skuNameIDs [
|
||||
sql += " AND t2.id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if bestSeller > 0 {
|
||||
sql += " AND t1.best_seller = ? "
|
||||
sqlParams = append(sqlParams, bestSeller)
|
||||
}
|
||||
if categoryID > 0 {
|
||||
cat := &model.SkuCategory{}
|
||||
cat.ID = categoryID
|
||||
@@ -3502,3 +3584,10 @@ func GetSkuNamesNew(ctx *jxcontext.Context, keyword string, skuIDs, skuNameIDs [
|
||||
}
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
|
||||
func SetSkuNameSeller(nameIds []int64, bastSeller int) error {
|
||||
sql := ` UPDATE sku_name SET bast_seller = ? WHERE id IN (` + dao.GenQuestionMarks(len(nameIds)) + `)`
|
||||
param := []interface{}{bastSeller, nameIds}
|
||||
_, err := dao.ExecuteSQL(dao.GetDB(), sql, param...)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1125,10 +1125,56 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("UpdateStore track:%s, store:%s", ctx.GetTrackInfo(), utils.Format4Output(store, true))
|
||||
}
|
||||
if status == -2 {
|
||||
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
//// updateVendorStoreStatusAndDeliveryStatus 当门店被禁用时,将三方平台和三方配送全部关闭
|
||||
//func updateVendorStoreStatusAndDeliveryStatus(ctx *jxcontext.Context, storeId int) error {
|
||||
// var (
|
||||
// db = dao.GetDB()
|
||||
// )
|
||||
// // 获取门店绑定三方平台列表
|
||||
// storeMap, err := dao.GetStoresMapList(db, nil, []int{storeId}, nil, 0, 0, "", "", "")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // 获取门店绑定的配送凭条
|
||||
// storeCouriers, err := dao.GetOpenedStoreCouriersByStoreID(db, storeId, -1)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// work := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// var errList []error
|
||||
// step := batchItemList[0].(int)
|
||||
// switch step {
|
||||
// case 0: // 同步修改门店营业撞他
|
||||
// // 京东关店,本地店铺状态修改
|
||||
// // 美团关店,本地店铺状态修改
|
||||
// // 饿百关店,本地店铺状态修改
|
||||
// // 抖音关店,本地店铺状态修改
|
||||
// case 1: // 同步修改门店配送状态
|
||||
// // 美团跑腿配送(没有门店状态修改,直接修改本店)
|
||||
// // 蜂鸟配送,关闭(有)
|
||||
// // 达达配送,关闭(有)
|
||||
// // uu跑腿,关闭(不涉及门店概念,直接本地取消绑定信息)
|
||||
// }
|
||||
// return errList, nil
|
||||
// }
|
||||
// tasksch.NewParallelTask(
|
||||
// "禁用门店,修改平台门店状态",
|
||||
// tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(false),
|
||||
// ctx,
|
||||
// work,
|
||||
// []int{0, 1},
|
||||
// )
|
||||
//
|
||||
//}
|
||||
|
||||
func notifyStoreOperatorChanged(ctx *jxcontext.Context, storeID int, operatorRoleName, phone string, newPhone interface{}) {
|
||||
if phone != "" && newPhone != nil {
|
||||
db := dao.GetDB()
|
||||
@@ -1780,6 +1826,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
dao.Rollback(db, txDB)
|
||||
return 0, err
|
||||
}
|
||||
isSyncStoreMapSku := false
|
||||
if num > 0 {
|
||||
if globals.IsAddEvent {
|
||||
mapBefore := refutil.FindMapAndStructMixed(valid, beforeStoreMap)
|
||||
@@ -1794,6 +1841,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
dao.Rollback(db, txDB)
|
||||
return 0, err
|
||||
}
|
||||
isSyncStoreMapSku = true
|
||||
}
|
||||
} else {
|
||||
if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil {
|
||||
@@ -1804,7 +1852,27 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
dao.Commit(db, txDB)
|
||||
if isStoreMapNeedSync(vendorID, valid) {
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||
globals.SugarLogger.Debug("CurVendorSync.SyncStore:err======%v", err)
|
||||
}
|
||||
|
||||
// 更新商品
|
||||
if isSyncStoreMapSku {
|
||||
globals.SugarLogger.Debugf("修改门店调价包是同步门店商品价格=============: %v", err)
|
||||
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
task := tasksch.NewParallelTask("修改门店调价包的时候,同时同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 1:
|
||||
if singleStoreHandler != nil {
|
||||
// 直接同步商品
|
||||
err = syncStoreSkuNew(ctx, task, 0, true, vendorID, storeID, "", nil, nil, nil, false, true)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{1})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3738,8 +3738,14 @@ func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (storeSkuNameE
|
||||
return storeSkuNameExt2, err
|
||||
}
|
||||
|
||||
// GetTopSkusByCityCode 获取当前城市订单销量前一百的商品,排除掉商户已经可售的商品剩下的为热销推荐
|
||||
func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNameAndPlaceList []*dao.SkuNameAndPlace, err error) {
|
||||
db := dao.GetDB()
|
||||
store, err := dao.GetStoreDetail(db, storeID, -1, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cityCode = store.CityCode
|
||||
orderCreate := time.Now().AddDate(0, -1, 0)
|
||||
var skuNameAndPlace []*dao.SkuNameAndPlace
|
||||
if cityCode > 0 {
|
||||
@@ -3779,10 +3785,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
|
||||
for _, v := range skuNameList {
|
||||
skuNameMap[v.ID] = v
|
||||
}
|
||||
store, err := dao.GetStoreDetail(db, storeID, -1, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var payPercentage int
|
||||
if store.PayPercentage < 50 {
|
||||
payPercentage = 70
|
||||
@@ -5889,14 +5892,13 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto
|
||||
}
|
||||
}
|
||||
for _, skuBindInfo := range skuBindInfos {
|
||||
globals.SugarLogger.Debugf("doStoreSkuAudit storeID: %v , nameID: %v", storeID, skuBindInfo.NameID)
|
||||
storeAudits, err := dao.GetStoreSkuAuditLight(db, []int{storeID}, []int{skuBindInfo.NameID}, model.StoreAuditStatusOnline)
|
||||
//取消关注,可售排除
|
||||
if skuBindInfo.IsFocus == -1 || skuBindInfo.IsSale != 0 || skuBindInfo.UnitPrice == 0 {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
|
||||
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile && ctx.GetLoginType() != auth2.AuthTypePassword {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil && authInfo != nil && (ctx.GetFullUser().Type&model.UserTypeOperator) != 0 {
|
||||
if len(storeAudits) > 0 {
|
||||
|
||||
@@ -203,7 +203,6 @@ func SyncSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int,
|
||||
}
|
||||
|
||||
if err == nil && len(skuList) > 0 {
|
||||
// todo 按vendorID orgCode合并操作SyncSkus=============
|
||||
task := tasksch.NewParallelTask(
|
||||
fmt.Sprintf("同步商品:%v,%v", nameIDs, skuIDs),
|
||||
tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, cc, skuList)
|
||||
|
||||
158
business/jxstore/cms/system_store_sku.go
Normal file
158
business/jxstore/cms/system_store_sku.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"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/business/partner/purchase/mtwm"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/putils"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CopyOnStoreSkuToOther 将一个美团门店分类和商品复制到另一个门店
|
||||
func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromVendorStoreId, toStoreId int, isAsync bool) (hint string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
|
||||
// 门店api加载
|
||||
// fromStore, err := dao.GetStoreDetail(db, fromStoreId, model.VendorIDMTWM, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
toStore, err := dao.GetStoreDetail(db, toStoreId, model.VendorIDMTWM, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
//fromApi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, toStore.VendorOrgCode).(*mtwmapi.API)
|
||||
toApi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, toStore.VendorOrgCode).(*mtwmapi.API)
|
||||
|
||||
taskName := fmt.Sprintf("将平台门店[%d],分类和商品复制到[%d]", fromVendorStoreId, toStoreId)
|
||||
config := tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(false)
|
||||
work := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 1:
|
||||
// 1.加载门店商品,删除商品.当分类下没有商品时.删除分类
|
||||
errs := LoadingStoreSkuList(ctx, toApi, toStore.VendorStoreID)
|
||||
if errs != nil && len(errs) > 0 {
|
||||
return nil, errs[0]
|
||||
}
|
||||
case 2:
|
||||
// 同步分类
|
||||
fromCategoryList, err := toApi.RetailCatList(utils.Int2Str(fromVendorStoreId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range fromCategoryList {
|
||||
if err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
|
||||
CategoryCode: v.Code,
|
||||
Sequence: v.Sequence,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v.Children != nil && len(v.Children) != 0 {
|
||||
for _, c := range v.Children {
|
||||
if err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
|
||||
CategoryCode: v.Code,
|
||||
SecondaryCategoryCode: c.Code,
|
||||
SecondaryCategoryName: c.Name,
|
||||
Sequence: c.Sequence,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case 3:
|
||||
// 同步商品
|
||||
fromFoodList, err1 := toApi.RetailListAll(utils.Int2Str(fromVendorStoreId))
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
if err := BatchInitData(ctx, fromFoodList, toApi, toStore.VendorStoreID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
task := tasksch.NewParallelTask(taskName, config, ctx, work, []int{1, 2, 3})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = task.ID
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func LoadingStoreSkuList(ctx *jxcontext.Context, api *mtwmapi.API, poiCode string) (err []error) {
|
||||
foodList, err1 := api.RetailListAll(poiCode)
|
||||
if err1 != nil {
|
||||
return append(err, err1)
|
||||
}
|
||||
|
||||
i := 0
|
||||
for _, v := range foodList {
|
||||
err1 := api.RetailDelete(ctx.GetTrackInfo(), poiCode, v.AppFoodCode)
|
||||
if err1 != nil {
|
||||
err = append(err, err1)
|
||||
}
|
||||
if i%40 == 0 {
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BatchInitData 批量创建商品
|
||||
func BatchInitData(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi *mtwmapi.API, vendorStoreID string) error {
|
||||
foodDataList := make([]map[string]interface{}, len(fromSku))
|
||||
for i, storeSku := range fromSku {
|
||||
foodData := make(map[string]interface{})
|
||||
foodDataList[i] = foodData
|
||||
foodData[mtwmapi.KeyAppFoodCode] = storeSku.AppFoodCode
|
||||
foodData["skus"] = storeSku.Skus
|
||||
foodData["name"] = utils.LimitUTF8StringLen(storeSku.Name, mtwmapi.MaxSkuNameCharCount)
|
||||
foodData["description"] = storeSku.Description
|
||||
foodData["price"] = storeSku.Price
|
||||
if storeSku.MinOrderCount != 0 {
|
||||
foodData["min_order_count"] = storeSku.MinOrderCount
|
||||
} else {
|
||||
foodData["min_order_count"] = 1
|
||||
}
|
||||
foodData["unit"] = storeSku.Unit
|
||||
attr := mtwm.SwitchAttr(int64(storeSku.TagID))
|
||||
if attr != "" {
|
||||
foodData["common_attr_value"] = attr
|
||||
}
|
||||
foodData["category_code"] = storeSku.CategoryCode
|
||||
foodData["category_name"] = storeSku.CategoryName
|
||||
foodData["is_sold_out"] = storeSku.IsSoldOut
|
||||
foodData["picture"] = storeSku.Picture
|
||||
foodData["picture_contents"] = storeSku.PictureContents
|
||||
foodData["sequence"] = storeSku.Sequence
|
||||
foodData["tag_id"] = storeSku.TagID
|
||||
}
|
||||
|
||||
failedFoodList, err2 := toApi.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList)
|
||||
if err := err2; err == nil {
|
||||
if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err2 != nil && len(failedFoodList) == 0 {
|
||||
if errExt, ok := err2.(*utils.ErrorWithCode); ok {
|
||||
return utils.UnmarshalUseNumber([]byte(errExt.ErrMsg()), &failedFoodList)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user