银豹创建商品测试,新增查询api
This commit is contained in:
@@ -46,6 +46,9 @@ type StoreDetail struct {
|
|||||||
|
|
||||||
JdStoreLevel string `json:"jdStoreLevel"` //京东门店等级
|
JdStoreLevel string `json:"jdStoreLevel"` //京东门店等级
|
||||||
IsOrder int `json:"isOrder"` //是否是下预订单门店
|
IsOrder int `json:"isOrder"` //是否是下预订单门店
|
||||||
|
|
||||||
|
YbAppID string `orm:"column(yb_app_id)" json:"ybAppID"`
|
||||||
|
YbAppKey string `json:"ybAppKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 带快递门店信息的
|
// 带快递门店信息的
|
||||||
@@ -89,7 +92,7 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
|||||||
sql := `
|
sql := `
|
||||||
SELECT t1.*,
|
SELECT t1.*,
|
||||||
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee_deduction_sill, t2.delivery_fee_deduction_fee, t2.sync_status, t2.vendor_org_code,
|
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee_deduction_sill, t2.delivery_fee_deduction_fee, t2.sync_status, t2.vendor_org_code,
|
||||||
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync, t2.vendor_store_name, t2.is_order,
|
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync, t2.vendor_store_name, t2.is_order, t2.yb_app_id, t2.yb_app_key,
|
||||||
t3.value price_percentage_pack_str,
|
t3.value price_percentage_pack_str,
|
||||||
t4.value freight_deduction_pack_str,
|
t4.value freight_deduction_pack_str,
|
||||||
district.name district_name,
|
district.name district_name,
|
||||||
|
|||||||
@@ -109,9 +109,6 @@ type StoreSkuSyncInfo struct {
|
|||||||
ActPercentage int `json:"actPercentage"` // 直降活动百分比
|
ActPercentage int `json:"actPercentage"` // 直降活动百分比
|
||||||
ActSyncStatus int8 `orm:"default(2)" json:"actSyncStatus"`
|
ActSyncStatus int8 `orm:"default(2)" json:"actSyncStatus"`
|
||||||
VendorActPrice int64 `json:"vendorActPrice"` // 保存数据用,实际的活动价
|
VendorActPrice int64 `json:"vendorActPrice"` // 保存数据用,实际的活动价
|
||||||
|
|
||||||
YbAppID string `orm:"column(yb_app_id)" json:"ybAppID"` //银豹对应门店的appID
|
|
||||||
YbAppKey string `json:"ybAppKey"` //银豹对应门店的appkey
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MissingStoreSkuInfo struct {
|
type MissingStoreSkuInfo struct {
|
||||||
@@ -389,7 +386,7 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo
|
|||||||
}
|
}
|
||||||
sql := `
|
sql := `
|
||||||
SELECT
|
SELECT
|
||||||
t14.vendor_id, t14.vendor_org_code, t14.yb_app_id, t14.yb_app_key,
|
t14.vendor_id, t14.vendor_org_code,
|
||||||
t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status,
|
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,
|
%s vendor_sku_id, t1.%s_sync_status sku_sync_status, t1.%s_price vendor_price, t1.%s_lock_time lock_time,
|
||||||
t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end,
|
t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end,
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
package yb
|
package yb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/yinbaoapi"
|
"git.rosy.net.cn/baseapi/platformapi/yinbaoapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"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/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"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"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"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/putils"
|
"git.rosy.net.cn/jx-callback/business/partner/putils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +22,7 @@ var (
|
|||||||
|
|
||||||
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||||
storeSku := storeSkuList[0]
|
storeSku := storeSkuList[0]
|
||||||
api.YinBaoAPI = yinbaoapi.New(storeSku.YbAppKey, storeSku.YbAppID)
|
buildYbConfigs(storeID)
|
||||||
result, err := api.YinBaoAPI.AddProductInfo(buildProductInfoParam(storeSku))
|
result, err := api.YinBaoAPI.AddProductInfo(buildProductInfoParam(storeSku))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDYB], "创建商品")
|
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDYB], "创建商品")
|
||||||
@@ -31,6 +36,18 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v
|
|||||||
return failedList, err
|
return failedList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildYbConfigs(storeID int) (err error) {
|
||||||
|
if storeID == 0 {
|
||||||
|
return fmt.Errorf("门店ID不能为空!平台:[%v]", model.VendorIDYB)
|
||||||
|
}
|
||||||
|
store, err := dao.GetStoreDetail(dao.GetDB(), storeID, model.VendorIDYB)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
api.YinBaoAPI = yinbaoapi.New(store.YbAppKey, store.YbAppID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func buildProductInfoParam(storeSku *dao.StoreSkuSyncInfo) (productInfoParam *yinbaoapi.ProductInfoParam) {
|
func buildProductInfoParam(storeSku *dao.StoreSkuSyncInfo) (productInfoParam *yinbaoapi.ProductInfoParam) {
|
||||||
var (
|
var (
|
||||||
buyPrice float64 = utils.Str2Float64(utils.Int64ToStr(storeSku.Price)) / 100
|
buyPrice float64 = utils.Str2Float64(utils.Int64ToStr(storeSku.Price)) / 100
|
||||||
@@ -48,6 +65,137 @@ func buildProductInfoParam(storeSku *dao.StoreSkuSyncInfo) (productInfoParam *yi
|
|||||||
return productInfoParam
|
return productInfoParam
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||||
|
buildYbConfigs(storeID)
|
||||||
|
if storeSkuList != nil {
|
||||||
|
if len(storeSkuList) == 1 {
|
||||||
|
storeSku := storeSkuList[0]
|
||||||
|
result, err := api.YinBaoAPI.QueryProductByBarcode(utils.Int2Str(storeSku.SkuID))
|
||||||
|
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(utils.Int2Str(storeSku.SkuID))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if skuName := vendorSku2Jx(result, resultp); skuName != nil {
|
||||||
|
skuNameList = append(skuNameList, skuName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var barcodes []string
|
||||||
|
for _, v := range storeSkuList {
|
||||||
|
barcodes = append(barcodes, utils.Int2Str(v.SkuID))
|
||||||
|
}
|
||||||
|
results, err := api.YinBaoAPI.QueryProductByBarcodes(barcodes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, v := range results {
|
||||||
|
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if skuName := vendorSku2Jx(v, resultp); skuName != nil {
|
||||||
|
skuNameList = append(skuNameList, skuName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result, err := api.YinBaoAPI.QueryProductPages(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.PostBackParameter.ParameterType == yinbaoapi.PageMaxID {
|
||||||
|
for _, v := range result.Result {
|
||||||
|
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
vv := &yinbaoapi.QueryProductByBarcodeResult{}
|
||||||
|
err = utils.Map2StructByJson(utils.Struct2MapByJson(v), vv, false)
|
||||||
|
if skuName := vendorSku2Jx(vv, resultp); skuName != nil {
|
||||||
|
skuNameList = append(skuNameList, skuName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loopPages(result.PostBackParameter.ParameterType, result.PostBackParameter.ParameterValue, skuNameList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return skuNameList, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuNameInfo) (err error) {
|
||||||
|
var postBackParameter = &yinbaoapi.PostBackParameter{
|
||||||
|
ParameterType: parameterType,
|
||||||
|
ParameterValue: parameterValue,
|
||||||
|
}
|
||||||
|
resultPages, err := api.YinBaoAPI.QueryProductPages(postBackParameter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, v := range resultPages.Result {
|
||||||
|
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
vv := &yinbaoapi.QueryProductByBarcodeResult{}
|
||||||
|
err = utils.Map2StructByJson(utils.Struct2MapByJson(v), vv, false)
|
||||||
|
if skuName := vendorSku2Jx(vv, resultp); skuName != nil {
|
||||||
|
skuNameList = append(skuNameList, skuName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if resultPages.PostBackParameter.ParameterType != yinbaoapi.PageMaxID {
|
||||||
|
err = loopPages(resultPages.PostBackParameter.ParameterType, resultPages.PostBackParameter.ParameterValue, skuNameList)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
for _, v := range resultp {
|
||||||
|
picList = append(picList, v.ImageURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(result.Name)
|
||||||
|
skuID := int(utils.Str2Int64WithDefault(result.Barcode, 0))
|
||||||
|
skuName = &partner.SkuNameInfo{
|
||||||
|
Prefix: prefix,
|
||||||
|
Name: name,
|
||||||
|
Unit: unit,
|
||||||
|
SkuList: []*partner.SkuInfo{
|
||||||
|
&partner.SkuInfo{
|
||||||
|
StoreSkuInfo: partner.StoreSkuInfo{
|
||||||
|
VendorSkuID: utils.Int64ToStr(result.UID),
|
||||||
|
SkuID: skuID,
|
||||||
|
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 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 (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -59,3 +207,7 @@ func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID in
|
|||||||
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) {
|
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) IsErrSkuExist(err error) (isExist bool) {
|
||||||
|
return yinbaoapi.IsErrSkuExist(err)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user