加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo_1.py 3.93 KB
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2024-02-19 10:31 . init
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
# @Project : pythonProject
# @File : kai_dan_ming_xi_mu_ban
# @Date : 2023/12/21 15:49
# @Author : 徐胜虎
# @Email : 1813366784@qq.com
# @Software : PyCharm
-------------------------------------------------
输入文件 : 开单明细模板.xlsx ==收货报表.xlsx
输出文件 : 当前时间日期的开单明细模板.xlsx
"""
import math
import pandas as pd
import requests
from pandas import DataFrame
from utils import headers, params_login
param_cal_stand_freight = {
'billDeptId': '005223', # 武汉总部收货部 005223
'discDeptId': '004793',
'destDeptId': '',
'serviceType': 10101,
'itemQty': 1,
'itemKgs': 5400,
'itemCbm': 22,
# 'orderDate': datetime.now().timestamp().__int__() * 1000,
# 'isMutant': 0,
# 'terminal': 'PC',
# 'module': 'orderEditApplyDetails'
}
def cal_stand_freight(row_: DataFrame, headers_=None, ref_data_: dict = None, url_: str = None,
param_cal_stand_freight_=None):
if row_['到达部门'] == '':
return None
param_cal_stand_freight_['discDeptId'] = ref_data_[row_['到达部门']]
param_cal_stand_freight_['itemKgs'] = row_['重量']
param_cal_stand_freight_['itemCbm'] = row_['体积']
response_ = requests.post(url_, data=param_cal_stand_freight_, headers=headers_).json()
if response_['code'] == '200':
return math.ceil(response_['rows']['standardFreight'])
else:
return None
def cal_ti_fu_amount(row_: DataFrame, insured_fee=1):
if row_['运费结算方式'] == '提付':
# 忽略转出费
return row_['费用合计'] - row_['送货费'] - insured_fee - row_['回单费']
else:
return None
if __name__ == '__main__':
url = "https://hdd.hddky.com/tms-hdd/token/login"
response = requests.post(url, data=params_login, headers=headers).json()
headers['Authorization'] = response['rows']['token']
ref_dept = pd.read_excel('resources/temp/json.xlsx', header=0, keep_default_na=False,
sheet_name='Sheet2', engine='openpyxl', dtype={'deptId': str})
ref_dept_dict = dict(zip(ref_dept['deptName'], ref_dept['deptId']))
yun_dan_info = pd.read_excel('resources/template/信息录入表.xlsx', header=0, keep_default_na=False,
sheet_name='郑州换单信息录入表', engine='openpyxl', dtype={'收货手机': str})
url = "https://hdd.hddky.com/tms-hdd/freightSchemeHdr/calculationStandardFreight"
response = requests.post(url, data=param_cal_stand_freight, headers=headers).json()
yun_dan_info['标准运费'] = yun_dan_info[['到达部门', '体积', '重量']].apply(cal_stand_freight, headers_=headers,
ref_data_=ref_dept_dict,
param_cal_stand_freight_=param_cal_stand_freight,
url_=url, axis=1).astype(
pd.UInt32Dtype(), errors='ignore')
yun_dan_info['提付金额'] = yun_dan_info[['运费结算方式', '费用合计', '送货费', '回单费']].apply(
cal_ti_fu_amount, axis=1).astype(
pd.UInt32Dtype(), errors='ignore')
yun_dan_info['现付金额'] = yun_dan_info[['运费结算方式', '标准运费']].apply(
lambda row_: row_['标准运费'] if row_['运费结算方式'] in ['现付'] else None, axis=1).astype(
pd.UInt32Dtype(), errors='ignore')
yun_dan_info['佣金'] = yun_dan_info[['运费结算方式', '提付金额', '标准运费']].apply(
lambda row_: row_['提付金额']-row_['标准运费'] if row_['运费结算方式'] in ['提付'] else None, axis=1).astype(
pd.UInt32Dtype(), errors='ignore')
yun_dan_info.to_excel(r'resources/temp/录单.xlsx', index=False, engine='openpyxl')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化