85 lines
1.9 KiB
Go
85 lines
1.9 KiB
Go
package fnpsapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
)
|
|
|
|
const (
|
|
StoreNotExist = "门店信息不存在"
|
|
StoreExist = "该门店已存在"
|
|
)
|
|
|
|
// 创建门店.
|
|
func (a *API) CreateStore(createStoreParam *CreateStoreParam) (err error) {
|
|
params := utils.Struct2FlatMap(createStoreParam)
|
|
_, err = a.AccessAPI(ApiURL, "chainstoreCreate", RequestPost, params)
|
|
return err
|
|
}
|
|
|
|
// 获取门店(单个)
|
|
func (a *API) GetStore(storeID string) (getStoreResult *GetStoreResult, err error) {
|
|
params := GetOneStoreParam{
|
|
BaseInfo: BaseInfo{
|
|
AccessToken: a.accessToken,
|
|
Signature: a.signature,
|
|
MerchantID: a.merchantId,
|
|
Version: a.version,
|
|
AppID: a.appID,
|
|
Timestamp: a.timestamp,
|
|
},
|
|
BusinessData: "",
|
|
}
|
|
|
|
// 序列化请求参数
|
|
data, err := json.Marshal(GetOneStore{MerchantID: a.merchantId, OutShopCode: storeID})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
params.BusinessData = string(data)
|
|
paramsMap := utils.Struct2FlatMap(params)
|
|
|
|
result, err := a.AccessAPI(ApiURL, "chainstoreQuery", RequestGet, paramsMap)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if result["code"] != "200" {
|
|
return nil, fmt.Errorf("%s", result["msg"])
|
|
}
|
|
|
|
if data, ok := result["business_data"].([]interface{}); ok {
|
|
utils.Map2StructByJson(data[0], &getStoreResult, false)
|
|
} else {
|
|
err = fmt.Errorf(result["msg"].(string))
|
|
}
|
|
return getStoreResult, err
|
|
}
|
|
|
|
func IsErrShopNotExist(err error) bool {
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), StoreNotExist) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func IsErrShopExist(err error) bool {
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), StoreExist) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (a *API) UpdateStore(createStoreParam *CreateStoreParam) (err error) {
|
|
//params := utils.Struct2FlatMap(createStoreParam)
|
|
//_, err = a.AccessAPI("v2/chain_store/update", URL, params, true)
|
|
return err
|
|
}
|