62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
import logging
|
|
|
|
# 로거 인스턴스 가져오기
|
|
logger = logging.getLogger('default_logger')
|
|
|
|
def calculate_margin_and_price(inputs):
|
|
logger.debug("calculate_margin_and_price 계산 시작")
|
|
|
|
# 입력값 처리
|
|
option_low_price = inputs["option_low_price"]
|
|
option_high_price = inputs["option_high_price"]
|
|
delv_fee = inputs["delv_fee"]
|
|
packing_fee = inputs["packing_fee"]
|
|
ns_low_price = inputs["ns_low_price"]
|
|
ns_high_price = inputs["ns_high_price"]
|
|
plus_margin = 5000 # 기본값
|
|
|
|
# 계산 로직
|
|
ns_avg_price = round(((ns_low_price + ns_high_price) / 2) / 100) * 100
|
|
logger.debug(f"ns_avg_price : {ns_avg_price}")
|
|
option_avg_price = round(((option_low_price + option_high_price) / 2) / 100) * 100
|
|
logger.debug(f"option_avg_price : {option_avg_price}")
|
|
# tao_cost = lambda price: price * 190 * 1.035
|
|
tao_cost = lambda price: round(price * 1.035 / 100) * 100
|
|
base_margin = lambda cost: round(cost * 0.12 / 100) * 100
|
|
|
|
|
|
def adjust_plus_margin_for_min_margin(seller_cost, mall_cost, selling_price):
|
|
nonlocal plus_margin
|
|
target_margin_rate = 22
|
|
while True:
|
|
final_margin = selling_price - (seller_cost + mall_cost)
|
|
final_margin_rate = (final_margin / selling_price) * 100
|
|
if final_margin_rate < target_margin_rate:
|
|
plus_margin += 100 # 더하기 마진 증가
|
|
selling_price = seller_cost + plus_margin + mall_cost
|
|
mall_cost = round(selling_price * 0.13 / 100) * 100
|
|
else:
|
|
break
|
|
|
|
logger.debug(f"final_margin_rate : {final_margin_rate}")
|
|
|
|
return selling_price, final_margin_rate
|
|
|
|
seller_cost = tao_cost(option_avg_price) + delv_fee + packing_fee
|
|
logger.debug(f"seller_cost : {seller_cost}")
|
|
|
|
mall_cost = round((seller_cost * 0.13)/100) * 100
|
|
selling_price = seller_cost + plus_margin + mall_cost
|
|
selling_price, final_margin_rate = adjust_plus_margin_for_min_margin(seller_cost, mall_cost, selling_price)
|
|
|
|
# 결과 반환
|
|
results = {
|
|
"selling_price": selling_price,
|
|
"final_margin_rate": final_margin_rate,
|
|
"seller_cost": seller_cost,
|
|
"base_margin": base_margin(tao_cost(option_avg_price)),
|
|
"plus_margin": plus_margin,
|
|
"ns_avg_price": ns_avg_price
|
|
}
|
|
return results
|