82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package ebai
|
|
|
|
import (
|
|
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/business/partner"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
)
|
|
|
|
var (
|
|
CurPurchaseHandler *PurchaseHandler
|
|
)
|
|
|
|
type PurchaseHandler struct {
|
|
partner.BasePurchasePlatform
|
|
}
|
|
|
|
func init() {
|
|
if api.EbaiAPI != nil {
|
|
CurPurchaseHandler = new(PurchaseHandler)
|
|
partner.RegisterPurchasePlatform(CurPurchaseHandler)
|
|
}
|
|
}
|
|
|
|
func EbaiBusStatus2JxStatus(ebaiStatus int) int {
|
|
if ebaiStatus == ebaiapi.ShopBusStatusHaveRest || ebaiStatus == ebaiapi.ShopBusStatusSuspended {
|
|
return model.StoreStatusHaveRest
|
|
}
|
|
return model.StoreStatusOpened
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetVendorID() int {
|
|
return model.VendorIDEBAI
|
|
}
|
|
|
|
func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, imgURL string, imgData []byte, imgName string) (imgHint string, err error) {
|
|
if globals.EnableEbaiStoreWrite {
|
|
imgHint, err = api.EbaiAPI.PictureUpload(imgURL, imgData)
|
|
}
|
|
return imgHint, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) getVendorCategories(level int, pid int64) (vendorCats []*model.SkuVendorCategory, err error) {
|
|
cats, err := api.EbaiAPI.SkuCategoryList("", level, pid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, v := range cats {
|
|
cat := &model.SkuVendorCategory{
|
|
VendorID: model.VendorIDJD,
|
|
Name: v.CatName,
|
|
Level: level,
|
|
VendorCategoryID: v.CatID,
|
|
}
|
|
cat.LastOperator = "builder"
|
|
if level > 1 {
|
|
cat.ParentID = v.ParentID
|
|
if level == 3 {
|
|
cat.IsLeaf = 1
|
|
}
|
|
}
|
|
vendorCats = append(vendorCats, cat)
|
|
if level < 3 {
|
|
childVendorCats, err2 := p.getVendorCategories(level+1, utils.Str2Int64(v.CatID))
|
|
if err2 == nil && len(childVendorCats) > 0 {
|
|
vendorCats = append(vendorCats, childVendorCats...)
|
|
} else {
|
|
cat.IsLeaf = 1
|
|
}
|
|
}
|
|
}
|
|
return vendorCats, nil
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error) {
|
|
vendorCats, err = p.getVendorCategories(1, 0)
|
|
return vendorCats, err
|
|
}
|