- 整理storesku的操作方式,统一一下,未完成
This commit is contained in:
204
business/partner/purchase/mtwm/store_sku2.go
Normal file
204
business/partner/purchase/mtwm/store_sku2.go
Normal file
@@ -0,0 +1,204 @@
|
||||
package mtwm
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
// 门店分类
|
||||
func (p *PurchaseHandler) ReadStoreCategory(ctx *jxcontext.Context, vendorStoreID string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
remoteCats, err := api.MtwmAPI.RetailCatList(vendorStoreID)
|
||||
if err == nil {
|
||||
cats = convertVendorCatList(remoteCats)
|
||||
}
|
||||
return cats, err
|
||||
}
|
||||
|
||||
func convertVendorCatList(remoteCats []*mtwmapi.RetailCategoryInfo) (cats []*partner.BareCategoryInfo) {
|
||||
for _, rCat := range remoteCats {
|
||||
cat := &partner.BareCategoryInfo{
|
||||
VendorCatID: rCat.Name,
|
||||
Name: rCat.Name,
|
||||
Level: rCat.Level,
|
||||
Seq: rCat.Sequence,
|
||||
Children: convertVendorCatList(rCat.Children),
|
||||
}
|
||||
cats = append(cats, cat)
|
||||
}
|
||||
return cats
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreSkuCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
level := 1
|
||||
if storeCat.ParentCatName != "" {
|
||||
level = 2
|
||||
}
|
||||
catName := storeCat.Name
|
||||
subCatName := ""
|
||||
originName := ""
|
||||
if storeCat.StoreCatSyncStatus&model.SyncFlagNewMask == 0 {
|
||||
originName = storeCat.VendorCatID
|
||||
}
|
||||
if level == 2 {
|
||||
originName = storeCat.ParentCatName
|
||||
catName = storeCat.ParentCatName
|
||||
subCatName = storeCat.Name
|
||||
if storeCat.StoreCatSyncStatus&model.SyncFlagNewMask == 0 {
|
||||
originName = storeCat.VendorCatID
|
||||
catName = storeCat.Name
|
||||
subCatName = ""
|
||||
}
|
||||
}
|
||||
if catName == "" {
|
||||
panic("catName is empty")
|
||||
}
|
||||
globals.SugarLogger.Debugf("mtwm CreateStoreSkuCategory vendorStoreID:%s, originName:%s, catName:%s, subCatName:%s, seq:%d", vendorStoreID, originName, catName, subCatName, storeCat.Seq)
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailCatUpdate(vendorStoreID, originName, catName, subCatName, storeCat.Seq)
|
||||
}
|
||||
if err == nil {
|
||||
storeCat.VendorCatID = storeCat.Name
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkuCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
return p.CreateStoreSkuCategory(ctx, vendorStoreID, storeCat)
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteStoreSkuCategory(ctx *jxcontext.Context, vendorStoreID, vendorCatID string) (err error) {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailCatDelete(vendorStoreID, vendorCatID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 门店商品
|
||||
|
||||
// 多门店平台不需要实现这个接口
|
||||
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
return p.CreateStoreSkus(ctx, vendorStoreID, storeSkuList)
|
||||
}
|
||||
|
||||
// 通用
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义
|
||||
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
foodDataList := make([]map[string]interface{}, len(storeSkuList))
|
||||
for i, storeSku := range storeSkuList {
|
||||
foodData := make(map[string]interface{})
|
||||
foodDataList[i] = foodData
|
||||
foodData[mtwmapi.KeyAppFoodCode] = utils.Int2Str(storeSku.SkuID)
|
||||
skus := []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"sku_id": foodData[mtwmapi.KeyAppFoodCode],
|
||||
},
|
||||
}
|
||||
foodData["skus"] = skus
|
||||
foodData["name"] = utils.LimitUTF8StringLen(storeSku.Name, 30)
|
||||
foodData["description"] = storeSku.Comment
|
||||
foodData["price"] = storeSku.Price
|
||||
foodData["min_order_count"] = 1
|
||||
foodData["unit"] = storeSku.Unit
|
||||
foodData["box_num"] = 0
|
||||
foodData["box_price"] = 0.0
|
||||
foodData["category_name"] = storeSku.VendorCatID
|
||||
foodData["is_sold_out"] = skuStatusJX2Mtwm(storeSku.StoreSkuStatus)
|
||||
foodData["picture"] = storeSku.Img
|
||||
if storeSku.DescImg != "" {
|
||||
foodData["picture_contents"] = storeSku.DescImg
|
||||
}
|
||||
foodData["sequence"] = storeSku.Price
|
||||
if storeSku.VendorVendorCatID != 0 {
|
||||
foodData["tag_id"] = utils.Int64ToStr(storeSku.VendorVendorCatID)
|
||||
} else {
|
||||
// foodData["tag_id"] = utils.Int64ToStr(defVendorCatID)
|
||||
}
|
||||
skus[0]["spec"] = jxutils.ComposeSkuSpec(storeSku.SpecQuality, storeSku.SpecUnit)
|
||||
skus[0]["price"] = foodData["price"]
|
||||
skus[0]["stock"] = "*"
|
||||
skus[0]["upc"] = storeSku.Upc
|
||||
if foodData["tag_id"] != nil {
|
||||
skus[0]["weight"] = storeSku.Weight // weight字段仅限服饰鞋帽、美妆、日用品、母婴、生鲜果蔬、生活超市下的便利店/超市门店品类的商家使用
|
||||
}
|
||||
}
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailBatchInitData(vendorStoreID, foodDataList)
|
||||
}
|
||||
if err == nil {
|
||||
for _, storeSku := range storeSkuList {
|
||||
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
if len(storeSkuList) == 1 {
|
||||
err = api.MtwmAPI.RetailDelete(vendorStoreID, storeSkuList[0].VendorSkuID)
|
||||
} else {
|
||||
err = api.MtwmAPI.RetailCatSkuBatchDelete(vendorStoreID, nil, nil, partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDList())
|
||||
}
|
||||
}
|
||||
return ignoreNoAppFoodErr(err)
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
|
||||
var validSkus, invalidSkus []*mtwmapi.BareStoreFoodInfo
|
||||
for _, storeSku := range storeSkuList {
|
||||
skuInfo := &mtwmapi.BareStoreFoodInfo{
|
||||
AppFoodCode: storeSku.VendorSkuID,
|
||||
Skus: []*mtwmapi.BareStoreSkuInfo{
|
||||
&mtwmapi.BareStoreSkuInfo{
|
||||
SkuID: storeSku.VendorSkuID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if storeSku.Status == model.SkuStatusNormal {
|
||||
validSkus = append(validSkus, skuInfo)
|
||||
} else {
|
||||
invalidSkus = append(invalidSkus, skuInfo)
|
||||
}
|
||||
}
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
if len(invalidSkus) > 0 {
|
||||
err = api.MtwmAPI.RetailSkuSellStatus2(vendorStoreID, invalidSkus, 1)
|
||||
}
|
||||
if err == nil && len(validSkus) > 0 {
|
||||
err = api.MtwmAPI.RetailSkuSellStatus2(vendorStoreID, validSkus, 0)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
|
||||
var priceList []*mtwmapi.BareStoreFoodInfo
|
||||
for _, storeSku := range storeSkuList {
|
||||
skuInfo := &mtwmapi.BareStoreFoodInfo{
|
||||
AppFoodCode: storeSku.VendorSkuID,
|
||||
Skus: []*mtwmapi.BareStoreSkuInfo{
|
||||
&mtwmapi.BareStoreSkuInfo{
|
||||
SkuID: storeSku.VendorSkuID,
|
||||
Price: utils.Int2Str(storeSku.Price),
|
||||
},
|
||||
},
|
||||
}
|
||||
priceList = append(priceList, skuInfo)
|
||||
}
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailSkuPrice(vendorStoreID, priceList)
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user