2025-06-23 16:08:03 +08:00
|
|
|
|
import json
|
2025-06-17 13:40:20 +08:00
|
|
|
|
import math
|
|
|
|
|
|
import sys
|
2025-06-26 00:50:14 +08:00
|
|
|
|
# sys.path.append(r'D:\test\logistics\sell')
|
2025-06-17 13:40:20 +08:00
|
|
|
|
import pandas as pd
|
|
|
|
|
|
from sell.base_sell_price import SellPriceBase
|
|
|
|
|
|
from utils.Package import Package, Package_group
|
2025-06-26 19:35:37 +08:00
|
|
|
|
from utils.gtools import MySQLconnect,DBconnect
|
2025-06-17 13:40:20 +08:00
|
|
|
|
import math
|
|
|
|
|
|
import re
|
2025-06-26 19:35:37 +08:00
|
|
|
|
# 取计算订单物流费的参数
|
|
|
|
|
|
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"]))
|
2025-06-17 13:40:20 +08:00
|
|
|
|
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():
|
2025-06-23 16:08:03 +08:00
|
|
|
|
if max(package.get_volume_weight(8500)*1000, package.weight) <=key:
|
2025-06-17 13:40:20 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
2025-06-26 19:35:37 +08:00
|
|
|
|
# 美国售价2025
|
|
|
|
|
|
def call_sell_price_2025(price, package_dict):
|
2025-06-17 13:40:20 +08:00
|
|
|
|
"""
|
|
|
|
|
|
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
|
2025-06-26 00:50:14 +08:00
|
|
|
|
|
2025-06-17 13:40:20 +08:00
|
|
|
|
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:
|
2025-06-26 00:50:14 +08:00
|
|
|
|
return 0,0,0
|
2025-06-17 13:40:20 +08:00
|
|
|
|
packages.add_package(Package(key,package['长'], package['宽'], package['高'], package['重量']))
|
|
|
|
|
|
|
|
|
|
|
|
if packages is None:
|
2025-06-26 00:50:14 +08:00
|
|
|
|
return 0,0,0
|
|
|
|
|
|
litfad = SellPriceBase.litfad_2025(packages, price,1)
|
2025-06-17 13:40:20 +08:00
|
|
|
|
# 修改版本,网站售价
|
2025-06-26 00:50:14 +08:00
|
|
|
|
sell_price = litfad.cal_sell_price_2025()
|
2025-06-26 19:35:37 +08:00
|
|
|
|
|
|
|
|
|
|
return sell_price
|
2025-06-17 13:40:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|