def create_express(self, baidu_shop_id=None, shop_id=None, express_list=[]): """ 设置订单快递单号 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_express_create :param baidu_shop_id: 合作方门店ID :param shop_id: 平台门店ID :param express_list: 快递信息;数组 order_id: 订单号 express_id: 快递单号 express_company: 快递名称 :return: """ cmd = 'order.express.create' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") if not express_list: raise EbaiClientException(errno=10000, errmsg="快递信息为空") body = {'express_list': express_list} if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def delete(self, shop_id, **kwargs): """ 删除商品 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Sku-sku_delete :param shop_id: 合作方门店ID :param sku_id: `可选` 商品id,多个id以逗号连接,最多同时支持100个商品id,与custom_sku_id参数互斥 :param custom_sku_id: `可选` 商品自定义ID,与sku_id参数互斥 :return: """ cmd = 'sku.delete' body = {'shop_id': shop_id} sku_id = kwargs.pop('sku_id', None) custom_sku_id = kwargs.pop('custom_sku_id', None) if not sku_id and not custom_sku_id: raise EbaiClientException(errno=10208, errmsg='缺少参数sku_id') if sku_id and custom_sku_id: raise EbaiClientException(errno=1, errmsg='sku_id和custom_sku_id参数互斥') if sku_id: body['sku_id'] = sku_id elif custom_sku_id: body['custom_sku_id'] = custom_sku_id return self._post(cmd, **{'body': body})
def batchupdate_id(self, baidu_shop_ids, shop_ids): """ 商户三方门店ID映射 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Shop-shop_id_batchupdate :param baidu_shop_ids: 平台门店ID(数组) :param shop_ids: 合作方门店ID(数组) :return: """ cmd = 'shop.id.batchupdate' if not isinstance(baidu_shop_ids, list): raise EbaiClientException(errno=10000, errmsg="baidu_shop_ids 平台门店ID 应该是一个数组") if not isinstance(shop_ids, list): raise EbaiClientException(errno=10000, errmsg="baidu_shop_ids 平台门店ID 应该是一个数组") if len(baidu_shop_ids) != len(shop_ids): raise EbaiClientException( errno=10000, errmsg="baidu_shop_ids 和 shop_ids数组个数不匹配") body = {'baidu_shop_ids': baidu_shop_ids, 'shop_ids': shop_ids} return self._post(cmd, **{'body': body})
def taking_limited(self, baidu_shop_id=None, shop_id=None, limit_data=[]): """ 设置门店限单值 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_limited_taking :param baidu_shop_id: 合作方门店ID :param shop_id: 平台门店ID :param limit_data: 限单时间和数量 startTime: 限单开始时间 endTime: 限单结束时间 order_limit_num: 该时间段内的限单数量 :return: """ cmd = 'order.limited.taking' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") body = { 'limit_data': limit_data, } if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def cancel_list(self, baidu_shop_id=None, shop_id=None, page=1): """ 获取未处理取消单/退单 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_cancellist :param baidu_shop_id: 平台门店ID :param shop_id: 合作方门店ID :param page: 查询页码,默认查询第一页 :return: """ cmd = 'order.cancellist' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") body = {'page': page} if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def _handle_result(self, res, method=None, result_processor=None, **kwargs): try: result = res.json() except (TypeError, ValueError): result = res if not isinstance(result, dict): return result result = result.get('body') if not isinstance(result, dict): return result if 'errno' in result: result['errno'] = int(result['errno']) if 'errno' in result and result['errno'] != 0: errno = result['errno'] errmsg = result.get('error', errno) raise EbaiClientException(errno, errmsg, client=self, request=res.request, response=res) return result if not result_processor else result_processor(result)
def get_status(self, baidu_shop_id=None, shop_id=None): """ 查看商户状态 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Shop-shop_status_get :param baidu_shop_id: 合作方门店ID :param shop_id: 平台门店ID :return: """ cmd = 'shop.status.get' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") body = {} if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def _request(self, method, **kwargs): key = {'get': 'params', 'post': 'data'}.get(method) cmd = kwargs.pop('cmd') body = kwargs.pop('body', {}) result_processor = kwargs.pop('result_processor', None) body = self.request_body(cmd, body) kwargs[key] = body res = self._http.request(method=method, url=self.API_BASE_URL, **kwargs) try: res.raise_for_status() except requests.RequestException as reqe: raise EbaiClientException(errno=None, errmsg=None, client=self, request=reqe.request, response=reqe.response) return self._handle_result(res, method, result_processor, **kwargs)
def get_busstatus(self, baidu_shop_id=None, shop_id=None, platform_flag=1): """ 查看商户的营业状态 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Shop-shop_busstatus_get :param baidu_shop_id: 合作方门店ID :param shop_id: 平台门店ID :param platform_flag: 来源平台,'1' 表示饿了么,'2' 表示饿了么星选 :return: """ cmd = 'shop.busstatus.get' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") body = { 'platformFlag': platform_flag, } if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def reply_remind(self, order_id, reply_type, reply_msg=None): """ 商户回复催单 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_remind_reply :param order_id: 订单ID :param reply_type: 商家回复催单类型(1 备货中、2 已送出、3 天气原因、6 自定义) :param reply_msg: 商家回复催单文案(回复内容不超过30个汉字,回复类别选择自定义,此项必传) :return: """ cmd = 'order.remind.reply' body = {'order_id': order_id, 'reply_type': reply_type} if reply_type == 6: if not reply_msg: raise EbaiClientException( errno=10000, errmsg="reply_type为自定义时,reply_msg不能为空") body['reply_msg'] = reply_msg return self._post(cmd, **{'body': body})
def batch_update_sku(self, activity_id, act_sku_info=[]): """ 批量更新活动商品 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Marketing-activity_sku_update_batch :param activity_id: 活动id :param act_sku_info: (数组)活动商品信息 baidu_shop_id: 平台门店id,与合作方门店id互斥 shop_id: 合作方门店id,与平台门店id互斥 sku_id: 商品id,与商品自定义id互斥 custom_sku_id: 商品自定义id,与商品id互斥 stock: 活动商品库存 store_user_limit: “店/人”:活动时间内,单商品在每个店铺中,每个用户可以购买的数量上限。 默认 0表示没有填(-1表示不限制),范围1~9999。现在只支持直降活动,满减不要填 special_price: 商品活动价,单位分 :return: """ cmd = 'activity.sku.update.batch' if not act_sku_info: raise EbaiClientException(errno=10000, errmsg="活动商品信息为空") body = {'activity_id': activity_id, 'act_sku_info': act_sku_info} return self._post(cmd, **{'body': body})
def get_remind(self, baidu_shop_id=None, shop_id=None, page=1, quantity=20): """ 获取商户未处理催单 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_remind_get :param baidu_shop_id: 合作方门店ID 可以和平台门店ID二选一 :param shop_id: 平台门店ID 可以和合作方门店ID二选一 :param page: 当前页(默认第一页) :param quantity: 每页显示条数(默认20条) :return: """ cmd = 'order.remind.get' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") body = {'page': page, 'quantity': quantity} if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def part_refund_untrelist(self, baidu_shop_id=None, shop_id=None, page=1): """ 获取未处理部分退单 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_partrefund_untrelist :param baidu_shop_id: 合作方门店ID,可以和平台门店ID二选一 :param shop_id: 平台门店ID,可以和合作方门店ID二选一 :param page: 平台门店ID,可以和合作方门店ID二选一 :return: """ cmd = 'order.partrefund.untrelist' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") body = {'page': page} if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def set_announcement(self, baidu_shop_id=None, shop_id=None, content=None, descritption=None): """ 设置商户公告 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Shop-shop_announcement_set :param baidu_shop_id: `可选`平台门店ID,与shop_id二选一 :param shop_id: `可选`合作方门店ID,与平台门店ID二选一 :param content: 内容 :param descritption: 简介,仅饿了么前端展示使用 :return: """ cmd = 'shop.announcement.set' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") if content is None: raise EbaiClientException(errno=10000, errmsg="内容不能为空") body = {'content': content} if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id if descritption: body['descritption'] = descritption return self._post(cmd, **{'body': body})
def batch_add_ns1_sku(self, sku_info=[]): """ N选1批量添加活动商品 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Marketing-activity_ns1_sku_add_batch :param sku_info: (数组)活动商品信息 :return: """ cmd = 'activity.ns1.sku.add.batch' if not sku_info: raise EbaiClientException(errno=10000, errmsg="活动商品信息为空") body = {'skuInfo': sku_info} return self._post(cmd, **{'body': body})
def get_claim(self, order_ids=[]): """ 批量查询订单索赔结果 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_claim_get :param order_ids: 订单ID数组 :return: """ cmd = 'order.claim.get' if not order_ids: raise EbaiClientException(errno=10000, errmsg="订单号为空") body = {'order_ids': order_ids} return self._post(cmd, **{'body': body})
def apply_claim(self, claim_list=[]): """ 批量发起订单索赔 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_claim_apply :param claim_list: (数组)索赔订单信息列表 order_id: 订单ID claim_reason: 索赔原因编码,使用通过order.claim.query获取的索赔原因编码,任选其一即可 reason_detail: 填写的附加额外信息 :return: """ cmd = 'order.claim.apply' if not claim_list: raise EbaiClientException(errno=10000, errmsg="索赔订单信息列表为空") body = {'claim_list': claim_list} return self._post(cmd, **{'body': body})
def _on_offline(self, cmd, shop_id, **kwargs): body = {'shop_id': shop_id} sku_id = kwargs.pop('sku_id', None) upc = kwargs.pop('upc', None) custom_sku_id = kwargs.pop('custom_sku_id', None) if not (sku_id and upc and custom_sku_id): raise EbaiClientException( errno=1, errmsg='缺少参数sku_id/upc/custom_sku_id 三选一') if sku_id: body['sku_id'] = sku_id elif upc: body['upc'] = upc elif custom_sku_id: body['custom_sku_id'] = custom_sku_id return self._post(cmd, **{'body': body})
def get_aptitude(self, baidu_shop_id=None, shop_id=None): """ 获取商户资质 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Shop-shop_aptitude_get :param baidu_shop_id: `可选`平台门店ID,与shop_id二选一 :param shop_id: `可选`合作方门店ID,与平台门店ID二选一 :return: """ cmd = 'shop.aptitude.get' if baidu_shop_id is None and shop_id is None: raise EbaiClientException(errno=10000, errmsg="平台门店ID,与shop_id二选一") body = {} if baidu_shop_id: body['baidu_shop_id'] = baidu_shop_id elif shop_id: body['shop_id'] = shop_id return self._post(cmd, **{'body': body})
def part_refund(self, order_id, products=[]): """ 商户发起部分退款申请 详情请参考 https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_partrefund :param order_id: 订单ID :param products: 申请退款的商品信息 sku_id: 商品的sku码,和upc,custom_sku_id三选一 upc: 商品的upc编码,和sku_id,custom_sku_id三选一 custom_sku_id: 商品的自定义编码ID,和sku_id,upc三选一 number: 退款的该商品数量 :return: """ cmd = 'order.partrefund' if not products: raise EbaiClientException(errno=10000, errmsg="申请退款的商品信息为空") body = {'order_id': order_id, 'products': products} return self._post(cmd, **{'body': body})