首页 > 其他分享 >抖音 校验库存 转单版

抖音 校验库存 转单版

时间:2022-12-03 18:47:20浏览次数:43  
标签:抖音 name sp 校验 转单 https owner com id

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

相关文章

  • 最新抖音Clickid和拼多多/京东/小程序-APP内下单转化回传对接程序实现-规避淘宝回传各
    在最近几个月时间里,抖音Clickid回传淘宝APP内下单的两种技术方案①淘宝联盟方案CID+RID技术方案;②淘宝小程序方案CID+小程序跳转。被淘宝官方日益严厉打压的情况下,具体表现......
  • golang校验结构体字段的库validator的使用
    packagescripts_stroageimport("fmt""github.com/go-playground/validator/v10""testing")//参考博客://https://juejin.cn/post/69003756803582......
  • C# CRC16数据校验支持ModelBus和XMODEM校验模式
    C#CRC16数据校验支持ModelBus和XMODEM校验模式最近在研究C#CRC数据校验规则,之前用过ModelBus模式,但是这次的现场用到的是XMODEM模式,写一篇文章记录实现细节,方便后期快速开......
  • 剑指offer:翻转单词顺序列
    题目描述牛客最近来了一个新员工Fish,每天早晨总是会拿着一本英文杂志,写些句子在本子上。同事Cat对Fish写的内容颇感兴趣,有一天他向Fish借来翻看,但却读不懂它的意思。例如,“s......
  • (笔记)VHDL/Verilog之CRC(循环冗余校验)计算
     背景:我们在使用VHDL或Verilog进行FPGA开发时,经常会遇到CRC校验计算的情况,如校验公式为:G(x)=X8+X4+X3+X2+1G(x)=X3+X+1 那使用VHDL或Verilog语言该如何......
  • SAP ABAP ABVAN保存校验增强
    增强点:CL_FAA_BF_PAR_VAL_ACTIVATION 1IFsy-tcode='ABAVN'ORsy-ucomm='SAVE'.2ASSIGN('(SAPLAMDPS2I)RAIFP2-BUKRS')TO<fs_bukrs>.3IF<fs_buk......
  • SpringBoot参数校验
    1.前言因为网络传输的不可靠性,以及前端数据控制的可篡改性,后端的参数校验是必须的,应用程序必须通过某种手段来确保输入进来的数据从语义上来讲是正确的。2.数据校验的......
  • Dubbo RPC基于Filter的自定义参数校验
    在web应用中,我们经常使用注解的方式来校验参数,使得业务开发不用过分关注参数校验的逻辑但是在现有的微服务架构中,常常只是作为一个服务提供rpc服务的方式,那是不是还是退......
  • python-反反爬抖音(绕过抖音登录与新手引导)
    """反反爬--driver.get(网页)--人工登录后关闭程序--driver.get(网页)"""#1.普通浏览器:不能记录登录信息,容易触发反爬机制#fr......
  • 身份证校验
    staticstringTestCardId(stringcardId){stringpattern=@"^\d{17}(?:\d|X)$";stringbirth=cardId.Substring(6,8).Insert(6......