- A+
所属分类:编程语言
最近看到如下需求,和目前正在做的千牛批量处理比较类似,目前已经解决了无限账号登陆统一管理的问题,批量上下架宝贝的问题等。调查一下是否需求比较大,有大量需求的话和站长联系具体开发细节和功能需求,微信ak476118
展开
- class TBApi(TBCore):
- def search_order(self,orderId='3849201972101364512'):
- url = 'https://trade.taobao.com/trade/itemlist/asyncSold.htm'
- headers = {
- 'Referer': 'https://qn.taobao.com/',
- 'Accept': '*/*',
- 'Connection': 'keep-alive',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 SE 2.X MetaSr 1.0',
- }
- params = {
- 'event_submit_do_query': '1',
- '_input_charset': 'utf8',
- }
- data = {
- 'prePageNo': '1',
- 'sifg': '0',
- 'action': 'itemlist/SoldQueryAction',
- 'tabCode': 'latest3Months',
- 'buyerNick': '',
- 'dateBegin': 'NaN',
- 'dateEnd': 'NaN',
- 'orderStatus': 'ALL',
- 'rateStatus': 'ALL',
- 'pageSize': '15',
- 'rxOldFlag': '0',
- 'rxSendFlag': '0',
- 'useCheckcode': 'false',
- 'tradeTag': '0',
- 'rxHasSendFlag': '0',
- 'auctionType': '0',
- 'close': '0',
- 'sellerNick': '',
- 'notifySendGoodsType': 'ALL',
- 'sellerMemoFlag': '0',
- 'useOrderInfo': 'false',
- 'logisticsService': 'ALL',
- 'isQnNew': 'true',
- 'pageNum': '1',
- 'o2oDeliveryType': 'ALL',
- 'rxAuditFlag': '0',
- 'queryOrder': 'desc',
- 'holdStatus': '0',
- 'rxElectronicAuditFlag': '0',
- 'queryMore': 'false',
- 'rxWaitSendflag': '0',
- 'sellerMemo': '0',
- 'rxElectronicAllFlag': '0',
- 'rxSuccessflag': '0',
- 'refund': 'ALL',
- 'errorCheckcode': 'false',
- 'mailNo': '',
- 'yushouStatus': 'ALL',
- 'orderType': 'ALL',
- 'deliveryTimeType': 'ALL',
- 'queryTag': '',
- 'orderId': orderId,
- 'buyerEncodeId': '',
- 'isHideNick': 'true',
- }
- req = self.session.post(url,params=params,data=data,headers=headers)
- mainOrders = req.json().get('mainOrders')
- pprint(mainOrders)
- return req
- def query_sold_item_list(self,orderStatus='PAID'):
- """
- 订单查询处理,#如果不要该参数表示获取所有订单包括已经完成的 关闭的订单DROP,成功的订单SUCCESS,待发货的订单PAID,已发货SEND,等待付款的NOT_PAID
- 获取三个月内的订单信息
- tabCode: before3Months 三月前的订单 rateStatus:"" orderStatus: ""
- tabCode: deliveryHadTimeOut 已过时订单
- tabCode: waitSend 等待发货
- :return:
- """
- url = 'https://trade.taobao.com/trade/itemlist/asyncSold.htm'
- headers = {
- 'Referer': 'https://qn.taobao.com/',
- # 'Referer': 'https://trade.taobao.com/trade/itemlist/asyncSold.htm?event_submit_do_query=1&_input_charset=gbk&sifg=1',
- 'Accept': '*/*',
- 'Connection': 'keep-alive',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 SE 2.X MetaSr 1.0',
- }
- params = {
- 'event_submit_do_query': '1',
- '_input_charset': 'utf8',
- }
- data = {
- 'action':'itemlist/SoldQueryAction',
- 'actionType':0,
- 'close':0,
- 'pageNum':1,
- 'pageSize':15,
- 'queryMore':False,
- 'showQueryTag':True,
- 'tradeTag':0,
- 'useOrderInfo':False,
- 'orderStatus':orderStatus,
- 'prePageNo':1,
- }
- req = self.session.post(url,params=params,data=data,headers=headers)
- data = req.json().get("mainOrders")
- pprint(data)
- req = self.session.get('https://wuliu.taobao.com/user/order_list_new.htm?order_status_show=send')
- print(req.text)
- # <a class="btn" href="//wuliu.taobao.com/user/consign.htm?order_id=643946624243">发货</a> 要加一个old=1&
- #get请求直接确认发货 https://wuliu.taobao.com/user/order_detail_old.htm?order_id=643946624243&show_menu_in_detail=true&change_result=true
- return req
- def memo_order_sold(self,orderId="3849201972101364512"):
- """
- 查询订单的注释信息
- :param orderId:
- :return:
- """
- api = 'mtop.com.taobao.order.sold.memo'
- body = json.dumps({"operation":"queryMemo","orderId":orderId}) #orderId"3849201972101364512"
- response = self._h5request(api, body)
- pprint(response.json())
- return response
- def update_memo_order_sold(self,orderId="3853424016200364512",flagId='4',memoContent='备注33333'):
- """
- 设置订单备注信息
- :param orderId:
- operation:batchUpdate 批量标注则在batchOrderIdList中写订单编码
- :return:
- """
- api = 'mtop.com.taobao.order.sold.memo'
- body = json.dumps({"operation":"update","orderId":orderId,"params":json.dumps({"flagId":flagId,"flagTag":"","memoContent":memoContent,"tagToUpdateGlobal":"[]","batchOrderIdList":"[]"})}) #orderId"3849201972101364512"
- response = self._h5request(api, body)
- pprint(response.json())
- return response
- def soldop_trade(self,orderId="3853424016200364512"):
- """
- 关闭订单
- :param orderId:
- operation:batchUpdate 批量标注则在batchOrderIdList中写订单编码
- :return:
- """
- api = 'mtop.taobao.trade.soldop'
- body = json.dumps({"paramMap":json.dumps({"closeReason":"买家信息填写错误,重新拍"}),"orderId":orderId,"code":"closeOrder","terminalType":"pc"}) #orderId"3849201972101364512"
- response = self._h5request(api, body)
- pprint(response.json())
- return response
- def get_shop_info(self):
- """
- 获取店铺信息
- :return:
- """
- api = 'mtop.taobao.jdy.resource.shop.info.get'
- body = json.dumps({})
- response = self._h5request(api, body)
- self._parse_h5_res(response)
- return response
- def donate_goodsseller_projectlist(self):
- """
- 获取公益捐赠项目
- :return:
- """
- api = 'mtop.taobao.csr.donate.goodsseller.projectlist'
- body = json.dumps({"projectCodeList":[]})
- response = self._h5request(api, exparams=body)
- print(json.loads(response.text))
- # self._parse_h5_res(response)
- return response
- def set_csr_goods(self,IDs=["784380895646"]):
- """
- {"donateMode":0,"donateProjectCode":"d126578e45a44d09b0493258c88c2b61","csrProceed":true,"wholeShop":false,"itemIdList":"[\"780186781933\"]","showCsrDetail":true}
- :return:
- """
- # IDs = ["780445794088","780186781933"]
- api = 'mtop.taobao.csr.donate.goodsseller.setCsrGoods'
- exparams = json.dumps({"donateMode":0,"donateProjectCode":"d126578e45a44d09b0493258c88c2b61","csrProceed":True,"wholeShop":False,"itemIdList":json.dumps(IDs),"showCsrDetail":True})
- # exparams = '{"donateMode":0,"donateProjectCode":"d126578e45a44d09b0493258c88c2b61","csrProceed":true,"wholeShop":false,"itemIdList":"[\"780445794088\"]","showCsrDetail":true}'
- response = self._h5request(api, exparams=exparams)
- data = json.loads(response.text)
- # self._parse_h5_res(response)
- return response
- def cancel_csr_goods(self,IDs=["784380895646"]):
- """
- 获取店铺信息
- :return:
- """
- # IDs = ["780445794088","780186781933"]
- api = 'mtop.taobao.csr.donate.goodsseller.cancelSetCsrGoods'
- body = json.dumps({"wholeShop":False,"itemIdList":json.dumps(IDs)})
- response = self._h5request(api, exparams=body)
- data = json.loads(response.text)
- # self._parse_h5_res(response)
- return response
- def fast_edit_sell(self,itemId='780445794088',optType='downShelf'):
- """
- 快速管理商品的上架、下架、删除
- 上架商品optType=upShelf
- 批量上架商品optType=batchUpShelf {"itemId":[itemId,itemId],"auctionids":[itemId,itemId]}
- 下架商品optType=downShelf
- 删除商品optType=deleteItem
- 恢复商品optType=recycleItem
- :return:
- """
- api = 'mtop.taobao.sell.pc.manage.async'
- if optType in ['upShelf','downShelf','deleteItem']:
- data = {"itemId":itemId}
- elif optType in ['batchUpShelf','batchDownShelf','batchDeleteItem']:
- if isinstance(itemId,str):
- itemId = [itemId]
- if not isinstance(itemId,list):
- return '商品编码格式不正确!'
- data = {"itemId":itemId,"auctionids":itemId}
- elif optType in ['recycleItem']:
- if isinstance(itemId,str):
- itemId = [itemId]
- data = {"reasonSelect":{"value":"-1","text":"其他"},"itemId":itemId,"auctionids":itemId}
- else:
- data = {"itemId": itemId}
- body = json.dumps({'url': f'/taobao/manager/fastEdit.htm?optType={optType}&action=submit', 'jsonBody': json.dumps(data)})
- response = self._h5request(api, body)
- self._parse_h5_res(response)
- # pprint(result.get('data',{}).get('table',{}).get('dataSource'))
- # print(result.get('dataSource'))
- return response
- def taobao_manager_table(self,tabtype='all',filter_type={},table_type={}):
- """
- tabtype='all' 全部商品,包括出售中,仓库中的,
- tabtype='on_sale' 在售
- tabtype='in_stock' 仓库中
- tabtype='rubbish' 回收站中的
- tabtype='draft' 草稿箱中的
- unsalable #滞销下架
- history #历史的商品
- failed #违规的
- 后去商品数据,在售数据等
- # filter_type = {} #商品搜索
- # filter_type.update({"queryTitle":queryTitle}) #标题
- # filter_type.update({"queryItemId":queryItemId}) #商品id
- # filter_type.update({"queryOuterId":queryOuterId}) #商家编码
- # filter_type.update({"queryShopCategoryId":queryShopCategoryId}) #店铺分类
- # filter_type.update({"querySkuOuterId":querySkuOuterId}) #sku商家编码
- # table_type = {} #表格排序
- # table_type.update({"sort":{"soldQuantityPromotion":"desc"}})
- # \"sort\":{\"soldQuantityPromotion\":\"desc\"} 累积销量 asc
- #"sort\":{\"monthlySoldQuantity\":\"desc\"} 月销量
- :return:
- """
- api = 'mtop.taobao.sell.pc.manage.async'
- body = json.dumps({'url': '/taobao/manager/table.htm', 'jsonBody': json.dumps({"tab":tabtype,"pagination":{"current":1,"pageSize":20},"filter":filter_type,"table":table_type})})
- response = self._h5request(api, body)
- self._parse_h5_res(response)
- # data = response.json()
- # result = json.loads(data.get('data',{}).get('result','{}'))
- # pprint(result)
- # pprint(result.get('data',{}).get('table',{}).get('dataSource'))
- # print(result.get('dataSource'))
- return response
- def send_product(self):
- """
- 浏览物流列表,获取csrf
- 发货,可能需要先获取列表然后从cookie中获取'XSRF-TOKEN' 即是_csrf
- 首先根据订单号生成orderid 网址如下,请求后会注入csrf 同时返回参数信息
- https://wuliu2.taobao.com/user/consign.do?from=list¶ms=v3&tradeId=3853137024409364512
- :return:
- """
- url = 'https://wuliu2.taobao.com/user/do_consign.do'
- headers = {
- 'Referer': 'https://qn.taobao.com/',
- 'Accept': '*/*',
- 'Connection': 'keep-alive',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 SE 2.X MetaSr 1.0',
- }
- data = {
- '_csrf':self.session.cookies.get('XSRF-TOKEN',''), #'0bd944e8-8e07-4ad5-a47c-ed4e17af2b1b',
- 'params': json.dumps({}),
- 'type': '0',
- }
- # req = self.session.post(url,data=data,headers=headers)
- # mainOrders = req.json().get('mainOrders')
- # print(mainOrders)
- req = self.session.get('https://wuliu.taobao.com/user/order_detail_old.htm?order_id=644456868389&show_menu_in_detail=true&change_result=true')
- print(req.content)
- return req
- def query_order_list(self):
- """查询物流信息,待发货"""
- headers = {
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 SE 2.X MetaSr 1.0',
- 'referer': 'https://qn.taobao.com/',
- }
- params = {
- 'pageSize': '20',
- 'pageIndex': '1',
- 'listType': 'send',
- 'orderType': '-1',
- }
- response = self.session.get('https://wuliu2.taobao.com/user/queryOrderList', params=params, headers=headers)
- pprint(response.json())
- if __name__ == '__main__':
- tbapi = TBApi()
- tbapi.get_shop_info()
- tbapi.query_order_list()
- tbapi.memo_order_sold()
- tbapi.taobao_manager_table(tabtype='in_stock')
- tbapi.fast_edit_sell(itemId='780445794088',optType='downShelf')
- tbapi.query_sold_item_list()
- tbapi.send_product()
- tbapi.donate_goodsseller_projectlist()
- tbapi.set_csr_goods()
- tbapi.cancel_csr_goods()
现在需要有一个后台 我能批量控制其他几百家或者上千家的淘宝店铺 批量删除或者上下架符合我要求的宝贝,比如关键词,上架时间,销量等,还需要能批量设置优惠券 和一些简单的功能比如(退货地址,店铺信息,子账号权限) 能减少人工重复操作的流程。
我们有多个淘宝店铺,目前正在使用千牛平台进行店铺的管理,包括日常的商品管理、订单管理、活动设置等等。
那么目前的需求则有:
1)、希望开发一个本地软件系统,能绑定多个淘宝店铺,无限制
2)、可以根据商品标题关键词检索勾选所有店铺或者要处理的多个店铺,进行商品的批量删除,批量下架操作,不需要每个店铺操作
3)、也可以批量一次设置多个店铺优惠券,营销宝
4.可以共享云违规功能(比如A店铺店铺出现某个违规 其他店铺会自动排查这个宝贝进行删除)
我的微信公众号
爱真理,得永生! 爱在灵灵久博客,网罗天下,福利大家!