186 lines
7.2 KiB
Python
186 lines
7.2 KiB
Python
import json
|
||
import math
|
||
import sys
|
||
# sys.path.append(r'D:\test\logistics\sell')
|
||
import pandas as pd
|
||
from sell.base_sell_price import SellPriceBase
|
||
from utils.Package import Package, Package_group
|
||
from utils.gtools import MySQLconnect
|
||
import math
|
||
import re
|
||
express_price = pd.read_excel(r'D:\workspace\logistics\data\售价尾端价格.xlsx', sheet_name='2025')
|
||
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))
|
||
def ocean_order_price(packages):
|
||
express_fee = 0 # 快递基础费
|
||
long_fee = 0 # 超长费
|
||
weight_fee = 0 # 超重费
|
||
big_fee = 0 # 大包裹费
|
||
express_type = ''
|
||
express_type_weight = ''
|
||
express_type_length = ''
|
||
for package in packages:
|
||
for key, value in ocean_price_dict.items():
|
||
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:
|
||
long_fee += 16.3
|
||
if express_type_length == '':
|
||
express_type_length ="超长"
|
||
if package.weight>=21000 and package.fst_size<238 and package.girth<315:
|
||
weight_fee+=25.5
|
||
express_type_weight ="超重"
|
||
if package.fst_size>=238 or package.girth>=315:
|
||
big_fee+=61.6
|
||
express_type_length ="大包裹"
|
||
express_fee = express_fee + long_fee + weight_fee + big_fee
|
||
express_type = express_type_length + express_type_weight
|
||
|
||
# 卡派(步长为3)
|
||
ltl_base = 0
|
||
ltl_fee = 0
|
||
count1 = 0
|
||
count2 = 0
|
||
count3 = 0
|
||
count4 = 0
|
||
ltl_type = '卡派'
|
||
order_type_length=''
|
||
order_type_weight=''
|
||
order_ltl_oversize = 0
|
||
order_ltl_overweight1 = 0
|
||
order_ltl_overweight2 = 0
|
||
order_ltl_overpackage = 0
|
||
sku_total_cubic_feet = 0
|
||
for package in packages:
|
||
cubic_feet= package.length * package.width * package.height / 1000000 * 35.3
|
||
sku_total_cubic_feet += cubic_feet
|
||
# 卡派额外费用
|
||
if package.fst_size>= 250:
|
||
count1 += 1
|
||
order_ltl_oversize = 118
|
||
if order_type_length == '':
|
||
order_type_length = '超长'
|
||
if package.weight >= 111000:
|
||
count2 += 1
|
||
order_ltl_overweight1 = 78
|
||
order_type_weight = '超重'
|
||
if package.weight >= 130000:
|
||
count3 += 1
|
||
order_ltl_overweight2 = 30
|
||
if package.fst_size >= 310:
|
||
count4 += 1
|
||
order_ltl_overpackage = 30
|
||
order_type_length = '大包裹'
|
||
order_type2 = ltl_type +order_type_length+ order_type_weight
|
||
|
||
# 卡派基础费用 体积/1000000 *35.3
|
||
if sku_total_cubic_feet < 25:
|
||
ltl_base = round(163 / 0.45 / 2, 2) # 181.11
|
||
|
||
elif sku_total_cubic_feet < 35:
|
||
ltl_base = round(180 / 0.45 / 2, 2) # 200
|
||
else:
|
||
# 大于一个立方的(35立方英尺) 按照每立方英尺*5美金
|
||
# 最低为190美金
|
||
ltl_base = round(max(190, 5 * sku_total_cubic_feet) / 0.359 / 2)
|
||
|
||
|
||
ltl_fee = math.ceil(count1 / 3) * order_ltl_oversize + math.ceil(count2 / 3) * order_ltl_overweight1 + math.ceil(
|
||
count3 / 3) * order_ltl_overweight2 + math.ceil(count4 / 3) * order_ltl_overpackage + ltl_base
|
||
|
||
if ltl_fee < express_fee:
|
||
ocean_fee = ltl_fee
|
||
order_type = order_type2
|
||
else:
|
||
ocean_fee = express_fee
|
||
order_type = express_type
|
||
return ocean_fee, order_type
|
||
|
||
def air_order_price(packages):
|
||
express_fee = 0
|
||
express_type = ''
|
||
for package in packages:
|
||
price=0
|
||
bill_weight = max(package.weight, package.get_volume_weight(8500))
|
||
if package.weight<=420 and package.fst_size<=50 and package.sed_size<=40 and package.trd_size<=30:
|
||
for key, value in air_small_dict.items():
|
||
if package.weight <=key:
|
||
price =value
|
||
break
|
||
elif package.weight<=2718 and package.fst_size<=50 and package.sed_size<=40 and package.trd_size<=30:
|
||
for key, value in air_small_dict.items():
|
||
if bill_weight <=key:
|
||
price =value
|
||
break
|
||
else:
|
||
for key, value in air_big_dict.items():
|
||
if bill_weight <=key:
|
||
price =value
|
||
break
|
||
if package.weight<=420:
|
||
express_fee+=((((min(max(package.density,37),337)*0.093+27.7)/6+0.65)*package.get_volume_weight(6000))*0.3+price)/0.45
|
||
if express_type == '':
|
||
express_type='USPS'
|
||
elif package.weight<=2718:
|
||
express_fee+=(((min(max(package.density,37),337)*0.093+27.7)/6+0.65)*package.get_volume_weight(8500)*0.3+price)/0.45
|
||
if express_type == '' or express_type == 'USPS':
|
||
express_type='UandF'
|
||
else:
|
||
express_fee+=(((min(max(package.density,37),337)*0.093+27.7-1.08)/6+0.65-1.06)*package.get_volume_weight(8500))/0.45+price
|
||
express_type='FEDEX'
|
||
return express_fee, express_type
|
||
|
||
# 美国售价,订单物流费,订单类型,分海运空运
|
||
def call_sell_and_order_price(price, package_dict,head_type):
|
||
"""
|
||
price:采购价
|
||
package_dict:包裹数据
|
||
head_type:头程类型 海运/空运
|
||
"""
|
||
packages = Package_group()
|
||
def extract_number(value):
|
||
# 提取字符串中的第一个数字
|
||
match = re.search(r"[-+]?\d*\.\d+|\d+", str(value))
|
||
return float(match.group()) if match else 0.0
|
||
|
||
for key, package in package_dict.items():
|
||
package['长'] = extract_number(package['长'])
|
||
package['宽'] = extract_number(package['宽'])
|
||
package['高'] = extract_number(package['高'])
|
||
package['重量'] = extract_number(package['重量'])
|
||
|
||
if package['长'] == 0 or package['宽'] == 0 or package['高'] == 0 or package['重量'] == 0:
|
||
return 0,0,0
|
||
packages.add_package(Package(key,package['长'], package['宽'], package['高'], package['重量']))
|
||
|
||
if packages is None:
|
||
return 0,0,0
|
||
litfad = SellPriceBase.litfad_2025(packages, price,1)
|
||
# 修改版本,网站售价
|
||
sell_price = litfad.cal_sell_price_2025()
|
||
# 订单物流费
|
||
if "海" in head_type:
|
||
order_price, order_type = ocean_order_price(packages)
|
||
else:
|
||
order_price, order_type = air_order_price(packages)
|
||
return sell_price,order_price,order_type
|
||
|
||
|
||
if __name__ == '__main__':
|
||
package_dict = {
|
||
'1': {'长': 10, '宽': 10, '高': 10, '重量': 10},
|
||
'2': {'长': 20, '宽': 20, '高': 20, '重量': 20},
|
||
'3': {'长': 30, '宽': 30, '高': 30, '重量': 30},
|
||
'4': {'长': 40, '宽': 40, '高': 40, '重量': 40},
|
||
'5': {'长': 50, '宽': 50, '高': 50, '重量': 50},
|
||
}
|
||
price = 100
|
||
sell_price,order_price,order_type = call_sell_and_order_price(price, package_dict)
|
||
print(sell_price,order_price,order_type) |