package ebaiapi import ( "git.rosy.net.cn/baseapi/utils" ) const ( SysStatusAll = -1 SysStatusNew = 1 SysStatusModifiedWait = 3 SysStatusFailedVerify = 4 SysStatusOpening = 6 SysStatusNewWait = 7 SysStatusOnlineRejected = 8 SysStatusPassQC = 12 ) const ( ShopBusStatusOffline = 1 ShopBusStatusCanBooking = 2 ShopBusStatusOpening = 3 ShopBusStatusSuspended = 4 ShopBusStatusBookingNextDay = 5 ) const ( PlatformFlagElm = "1" PlatformFlagBaidu = "2" ) const ( KeyShopID = "shop_id" KeyBaiduShopID = "baidu_shop_id" KeyName = "name" KeyPhone = "phone" ) const ( CoordTypeBaidu = "bdll" CoordTypeAutonavi = "amap" ) const ( DeliveryTypeBaiduLogistics = 1 DeliveryTypeBaiduDeliveryBySelf = 2 DeliveryTypeBaiduCrowdSourcing = 3 DeliveryTypeBaiduXiaofeixia = 7 DeliveryTypeBaiduKuaidipeisong = 8 ) type ShopInfo struct { ShopID string `json:"shop_id"` BaiduShopID int64 `json:"baidu_shop_id"` Name string `json:"name"` Status int `json:"status"` SysStatus int `json:"sys_status"` OrderPush int `json:"order_push"` OrderStatusPush int `json:"order_status_push"` } func (a *API) genShopIDParams(shopID string, baiduShopID int64) map[string]interface{} { if shopID == "" && baiduShopID == 0 || shopID != "" && baiduShopID != 0 { panic("shopID and baiduShopID can not all be empty or all not be empty") } params := map[string]interface{}{} if shopID != "" { params[KeyShopID] = shopID } else { params[KeyBaiduShopID] = baiduShopID } return params } func (a *API) ShopList( /*orderPush, orderStatusPush, status, */ sysStatus int) (shopList []*ShopInfo, err error) { body := map[string]interface{}{} // if orderPush >= 0 { // body["order_push"] = orderPush // } // if orderStatusPush >= 0 { // body["order_status_push"] = orderStatusPush // } // if status >= 0 { // body["status"] = status // } if sysStatus >= 0 { body["sys_status"] = sysStatus } result, err := a.AccessAPI("shop.list", body) if err == nil { list := result.Data.([]interface{}) shopList = make([]*ShopInfo, len(list)) for k, v := range list { mapData := v.(map[string]interface{}) shopList[k] = &ShopInfo{ ShopID: utils.Interface2String(mapData[KeyShopID]), BaiduShopID: utils.Str2Int64(utils.Interface2String(mapData[KeyBaiduShopID])), } } return shopList, nil } return nil, err } func (a *API) ShopCreate(params map[string]interface{}) (baiduShopID int64, err error) { result, err := a.AccessAPI("shop.create", params) if err == nil { return utils.MustInterface2Int64(result.Data.(map[string]interface{})[KeyBaiduShopID]), nil } return 0, err } func (a *API) ShopGet(shopID string, baiduShopID int64) (shop map[string]interface{}, err error) { params := a.genShopIDParams(shopID, baiduShopID) result, err := a.AccessAPI("shop.get", params) if err == nil { return result.Data.(map[string]interface{}), nil } return nil, err } func (a *API) ShopUpdate(params map[string]interface{}) (err error) { _, err = a.AccessAPI("shop.update", params) if err == nil { return nil } return err } func (a *API) ShopBusStatusGet(shopID string, baiduShopID int64, platformFlag string) (busStatus int, err error) { params := a.genShopIDParams(shopID, baiduShopID) params["platformFlag"] = platformFlag result, err := a.AccessAPI("shop.busstatus.get", params) if err == nil { return int(utils.MustInterface2Int64(result.Data.(map[string]interface{})["shop_busstatus"])), nil } return 0, err } // 相同值再次重复映射会出错 func (a *API) ShopIDBatchUpdate(baiduShopIDs []string, shopIDs []string) (err error) { _, err = a.AccessAPI("shop.id.batchupdate", utils.Params2Map("baidu_shop_ids", baiduShopIDs, "shop_ids", shopIDs)) if err == nil { return nil } return err } func (a *API) ShopOnline(shopID string, baiduShopID int64) (err error) { params := a.genShopIDParams(shopID, baiduShopID) _, err = a.AccessAPI("shop.open", params) if err == nil { return nil } return err } func (a *API) ShopOffline(shopID string, baiduShopID int64) (err error) { params := a.genShopIDParams(shopID, baiduShopID) _, err = a.AccessAPI("shop.offline", params) if err == nil { return nil } return err } func (a *API) ShopClose(shopID string, baiduShopID int64) (err error) { params := a.genShopIDParams(shopID, baiduShopID) _, err = a.AccessAPI("shop.close", params) if err == nil { return nil } return err } func (a *API) SupplierList() (supplierInfo map[string]interface{}, err error) { result, err := a.AccessAPI("supplier.list", nil) if err == nil { return result.Data.(map[string]interface{}), nil } return nil, err }