220 lines
7.3 KiB
Go
220 lines
7.3 KiB
Go
package jdshop
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
|
|
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
|
|
"git.rosy.net.cn/baseapi/platformapi/yinbaoapi"
|
|
"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/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/globals"
|
|
)
|
|
|
|
var (
|
|
sensitiveWordRegexp = regexp.MustCompile(`商品名称中含有敏感词(\[.*\])`)
|
|
)
|
|
|
|
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
|
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
|
|
|
|
}
|
|
return failedList, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
|
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
|
|
|
|
}
|
|
return failedList, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
|
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
|
|
|
|
}
|
|
return failedList, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (skuNameList []*partner.SkuNameInfo, err error) {
|
|
|
|
return skuNameList, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
|
if globals.EnableJdShopWrite {
|
|
|
|
}
|
|
return failedList, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
|
if globals.EnableJdShopWrite {
|
|
|
|
}
|
|
return failedList, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
|
if globals.EnableJdShopWrite {
|
|
|
|
}
|
|
return failedList, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*partner.BareCategoryInfo, err error) {
|
|
result, err := api.JdShopAPI.FindShopCategories()
|
|
for _, v := range result {
|
|
var cat = &partner.BareCategoryInfo{
|
|
VendorCatID: utils.Int64ToStr(v.CID),
|
|
Name: v.Name,
|
|
}
|
|
if v.ParentCID == 0 {
|
|
cat.Level = 1
|
|
} else {
|
|
cat.Level = 2
|
|
}
|
|
cats = append(cats, cat)
|
|
}
|
|
return cats, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
|
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
|
|
err = updateOrCreateCategories(storeCat, true)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
|
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
|
|
err = updateOrCreateCategories(storeCat, false)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) {
|
|
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
|
|
_, err = api.JdShopAPI.DeleteShopCategory(utils.Str2Int64(vendorCatID))
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (p *PurchaseHandler) IsErrSkuExist(err error) (isExist bool) {
|
|
return false
|
|
}
|
|
|
|
func (p *PurchaseHandler) IsErrCategoryExist(err error) (isExist bool) {
|
|
return false
|
|
}
|
|
|
|
func (p *PurchaseHandler) IsErrCategoryNotExist(err error) (isNotExist bool) {
|
|
return false
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
|
return 1
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp {
|
|
return sensitiveWordRegexp
|
|
}
|
|
|
|
func (p *PurchaseHandler) IsErrSkuNotExist(err error) (isNotExist bool) {
|
|
return false
|
|
}
|
|
|
|
func ybSkuStatus2Jx(ybStatus int) (jxSkuStatus int) {
|
|
if ybStatus == yinbaoapi.SkuStatusEnable {
|
|
jxSkuStatus = model.SkuStatusNormal
|
|
} else if ybStatus == yinbaoapi.SkuStatusDisabled {
|
|
jxSkuStatus = model.SkuStatusDontSale
|
|
} else if ybStatus == yinbaoapi.SkuStatusDeleted {
|
|
jxSkuStatus = model.SkuStatusDeleted
|
|
}
|
|
return jxSkuStatus
|
|
}
|
|
|
|
func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp []*yinbaoapi.QueryProductImagesByBarcodeResult) (skuName *partner.SkuNameInfo) {
|
|
var picList []string
|
|
if result == nil {
|
|
globals.SugarLogger.Warnf("vendorSku2Jx, strange result:%s", utils.Format4Output(result, true))
|
|
return nil
|
|
}
|
|
if len(resultp) > 0 {
|
|
if resultp[0].ImageURL != "" {
|
|
// for _, v := range resultp.Productimages {
|
|
picList = append(picList, resultp[0].ImageURL)
|
|
// }
|
|
}
|
|
}
|
|
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(result.Name)
|
|
skuName = &partner.SkuNameInfo{
|
|
Prefix: prefix,
|
|
Name: name,
|
|
Unit: unit,
|
|
YbBarCode: result.Barcode,
|
|
SkuList: []*partner.SkuInfo{
|
|
&partner.SkuInfo{
|
|
StoreSkuInfo: partner.StoreSkuInfo{
|
|
VendorSkuID: utils.Int64ToStr(result.UID),
|
|
Stock: int(utils.Float64TwoInt64(result.Stock)),
|
|
VendorPrice: jxutils.StandardPrice2Int(result.SellPrice),
|
|
Status: ybSkuStatus2Jx(result.Enable),
|
|
},
|
|
SkuName: result.Name,
|
|
Comment: comment,
|
|
SpecQuality: float64(specQuality),
|
|
SpecUnit: specUnit,
|
|
Weight: int(utils.Float64TwoInt64(float64(specQuality))),
|
|
},
|
|
},
|
|
PictureList: picList,
|
|
}
|
|
return skuName
|
|
}
|
|
|
|
func updateOrCreateCategories(storeCat *dao.SkuStoreCatInfo, isCreate bool) (err error) {
|
|
var createShopCategoryParams []*jdshopapi.CreateShopCategoryParam
|
|
result, err := api.JdShopAPI.FindShopCategories()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, v := range result {
|
|
createShopCategoryParam := &jdshopapi.CreateShopCategoryParam{
|
|
HomeShow: "0",
|
|
ID: utils.Int64ToStr(v.CID),
|
|
Open: "",
|
|
OrderNo: utils.Int2Str(v.OrderNo),
|
|
ParentID: utils.Int64ToStr(v.ParentCID),
|
|
Title: v.Name,
|
|
Type: jdshopapi.UpdateCatType,
|
|
}
|
|
createShopCategoryParams = append(createShopCategoryParams, createShopCategoryParam)
|
|
}
|
|
createShopCategoryParam2 := &jdshopapi.CreateShopCategoryParam{
|
|
HomeShow: "0",
|
|
Open: "",
|
|
OrderNo: utils.Int2Str(storeCat.Seq),
|
|
ParentID: storeCat.ParentVendorCatID,
|
|
Title: storeCat.Name,
|
|
}
|
|
if isCreate {
|
|
createShopCategoryParam2.Type = jdshopapi.CreateCatType
|
|
createShopCategoryParam2.ID = "1"
|
|
} else {
|
|
createShopCategoryParam2.Type = jdshopapi.UpdateCatType
|
|
createShopCategoryParam2.ID = storeCat.VendorCatID
|
|
}
|
|
createShopCategoryParams = append(createShopCategoryParams, createShopCategoryParam2)
|
|
err = api.JdShopAPI.CreateShopCategory(createShopCategoryParams)
|
|
return err
|
|
}
|