更新物流投递审核代码
This commit is contained in:
parent
0e49591945
commit
1bbd4c643f
|
|
@ -649,8 +649,14 @@ class XmilesLogistics_US(TailLogistics):
|
|||
detail_amount['tail_amount'] = 99999
|
||||
return detail_amount
|
||||
postcode = int(postcode[:5])
|
||||
# 判断邮编是美东还是美西
|
||||
zone = self.postcode_table[self.postcode_table['POSTCODE'] == postcode]['地区']
|
||||
if zone.empty:
|
||||
detail_amount['tail_amount'] = 99999
|
||||
return detail_amount
|
||||
|
||||
base_fee_list = set() # 将每个包裹费用都记录在列表中
|
||||
|
||||
base_fee_list = [] # 将每个包裹费用都记录在列表中
|
||||
volume_weight = 0 # 计算抛重,用于计算美西转运美东价格
|
||||
for package in packages:
|
||||
volume_weight +=package.get_volume_weight(6000)
|
||||
|
|
@ -658,31 +664,26 @@ class XmilesLogistics_US(TailLogistics):
|
|||
detail_amount['tail_amount'] = 99999
|
||||
return detail_amount
|
||||
if package.lbs_weight <=90 and package.fst_inch <=96 and package.girth_inch <=130:
|
||||
base_fee_list.add(20)
|
||||
base_fee_list.append(20)
|
||||
elif package.lbs_weight <=150 and package.fst_inch <=96 and package.girth_inch <=130:
|
||||
base_fee_list.add(38)
|
||||
base_fee_list.append(38)
|
||||
elif package.lbs_weight <=150 and package.fst_inch <=108 and package.girth_inch <=165:
|
||||
base_fee_list.add(50)
|
||||
base_fee_list.append(50)
|
||||
elif package.lbs_weight <=200 and package.fst_inch <=144 and package.girth_inch <=225:
|
||||
base_fee_list.add(75)
|
||||
base_fee_list.append(75)
|
||||
else:
|
||||
base_fee_list.add(75+0.55*math.ceil(package.lbs_weight))
|
||||
base_fee_list.append(75+0.55*math.ceil(package.lbs_weight))
|
||||
# 取所有费用,最大的费用取全部费用,其他取半价然后求和
|
||||
base_fee_list = sorted(base_fee_list,reverse=True)
|
||||
# 计算base_fee_list最大值+其他费用的一半
|
||||
if len(base_fee_list) == 0:
|
||||
detail_amount['tail_amount'] = 99999
|
||||
return detail_amount
|
||||
elif len(base_fee_list) == 1:
|
||||
detail_amount["base"] = base_fee_list[0]
|
||||
else:
|
||||
detail_amount["base"] = base_fee_list[0] + sum(base_fee_list[1:])/2
|
||||
|
||||
|
||||
# 判断邮编是美东还是美西
|
||||
zone = self.postcode_table[self.postcode_table['POSTCODE'] == postcode]['地区']
|
||||
if zone.empty:
|
||||
detail_amount['tail_amount'] = 99999
|
||||
return detail_amount
|
||||
zone = zone.iloc[0]
|
||||
if zone =="NJ":
|
||||
detail_amount["transfer"] = 0.5*volume_weight
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import pandas as pd
|
||||
import math
|
||||
express_price = pd.read_excel(r'D:\test\logistics\data\售价尾端价格.xlsx', sheet_name='Sheet1')
|
||||
key_column = express_price.iloc[:, 8] # 第 I 列
|
||||
value_column = express_price.iloc[:, 9] # 第 J 列
|
||||
small_column = express_price.iloc[:, 10] # 第 K 列
|
||||
big_column = express_price.iloc[:, 11] # 第 L 列
|
||||
air_small_dict = dict(zip(key_column, small_column))
|
||||
air_big_dict = dict(zip(key_column, big_column))
|
||||
# 转换成字典
|
||||
ocean_price_dict = dict(zip(key_column, value_column))
|
||||
from utils.gtools import MySQLconnect,DBconnect
|
||||
# 取计算订单物流费的参数
|
||||
with DBconnect() as db:
|
||||
express_dict= pd.read_sql("SELECT * FROM us_shop_logistics",db.eng)
|
||||
|
||||
# 构建字典
|
||||
air_small_dict = dict(zip(express_dict['g'], express_dict["空运usps_v2"]))
|
||||
air_big_dict = dict(zip(express_dict['g'], express_dict["空运fedex_v2"]))
|
||||
ocean_price_dict = dict(zip(express_dict['g'], express_dict["海运物流配置_v2"]))
|
||||
def ocean_order_price(packages):
|
||||
express_fee = 0 # 快递基础费
|
||||
long_fee = 0 # 超长费
|
||||
|
|
@ -19,7 +19,7 @@ def ocean_order_price(packages):
|
|||
express_type_length = ''
|
||||
for package in packages:
|
||||
for key, value in ocean_price_dict.items():
|
||||
if max(package.get_volume_weight(8.5), package.weight) <=key:
|
||||
if max(package.get_volume_weight(8500)*1000, package.weight) <=key:
|
||||
express_fee+=value
|
||||
break
|
||||
if package.fst_size>=116 or package.sed_size>=71 or package.girth>=251:
|
||||
|
|
|
|||
30
物流t投递审核.py
30
物流t投递审核.py
|
|
@ -23,7 +23,7 @@ def fetch_order_data():
|
|||
oe.单号 AS order_id,
|
||||
oe.运输方式,
|
||||
oe.`目的国`,
|
||||
oe.快递公司,
|
||||
ol.postcode AS postcode,
|
||||
oe.`快递分区`,
|
||||
oe.快递跟踪号,
|
||||
ecm.类型 AS 渠道类型, -- 包裹类型
|
||||
|
|
@ -34,7 +34,8 @@ def fetch_order_data():
|
|||
pfi.express_fee AS 基础估算,
|
||||
pfi.express_additional_fee AS 偶发估算,
|
||||
pfi.express_fee + pfi.express_additional_fee AS 总估算,
|
||||
ol.postcode AS postcode
|
||||
|
||||
oe.快递公司
|
||||
FROM
|
||||
ods.order_express oe
|
||||
LEFT JOIN ods.express_company ecm ON oe.快递公司 = ecm.快递公司
|
||||
|
|
@ -47,7 +48,7 @@ def fetch_order_data():
|
|||
AND `卡板发货时间` REGEXP "--"
|
||||
AND ol.fund_status NOT REGEXP '等待|全额退款'
|
||||
AND ol.site_name REGEXP 'litfad|kwoking|lakiq'
|
||||
AND oe.投递时间 >= DATE_SUB(NOW(), INTERVAL 20 DAY)
|
||||
AND oe.投递时间 >= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
AND pvi.length>0 AND pvi.width >0 AND pvi.hight>0 AND pvi.weight>0
|
||||
and oe.目的国 regexp 'United States'
|
||||
"""
|
||||
|
|
@ -58,6 +59,7 @@ def fetch_order_data():
|
|||
def cal_min_fee(raw_data: pd.DataFrame):
|
||||
"""
|
||||
处理物流费用数据并实现业务逻辑判断
|
||||
1.用
|
||||
"""
|
||||
df = raw_data.copy()
|
||||
# 包裹层面审核
|
||||
|
|
@ -81,10 +83,13 @@ def cal_min_fee(raw_data: pd.DataFrame):
|
|||
# 计算一票多件
|
||||
package_group.add_package(package)
|
||||
# 计算一票多件
|
||||
if len(package_group) > 1:
|
||||
bill_ltl = Billing("1",opCountry,package_group,row['postcode'],company_name=None,head_type=1,beizhu="")
|
||||
df.loc[df['order_id']==order_id,'卡派尾端费用'] = bill_ltl.tail_amount[0]/len(package_group)
|
||||
df.loc[df['order_id']==order_id,'卡派尾端渠道'] = bill_ltl.company_name
|
||||
min_fee = min(bill_ltl.tail_amount[0],express_fee)
|
||||
else:
|
||||
min_fee = express_fee
|
||||
if min_fee == express_fee:
|
||||
df.loc[df['order_id']==order_id,'最优总物流费用'] = min_fee
|
||||
df.loc[df['order_id']==order_id,'最优渠道类型'] = "快递"
|
||||
|
|
@ -141,7 +146,7 @@ def analyze_orders(raw_data: pd.DataFrame):
|
|||
'快递公司列表': grouped['快递公司'].unique(),
|
||||
'渠道类型列表': grouped['渠道类型'].unique(),
|
||||
'邮编列表': grouped['postcode'].first(),
|
||||
'快递跟踪号数量': grouped['快递跟踪号'].unique()
|
||||
'快递跟踪号': grouped['快递跟踪号'].unique()
|
||||
}).reset_index()
|
||||
|
||||
# 3. 实现业务逻辑判断(保持不变)
|
||||
|
|
@ -168,15 +173,15 @@ def analyze_orders(raw_data: pd.DataFrame):
|
|||
status = '正常'
|
||||
comments = []
|
||||
|
||||
if row['订单类型'] == '卡派':
|
||||
tracking_nos = [list(p.values())[0] for p in row['包裹数据'].values()]
|
||||
if len(set(tracking_nos)) > 1:
|
||||
if row['订单类型'] == '卡派' and len(row['快递跟踪号']) > 1:
|
||||
# tracking_nos = [list(p.values())[0] for p in row['包裹数据'].values()]
|
||||
# if len(set(tracking_nos)) > 1:
|
||||
# status = '异常'
|
||||
status = '异常'
|
||||
if len(row['快递跟踪号数量']) > 1 :
|
||||
comments.append('卡派订单包含多个不同快递单号')
|
||||
elif row['订单类型'] == '混合':
|
||||
status = '异常'
|
||||
comments.append('出现混合类型订单,需要核查')
|
||||
comments.append('出现混合渠道类型订单,需要核查')
|
||||
|
||||
if row['渠道种类'] == '多渠道':
|
||||
if row['总重量'] < 1000:
|
||||
|
|
@ -197,7 +202,7 @@ def analyze_orders(raw_data: pd.DataFrame):
|
|||
'包裹数量', '总重量',
|
||||
'总基础估算', '总附加估算', '总物流估算',
|
||||
'快递公司列表', '邮编列表',
|
||||
'包裹数据' ,'状态', '备注','快递跟踪号数量'# 使用新列名
|
||||
'包裹数据' ,'状态', '备注','快递跟踪号'# 使用新列名
|
||||
]
|
||||
|
||||
return aggregated[final_columns]
|
||||
|
|
@ -234,8 +239,9 @@ def analyze_logistics(df: pd.DataFrame):
|
|||
return all_estimate
|
||||
|
||||
|
||||
df['费用一致'] = df.apply(lambda row: abs(all_estimate(row) - row['最优总物流费用'])<1, axis=1)
|
||||
df['费用差(当地货币)'] = df.apply(lambda row: row['最优总物流费用']-all_estimate(row), axis=1)
|
||||
df['费用一致'] = df.apply(lambda row: False if isinstance(all_estimate(row), str) else abs(all_estimate(row) - row['最优总物流费用']) < 1,axis=1)
|
||||
|
||||
df['费用差(当地货币)'] = df.apply(lambda row: "费用有误" if isinstance(all_estimate(row), str) else row['最优总物流费用'] - all_estimate(row),axis=1)
|
||||
return df
|
||||
|
||||
def main():
|
||||
|
|
|
|||
Loading…
Reference in New Issue