抖音强制转单 -版本

import requests as req
from openpyxl import Workbook
import re

session_wms = req.Session()
login_url = "https://apollo-api.xtw-tech.com/v1/auth/token"
# 请求头文件Request Headers
headers = {
    # 'accept': 'application/json, text/plain, */*',
    # 'accept-encoding': 'gzip, deflate, br',
    # 'accept-language': 'zh-CN,zh;q=0.9',
    # 'content-length': '46',
    # 'content-type': 'application/json',
    'grpc-metadata-application-code': 'VENUS',
    # 'grpc-metadata-user-auth-token': 'null',
    'origin': 'https://venus.xtw-tech.com',
    'referer': 'https://venus.xtw-tech.com',
    # 'sec-fetch-mode': 'cors',
    # 'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36'
}

# 登陆wms
data = {

}

# 登录wms
response_wms = session_wms.post(url=login_url, headers=headers, json=data)

wb = Workbook()
ws = wb.active
# title = ['发货仓', '订单类型', '发货单号', '发货单号状态', 'SP', '品名', '货主id','货主','sp_map_id','库存类型', '数量', '客户名', '下单地址', '订单号', '订单渠道','需求','良品临期','良品过期','良品正常效期']
title = ['发货仓', '订单类型', '发货单号', '发货单号状态', 'SP', '品名', '货主id','货主','sp_map_id','库存类型', '数量', '客户名', '下单地址', '订单号', '订单渠道','需求']

ws.append(title)

