本地端群控千牛批量删除或上下架符合关键词的宝贝

  • A+
所属分类:编程语言

最近看到如下需求,和目前正在做的千牛批量处理比较类似,目前已经解决了无限账号登陆统一管理的问题,批量上下架宝贝的问题等。调查一下是否需求比较大,有大量需求的话和站长联系具体开发细节和功能需求,微信ak476118 

展开

  1. class TBApi(TBCore):
  2.     def search_order(self,orderId='3849201972101364512'):
  3.         url = 'https://trade.taobao.com/trade/itemlist/asyncSold.htm'
  4.         headers = {
  5.             'Referer': 'https://qn.taobao.com/',
  6.             'Accept': '*/*',
  7.             'Connection': 'keep-alive',
  8.             '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',
  9.         }
  10.         params = {
  11.             'event_submit_do_query': '1',
  12.             '_input_charset': 'utf8',
  13.         }
  14.         data = {
  15.             'prePageNo': '1',
  16.             'sifg': '0',
  17.             'action': 'itemlist/SoldQueryAction',
  18.             'tabCode': 'latest3Months',
  19.             'buyerNick': '',
  20.             'dateBegin': 'NaN',
  21.             'dateEnd': 'NaN',
  22.             'orderStatus': 'ALL',
  23.             'rateStatus': 'ALL',
  24.             'pageSize': '15',
  25.             'rxOldFlag': '0',
  26.             'rxSendFlag': '0',
  27.             'useCheckcode': 'false',
  28.             'tradeTag': '0',
  29.             'rxHasSendFlag': '0',
  30.             'auctionType': '0',
  31.             'close': '0',
  32.             'sellerNick': '',
  33.             'notifySendGoodsType': 'ALL',
  34.             'sellerMemoFlag': '0',
  35.             'useOrderInfo': 'false',
  36.             'logisticsService': 'ALL',
  37.             'isQnNew': 'true',
  38.             'pageNum': '1',
  39.             'o2oDeliveryType': 'ALL',
  40.             'rxAuditFlag': '0',
  41.             'queryOrder': 'desc',
  42.             'holdStatus': '0',
  43.             'rxElectronicAuditFlag': '0',
  44.             'queryMore': 'false',
  45.             'rxWaitSendflag': '0',
  46.             'sellerMemo': '0',
  47.             'rxElectronicAllFlag': '0',
  48.             'rxSuccessflag': '0',
  49.             'refund': 'ALL',
  50.             'errorCheckcode': 'false',
  51.             'mailNo': '',
  52.             'yushouStatus': 'ALL',
  53.             'orderType': 'ALL',
  54.             'deliveryTimeType': 'ALL',
  55.             'queryTag': '',
  56.             'orderId': orderId,
  57.             'buyerEncodeId': '',
  58.             'isHideNick': 'true',
  59.         }
  60.         req = self.session.post(url,params=params,data=data,headers=headers)
  61.         mainOrders = req.json().get('mainOrders')
  62.         pprint(mainOrders)
  63.         return req
  64.     def query_sold_item_list(self,orderStatus='PAID'):
  65.         """
  66.         订单查询处理,#如果不要该参数表示获取所有订单包括已经完成的 关闭的订单DROP,成功的订单SUCCESS,待发货的订单PAID,已发货SEND,等待付款的NOT_PAID
  67.         获取三个月内的订单信息
  68.         tabCode: before3Months 三月前的订单 rateStatus:"" orderStatus: ""
  69.         tabCode: deliveryHadTimeOut 已过时订单
  70.         tabCode: waitSend 等待发货
  71.         :return:
  72.         """
  73.         url = 'https://trade.taobao.com/trade/itemlist/asyncSold.htm'
  74.         headers = {
  75.             'Referer': 'https://qn.taobao.com/',
  76.             #     'Referer': 'https://trade.taobao.com/trade/itemlist/asyncSold.htm?event_submit_do_query=1&_input_charset=gbk&sifg=1',
  77.             'Accept': '*/*',
  78.             'Connection': 'keep-alive',
  79.             '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',
  80.         }
  81.         params = {
  82.             'event_submit_do_query': '1',
  83.             '_input_charset': 'utf8',
  84.         }
  85.         data = {
  86.             'action':'itemlist/SoldQueryAction',
  87.             'actionType':0,
  88.             'close':0,
  89.             'pageNum':1,
  90.             'pageSize':15,
  91.             'queryMore':False,
  92.             'showQueryTag':True,
  93.             'tradeTag':0,
  94.             'useOrderInfo':False,
  95.             'orderStatus':orderStatus,
  96.             'prePageNo':1,
  97.         }
  98.         req = self.session.post(url,params=params,data=data,headers=headers)
  99.         data = req.json().get("mainOrders")
  100.         pprint(data)
  101.         req = self.session.get('https://wuliu.taobao.com/user/order_list_new.htm?order_status_show=send')
  102.         print(req.text)
  103.         # <a class="btn" href="//wuliu.taobao.com/user/consign.htm?order_id=643946624243">发货</a> 要加一个old=1&
  104.         #get请求直接确认发货 https://wuliu.taobao.com/user/order_detail_old.htm?order_id=643946624243&show_menu_in_detail=true&change_result=true
  105.         return req
  106.     def memo_order_sold(self,orderId="3849201972101364512"):
  107.         """
  108.         查询订单的注释信息
  109.         :param orderId:
  110.         :return:
  111.         """
  112.         api = 'mtop.com.taobao.order.sold.memo'
  113.         body = json.dumps({"operation":"queryMemo","orderId":orderId}) #orderId"3849201972101364512"
  114.         response = self._h5request(api, body)
  115.         pprint(response.json())
  116.         return response
  117.     def update_memo_order_sold(self,orderId="3853424016200364512",flagId='4',memoContent='备注33333'):
  118.         """
  119.         设置订单备注信息
  120.         :param orderId:
  121.         operation:batchUpdate 批量标注则在batchOrderIdList中写订单编码
  122.         :return:
  123.         """
  124.         api = 'mtop.com.taobao.order.sold.memo'
  125.         body = json.dumps({"operation":"update","orderId":orderId,"params":json.dumps({"flagId":flagId,"flagTag":"","memoContent":memoContent,"tagToUpdateGlobal":"[]","batchOrderIdList":"[]"})}) #orderId"3849201972101364512"
  126.         response = self._h5request(api, body)
  127.         pprint(response.json())
  128.         return response
  129.     def soldop_trade(self,orderId="3853424016200364512"):
  130.         """
  131.         关闭订单
  132.         :param orderId:
  133.         operation:batchUpdate 批量标注则在batchOrderIdList中写订单编码
  134.         :return:
  135.         """
  136.         api = 'mtop.taobao.trade.soldop'
  137.         body = json.dumps({"paramMap":json.dumps({"closeReason":"买家信息填写错误,重新拍"}),"orderId":orderId,"code":"closeOrder","terminalType":"pc"}) #orderId"3849201972101364512"
  138.         response = self._h5request(api, body)
  139.         pprint(response.json())
  140.         return response
  141.     def get_shop_info(self):
  142.         """
  143.         获取店铺信息
  144.         :return:
  145.         """
  146.         api = 'mtop.taobao.jdy.resource.shop.info.get'
  147.         body = json.dumps({})
  148.         response = self._h5request(api, body)
  149.         self._parse_h5_res(response)
  150.         return response
  151.     def donate_goodsseller_projectlist(self):
  152.         """
  153.         获取公益捐赠项目
  154.         :return:
  155.         """
  156.         api = 'mtop.taobao.csr.donate.goodsseller.projectlist'
  157.         body = json.dumps({"projectCodeList":[]})
  158.         response = self._h5request(api, exparams=body)
  159.         print(json.loads(response.text))
  160.         # self._parse_h5_res(response)
  161.         return response
  162.     def set_csr_goods(self,IDs=["784380895646"]):
  163.         """
  164.         {"donateMode":0,"donateProjectCode":"d126578e45a44d09b0493258c88c2b61","csrProceed":true,"wholeShop":false,"itemIdList":"[\"780186781933\"]","showCsrDetail":true}
  165.         :return:
  166.         """
  167.         # IDs = ["780445794088","780186781933"]
  168.         api = 'mtop.taobao.csr.donate.goodsseller.setCsrGoods'
  169.         exparams = json.dumps({"donateMode":0,"donateProjectCode":"d126578e45a44d09b0493258c88c2b61","csrProceed":True,"wholeShop":False,"itemIdList":json.dumps(IDs),"showCsrDetail":True})
  170.         # exparams = '{"donateMode":0,"donateProjectCode":"d126578e45a44d09b0493258c88c2b61","csrProceed":true,"wholeShop":false,"itemIdList":"[\"780445794088\"]","showCsrDetail":true}'
  171.         response = self._h5request(api, exparams=exparams)
  172.         data = json.loads(response.text)
  173.         # self._parse_h5_res(response)
  174.         return response
  175.     def cancel_csr_goods(self,IDs=["784380895646"]):
  176.         """
  177.         获取店铺信息
  178.         :return:
  179.         """
  180.         # IDs = ["780445794088","780186781933"]
  181.         api = 'mtop.taobao.csr.donate.goodsseller.cancelSetCsrGoods'
  182.         body = json.dumps({"wholeShop":False,"itemIdList":json.dumps(IDs)})
  183.         response = self._h5request(api, exparams=body)
  184.         data = json.loads(response.text)
  185.         # self._parse_h5_res(response)
  186.         return response
  187.     def fast_edit_sell(self,itemId='780445794088',optType='downShelf'):
  188.         """
  189.         快速管理商品的上架、下架、删除
  190.         上架商品optType=upShelf
  191.         批量上架商品optType=batchUpShelf  {"itemId":[itemId,itemId],"auctionids":[itemId,itemId]}
  192.         下架商品optType=downShelf
  193.         删除商品optType=deleteItem
  194.         恢复商品optType=recycleItem
  195.         :return:
  196.         """
  197.         api = 'mtop.taobao.sell.pc.manage.async'
  198.         if optType in ['upShelf','downShelf','deleteItem']:
  199.             data = {"itemId":itemId}
  200.         elif optType in ['batchUpShelf','batchDownShelf','batchDeleteItem']:
  201.             if isinstance(itemId,str):
  202.                 itemId = [itemId]
  203.             if not isinstance(itemId,list):
  204.                 return '商品编码格式不正确!'
  205.             data = {"itemId":itemId,"auctionids":itemId}
  206.         elif optType in ['recycleItem']:
  207.             if isinstance(itemId,str):
  208.                 itemId = [itemId]
  209.             data = {"reasonSelect":{"value":"-1","text":"其他"},"itemId":itemId,"auctionids":itemId}
  210.         else:
  211.             data = {"itemId": itemId}
  212.         body = json.dumps({'url': f'/taobao/manager/fastEdit.htm?optType={optType}&action=submit', 'jsonBody': json.dumps(data)})
  213.         response = self._h5request(api, body)
  214.         self._parse_h5_res(response)
  215.         # pprint(result.get('data',{}).get('table',{}).get('dataSource'))
  216.         # print(result.get('dataSource'))
  217.         return response
  218.     def taobao_manager_table(self,tabtype='all',filter_type={},table_type={}):
  219.         """
  220.         tabtype='all' 全部商品,包括出售中,仓库中的,
  221.         tabtype='on_sale' 在售
  222.         tabtype='in_stock' 仓库中
  223.         tabtype='rubbish' 回收站中的
  224.         tabtype='draft' 草稿箱中的
  225.         unsalable #滞销下架
  226.         history #历史的商品
  227.         failed #违规的
  228.         后去商品数据,在售数据等
  229.         # filter_type = {} #商品搜索
  230.         # filter_type.update({"queryTitle":queryTitle}) #标题
  231.         # filter_type.update({"queryItemId":queryItemId}) #商品id
  232.         # filter_type.update({"queryOuterId":queryOuterId}) #商家编码
  233.         # filter_type.update({"queryShopCategoryId":queryShopCategoryId}) #店铺分类
  234.         # filter_type.update({"querySkuOuterId":querySkuOuterId}) #sku商家编码
  235.         # table_type = {} #表格排序
  236.         # table_type.update({"sort":{"soldQuantityPromotion":"desc"}})
  237.         # \"sort\":{\"soldQuantityPromotion\":\"desc\"} 累积销量 asc
  238.         #"sort\":{\"monthlySoldQuantity\":\"desc\"} 月销量
  239.         :return:
  240.         """
  241.         api = 'mtop.taobao.sell.pc.manage.async'
  242.         body = json.dumps({'url': '/taobao/manager/table.htm', 'jsonBody': json.dumps({"tab":tabtype,"pagination":{"current":1,"pageSize":20},"filter":filter_type,"table":table_type})})
  243.         response = self._h5request(api, body)
  244.         self._parse_h5_res(response)
  245.         # data = response.json()
  246.         # result = json.loads(data.get('data',{}).get('result','{}'))
  247.         # pprint(result)
  248.         # pprint(result.get('data',{}).get('table',{}).get('dataSource'))
  249.         # print(result.get('dataSource'))
  250.         return response
  251.     def send_product(self):
  252.         """
  253.         浏览物流列表,获取csrf
  254.         发货,可能需要先获取列表然后从cookie中获取'XSRF-TOKEN' 即是_csrf
  255.         首先根据订单号生成orderid 网址如下,请求后会注入csrf 同时返回参数信息
  256.         https://wuliu2.taobao.com/user/consign.do?from=list&params=v3&tradeId=3853137024409364512
  257.         :return:
  258.         """
  259.         url = 'https://wuliu2.taobao.com/user/do_consign.do'
  260.         headers = {
  261.             'Referer': 'https://qn.taobao.com/',
  262.             'Accept': '*/*',
  263.             'Connection': 'keep-alive',
  264.             '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',
  265.         }
  266.         data = {
  267.             '_csrf':self.session.cookies.get('XSRF-TOKEN',''), #'0bd944e8-8e07-4ad5-a47c-ed4e17af2b1b',
  268.             'params': json.dumps({}),
  269.             'type': '0',
  270.         }
  271.         # req = self.session.post(url,data=data,headers=headers)
  272.         # mainOrders = req.json().get('mainOrders')
  273.         # print(mainOrders)
  274.         req = self.session.get('https://wuliu.taobao.com/user/order_detail_old.htm?order_id=644456868389&show_menu_in_detail=true&change_result=true')
  275.         print(req.content)
  276.         return req
  277.     def query_order_list(self):
  278.         """查询物流信息,待发货"""
  279.         headers = {
  280.             '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',
  281.             'referer': 'https://qn.taobao.com/',
  282.         }
  283.         params = {
  284.             'pageSize': '20',
  285.             'pageIndex': '1',
  286.             'listType': 'send',
  287.             'orderType': '-1',
  288.         }
  289.         response = self.session.get('https://wuliu2.taobao.com/user/queryOrderList', params=params, headers=headers)
  290.         pprint(response.json())
  291. if __name__ == '__main__':
  292.     tbapi = TBApi()
  293.     tbapi.get_shop_info()
  294.     tbapi.query_order_list()
  295.     tbapi.memo_order_sold()
  296.     tbapi.taobao_manager_table(tabtype='in_stock')
  297.     tbapi.fast_edit_sell(itemId='780445794088',optType='downShelf')
  298.     tbapi.query_sold_item_list()
  299.     tbapi.send_product()
  300.     tbapi.donate_goodsseller_projectlist()
  301.     tbapi.set_csr_goods()
  302.     tbapi.cancel_csr_goods()

千牛批量处理

现在需要有一个后台 我能批量控制其他几百家或者上千家的淘宝店铺 批量删除或者上下架符合我要求的宝贝,比如关键词,上架时间,销量等,还需要能批量设置优惠券 和一些简单的功能比如(退货地址,店铺信息,子账号权限) 能减少人工重复操作的流程。

我们有多个淘宝店铺,目前正在使用千牛平台进行店铺的管理,包括日常的商品管理、订单管理、活动设置等等。
那么目前的需求则有:

1)、希望开发一个本地软件系统,能绑定多个淘宝店铺,无限制
2)、可以根据商品标题关键词检索勾选所有店铺或者要处理的多个店铺,进行商品的批量删除,批量下架操作,不需要每个店铺操作
3)、也可以批量一次设置多个店铺优惠券,营销宝
4.可以共享云违规功能(比如A店铺店铺出现某个违规 其他店铺会自动排查这个宝贝进行删除)

 

weinxin
我的微信公众号
爱真理,得永生!          爱在灵灵久博客,网罗天下,福利大家!