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 = {
'username': "xujingfei",
'password': "Xjf2567483"
}
# 登录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': "serial_number", 'keyword': "SO-20221201-1859585877"},
{'fieldToFilter': "type", 'keyword': "1"},
{'fieldToFilter': "warehouse_ids", 'keyword': f"{warehouse_id}"},
{'fieldToFilter': "created_time_start",
'keyword': "2022-10-01T00: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':
k = {}
sieve = re.match('良品临期|良品过期|良品正常效期',sieveName)
sieve =sieve.group()
k[f'{code+owner_id+owner_name+sieve}'] = expectedQuantity
# info = (warehouse, type, serialNumber, status, code, sp_name,owner_id,owner_name, sp_id,sieve, int(expectedQuantity), name,
# poiAddress, relatedSerialNumber, ordertype, k[f'{code+owner_id+owner_name+sieve}'] )
# ws.append(info)
# 进入库存校验
inventory = 'https://titan-api.xtw-tech.com/v1/inventory/list'
header ={
'authority': 'titan-api.xtw-tech.com',
'method': 'POST',
'path': '/v1/inventory/list',
'scheme': 'https',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'content-length': '519',
'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',
}
data ={'tenantId': "1", 'listOption': {'page': '1', 'pageSize': '100', 'keyword': "",'fieldFilter':[{'fieldToFilter': "no_virtual_location", 'keyword': "1"},
{'fieldToFilter': "only_no_lot", 'keyword': "0"},{'fieldToFilter': "sp_code", 'keyword': f"{code}"},
{'fieldToFilter': "inventory_scrap_type", 'keyword': "normal"},{'fieldToFilter': "is_show_invalid", 'keyword': "1"},
{'fieldToFilter': "no_zero_inventory", 'keyword': "1"},
{'fieldToFilter': "warehouse_ids", 'keyword': "137"}],'sortBy': {'fieldToSort': "created_at", 'direction': "DESCENDING"}}}
req_inventory = session_wms.post(json=data,url=inventory,headers=header)
items = req_inventory.json()['items']
# sp_quantity ={'良品临期':0,'良品过期':0,'良品正常效期':0}
sp_quantity ={}
for i in items:
owner_id_1 = i['owner']['id']
owner_name_1 = i['owner']['name']
quantity = i['quantity']
lotEnabled = i['lotEnabled']
if lotEnabled:
locationType= i['location']['locationType']
# sp_quantity['sieveName'] =locationType
else:
locationType ='LOCATION_TYPE_NORMAL'
# sp 货主 数量 库存类型
# sp_quantity['sp']=code
# sp_quantity['owner_id'] =owner_id_1
# sp_quantity['owner_name'] =owner_name_1
# sp_quantity['quantity'] =quantity
# sp_quantity['sieveName'] =logo[locationType]
# print(str(code+owner_name_1+logo[locationType]),sp_quantity.keys())
if str(code+owner_name_1+logo[locationType]) in sp_quantity.keys():
sp_quantity[f'{code+owner_name_1+logo[locationType]}'] +=int(quantity)
else:
sp_quantity[f'{code+owner_name_1+logo[locationType]}']=int(quantity)
# 这里 应该判断相同库存类型:
# 需要考虑一张订单有多个sp需要校验库存
if str(code+owner_name+sieve) in sp_quantity.keys():
if int(sp_quantity[f'{code+owner_name_1+logo[locationType]}']) >=int(k[f'{code+owner_id+owner_name+sieve}']):
sp_num =0
print('该sp库存足够')
else:
sp_num+=1
print('部分库存可供货,可以考虑转单')
info = (warehouse, type, serialNumber, status, code, sp_name,owner_id,owner_name, sp_id,sieve, int(expectedQuantity), name,
poiAddress, relatedSerialNumber, ordertype, k[f'{code+owner_id+owner_name+sieve}'] ,int(sp_quantity[f'{code+owner_name_1+logo[locationType]}']) )
ws.append(info)
else:
sp_num+=1
print("对应0库存,可以考虑转单")
if sp_num>=1:
# 进入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
wb.save('/Users/xujingfei/Desktop/xtw.xlsx')
# -----------------------------------------------------------------------------------------------------------------
标签:抖音,name,sp,校验,转单,https,owner,com,id
From: https://www.cnblogs.com/ivan09/p/16948548.html