solist = 'https://titan-api.xtw-tech.com/v1/shipment_order/list'
header = {
    'authority': 'titan-api.xtw-tech.com',
    'method': 'POST',
    'path': '/v1/shipment_order/list',
    'scheme': 'https',
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9',
    'content-length': '295',
    'content-type': 'application/json',
    'grpc-metadata-application-code': 'MERCURY',
    'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
    'origin': 'https://mercury.xtw-tech.com',
    'referer': 'https://mercury.xtw-tech.com/',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
tenantIds = ['1']
warehouse_ids = ['137']

for tenantId, warehouse_id in zip(tenantIds, warehouse_ids):
    # for tenantId in tenantIds:
    for page in range(1):
        data = {'tenantId': f"{tenantId}", 'justShowMine': False,
                'listOption': {'keyword': "", 'page': f'{page + 1}', 'pageSize': '100',
                               'fieldFilter': [{'fieldToFilter': "show_crossowner", 'keyword': "false"},
                                               {'fieldToFilter': "status_list", 'keyword': "201"},
                                               {'fieldToFilter': "type", 'keyword': "1"},
                                               {'fieldToFilter': "warehouse_ids", 'keyword': f"{warehouse_id}"},
                                               {'fieldToFilter': "created_time_start",
                                                'keyword': "2022-11-29T00:00:00+08:00"},
                                               {'fieldToFilter': "created_time_end",
                                                'keyword': "2030-11-30T23:59:59+08:00"}]}
                }

        response = session_wms.post(headers=header, url=solist, json=data)
        item = response.json()['items']
        logo ={'LOCATION_TYPE_EXPIRED':'良品过期','LOCATION_TYPE_CLOSE_TO_EXPIRY':'良品临期','LOCATION_TYPE_NORMAL':'良品正常效期'}
        for i in item:
            name = i['consigneeInfo']['name']
            poiAddress = i['consigneeInfo']['poiAddress']
            relatedSerialNumber = i['relatedSerialNumber']
            ordertype = relatedSerialNumber.split('-')[3]
            relatedSerial = relatedSerialNumber.split('-')[2]
            status = i['status']
            type = i['type']
            serialNumber = i['serialNumber']
            warehouse = i['warehouse']['name']

            so_url = f'https://titan-api.xtw-tech.com/v1/shipment_order/by_serial_number/{serialNumber}?tenantId={tenantId}'
            header = {
                'authority': 'titan-api.xtw-tech.com',
                'method': 'GET',
                'path': f'/v1/shipment_order/by_serial_number/{serialNumber}?tenantId={tenantId}',
                'scheme': 'https',
                'accept': 'application/json, text/plain, */*',
                'accept-encoding': 'gzip, deflate, br',
                'grpc-metadata-application-code': 'MERCURY',
                'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
                'origin': 'https://mercury.xtw-tech.com',
                'referer': 'https://mercury.xtw-tech.com/',
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
            }
            deatil = session_wms.get(url=so_url, headers=header)
            req = deatil.json()
            shipmentOrderWithDetail = req['shipmentOrderWithDetail']['inventories']
            sp_num = 0
            for sp in shipmentOrderWithDetail:
                # ['发货仓','订单号','发货单号','发货单号状态','SP','品名','效期状态','数量','收货人','收货地址']
                sieveName = sp['sieveName']  # 有效期
                owner_id = sp['owner']['id']
                owner_name = sp['owner']['name']
                code = sp['standardProductTenantMapping']['standardProduct']['code']
                sp_name = sp['standardProductTenantMapping']['standardProduct']['name']
                sp_id = sp['standardProductTenantMapping']['id']
                expectedQuantity = sp['expectedQuantity']

                # 库存校验
                if ordertype =='11':
                    # 进入venus菜单系统
                    order_list = 'https://matrix-api.xtw-tech.com/v1/matrix/shop/query_conditions/list'
                    header ={
                        'authority': 'matrix-api.xtw-tech.com',
                        'method': 'GET',
                        'path': '/v1/matrix/shop/query_conditions/list',
                        'scheme': 'https',
                        'accept': 'application/json, text/plain, */*',
                        'accept-encoding': 'gzip, deflate, br',
                        'accept-language': 'zh-CN,zh;q=0.9',
                        'grpc-metadata-application-code': 'VENUS',
                        'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
                        'origin': 'https://venus.xtw-tech.com',
                        'referer': 'https://venus.xtw-tech.com/',
                        'sec-ch-ua-mobile': '?0',
                        'sec-ch-ua-platform': "Windows",
                        'sec-fetch-dest': 'empty',
                        'sec-fetch-mode': 'cors',
                        'sec-fetch-site': 'same-site',
                        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
                    }


                    id =relatedSerial
                    order =f'https://fz.baiou-tech.com:8080/manager/orders?platform_order_id={id}&page=1&page_size=10'
                    header={
                        'authority': 'fz.baiou-tech.com:8080',
                        'method': 'GET',
                        'path': f'/manager/orders?platform_order_id={id}&page=1&page_size=10',
                        'scheme': 'https',
                        'accept': 'application/json, text/plain, */*',
                        'accept-encoding': 'gzip, deflate, br',
                        'accept-language': 'zh-CN,zh;q=0.9',
                        'grpc-metadata-application-code': 'VENUS',
                        'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
                        'origin': 'https://venus.xtw-tech.com',
                        'referer': 'https://venus.xtw-tech.com/',
                        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
                    }
                    response = session_wms.get(url=order,headers=header)
                    order_id = response.json()['data']['data'][0]['id']
                    warehouse =response.json()['data']['data'][0]['warehouse_name']

                    # 发起转单
                    transfer = 'https://fz.baiou-tech.com:8080/manager/order/transfer_order'
                    data = {'order_id': f'{order_id}', 'to_warehouse_id': '727'}
                    header={
                        'authority': 'fz.baiou-tech.com:8080',
                        'method': 'POST',
                        'path': '/manager/order/transfer_order',
                        'scheme': 'https',
                        'accept': 'application/json, text/plain, */*',
                        'accept-encoding': 'gzip, deflate, br',
                        'accept-language': 'zh-CN,zh;q=0.9',
                        'content-length': '42',
                        'content-type': 'application/json',
                        'grpc-metadata-application-code': 'VENUS',
                        'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
                        'origin': 'https://venus.xtw-tech.com',
                        'referer': 'https://venus.xtw-tech.com/',
                        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
                    }
                    trans = session_wms.post(url=transfer,headers=header,json=data)
                    if trans.status_code == '200':
                        print('转单成功')
                    else:
                        pass
                else:
                    pass

# -----------------------------------------------------------------------------------------------------------------



posted @ 2022-12-03 18:34  烦恼1234  阅读(67)  评论(0)    收藏  举报