新增银豹api和test
This commit is contained in:
@@ -18,6 +18,14 @@ const (
|
||||
sigKey = "sign"
|
||||
url = "https://area27-win.pospal.cn:443/pospal-api2/openapi/v1"
|
||||
statusSuccess = "success"
|
||||
|
||||
skuExistErrCode = "5004"
|
||||
|
||||
SkuStatusEnable = 1
|
||||
SkuStatusDisabled = 0
|
||||
SkuStatusDeleted = -1
|
||||
|
||||
PageMaxID = "LAST_RESULT_MAX_ID"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
@@ -86,7 +94,7 @@ func (a *API) AccessAPI(action string, bizParams map[string]interface{}) (retVal
|
||||
errMsg += v.(string)
|
||||
}
|
||||
err = utils.NewErrorCode(errMsg, jsonResult1["status"].(string))
|
||||
baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
baseapi.SugarLogger.Debugf("yinbao AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
@@ -153,6 +161,10 @@ func (a *API) AddProductInfo(productInfoParam *ProductInfoParam) (addProductInfo
|
||||
return addProductInfoResult, err
|
||||
}
|
||||
|
||||
func IsErrSkuExist(err error) (isExist bool) {
|
||||
return utils.IsErrMatch(err, skuExistErrCode, []string{"商品已存在"})
|
||||
}
|
||||
|
||||
//修改商品
|
||||
//http://pospal.cn/openplatform/productapi.html#addProductInfo
|
||||
func (a *API) UpdateProductInfo(productInfoParam *ProductInfoParam) (err error) {
|
||||
@@ -182,3 +194,114 @@ func (a *API) UpdateProductInfo(productInfoParam *ProductInfoParam) (err error)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
type QueryProductByBarcodeResult struct {
|
||||
UID int64 `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Barcode string `json:"barcode"`
|
||||
BuyPrice float64 `json:"buyPrice"`
|
||||
SellPrice float64 `json:"sellPrice"`
|
||||
SellPrice2 float64 `json:"sellPrice2"`
|
||||
Stock float64 `json:"stock"`
|
||||
MaxStock float64 `json:"maxStock"`
|
||||
MinStock float64 `json:"minStock"`
|
||||
Pinyin string `json:"pinyin"`
|
||||
Enable int `json:"enable"`
|
||||
CreatedDatetime string `json:"createdDatetime"`
|
||||
}
|
||||
|
||||
//按条形码查询商品(skuid)
|
||||
//http://pospal.cn/openplatform/productapi.html#queryProductByBarcode
|
||||
func (a *API) QueryProductByBarcode(barcode string) (queryProductByBarcodeResult *QueryProductByBarcodeResult, err error) {
|
||||
result, err := a.AccessAPI("productOpenApi/queryProductByBarcode", map[string]interface{}{
|
||||
"barcode": barcode,
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &queryProductByBarcodeResult, false)
|
||||
}
|
||||
return queryProductByBarcodeResult, err
|
||||
}
|
||||
|
||||
//按条形码批量查询商品
|
||||
//http://pospal.cn/openplatform/productapi.html#queryProductByBarcodes
|
||||
func (a *API) QueryProductByBarcodes(barcodes []string) (queryProductByBarcodeResult []*QueryProductByBarcodeResult, err error) {
|
||||
result, err := a.AccessAPI("productOpenApi/queryProductByBarcodes", map[string]interface{}{
|
||||
"barcodes": barcodes,
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &queryProductByBarcodeResult, false)
|
||||
}
|
||||
return queryProductByBarcodeResult, err
|
||||
}
|
||||
|
||||
type QueryProductImagesByBarcodeResult struct {
|
||||
ProductUID int64 `json:"productUid"`
|
||||
ProductName string `json:"productName"`
|
||||
ProductBarcode string `json:"productBarcode"`
|
||||
ImageURL string `json:"imageUrl"`
|
||||
}
|
||||
|
||||
//按条形码查询商品图片
|
||||
//http://pospal.cn/openplatform/productapi.html#queryProductImagesByBarcode
|
||||
func (a *API) QueryProductImagesByBarcode(barcode string) (queryProductImagesByBarcodeResult []*QueryProductImagesByBarcodeResult, err error) {
|
||||
result, err := a.AccessAPI("productOpenApi/queryProductImagesByBarcode", map[string]interface{}{
|
||||
"barcode": barcode,
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &queryProductImagesByBarcodeResult, false)
|
||||
}
|
||||
return queryProductImagesByBarcodeResult, err
|
||||
}
|
||||
|
||||
type PostBackParameter struct {
|
||||
ParameterType string `json:"parameterType"`
|
||||
ParameterValue string `json:"parameterType"`
|
||||
}
|
||||
|
||||
type QueryProductPagesResult struct {
|
||||
PostBackParameter struct {
|
||||
ParameterType string `json:"parameterType"`
|
||||
ParameterValue string `json:"parameterValue"`
|
||||
} `json:"postBackParameter"`
|
||||
Result []struct {
|
||||
UID int64 `json:"uid"`
|
||||
CategoryUID int `json:"categoryUid,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Barcode string `json:"barcode"`
|
||||
BuyPrice float64 `json:"buyPrice"`
|
||||
SellPrice float64 `json:"sellPrice"`
|
||||
SellPrice2 float64 `json:"sellPrice2"`
|
||||
Stock float64 `json:"stock"`
|
||||
MaxStock float64 `json:"maxStock"`
|
||||
MinStock float64 `json:"minStock"`
|
||||
Pinyin string `json:"pinyin"`
|
||||
CustomerPrice float64 `json:"customerPrice,omitempty"`
|
||||
IsCustomerDiscount int `json:"isCustomerDiscount,omitempty"`
|
||||
SupplierUID int `json:"supplierUid,omitempty"`
|
||||
Enable int `json:"enable"`
|
||||
CreatedDatetime string `json:"createdDatetime"`
|
||||
UpdatedDatetime string `json:"updatedDatetime,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ProductionDate string `json:"productionDate,omitempty"`
|
||||
Attribute1 string `json:"attribute1,omitempty"`
|
||||
Attribute2 string `json:"attribute2,omitempty"`
|
||||
Attribute3 string `json:"attribute3,omitempty"`
|
||||
Attribute4 string `json:"attribute4,omitempty"`
|
||||
Attribute5 string `json:"attribute5,omitempty"`
|
||||
Attribute6 string `json:"attribute6,omitempty"`
|
||||
Attribute7 string `json:"attribute7,omitempty"`
|
||||
} `json:"result"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
//分页查询所有商品
|
||||
//http://pospal.cn/openplatform/productapi.html#queryProductPages
|
||||
func (a *API) QueryProductPages(postBackParameter *PostBackParameter) (queryProductPagesResult *QueryProductPagesResult, err error) {
|
||||
result, err := a.AccessAPI("productOpenApi/queryProductPages", map[string]interface{}{
|
||||
"postBackParameter": postBackParameter,
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &queryProductPagesResult, false)
|
||||
}
|
||||
return queryProductPagesResult, err
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func init() {
|
||||
logger, _ := zap.NewDevelopment()
|
||||
sugarLogger = logger.Sugar()
|
||||
baseapi.Init(sugarLogger)
|
||||
api = New("682628966212343269", "18C0E0867E467DBC26EFF5E957B02EC4")
|
||||
api = New("682628966212343269", "18C0E0867E467DBC26EFF5E957B02EC4") //总店
|
||||
}
|
||||
|
||||
func TestAddProductInfo(t *testing.T) {
|
||||
@@ -26,11 +26,12 @@ func TestAddProductInfo(t *testing.T) {
|
||||
)
|
||||
result, err := api.AddProductInfo(&ProductInfoParam{
|
||||
ProductInfo: &ProductInfo{
|
||||
Name: "测试商品",
|
||||
Barcode: "12135",
|
||||
BuyPrice: &stock,
|
||||
SellPrice: &stock,
|
||||
Stock: &stock,
|
||||
Name: "测试商品",
|
||||
Barcode: "12132",
|
||||
BuyPrice: &stock,
|
||||
SellPrice: &stock,
|
||||
Stock: &stock,
|
||||
SupplierUID: 123,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -53,3 +54,41 @@ func TestUpdateProductInfo(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryProductByBarcode(t *testing.T) {
|
||||
result, err := api.QueryProductByBarcode("22510")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestQueryProductByBarcodes(t *testing.T) {
|
||||
result, err := api.QueryProductByBarcodes([]string{
|
||||
"22510",
|
||||
"2003181534102",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestQueryProductImagesByBarcode(t *testing.T) {
|
||||
result, err := api.QueryProductImagesByBarcode("22510")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestQueryProductPages(t *testing.T) {
|
||||
result, err := api.QueryProductPages(&PostBackParameter{
|
||||
ParameterType: "LAST_RESULT_MAX_ID",
|
||||
ParameterValue: "7064573",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user