1
0
Fork 0

더하기 마진을 최종마진으로 가져오면서 가격계산식 수정

This commit is contained in:
Envy_PC 2024-04-22 12:41:39 +09:00
parent 9a28be1bcb
commit b3d1a2b934
3 changed files with 99 additions and 14 deletions

View File

@ -409,10 +409,16 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
# 네이버 상품가격 담기
naver_price = naver_prices(products)
product_info.naver_low_price = naver_price[0]
product_info.naver_avg_price = naver_price[1]
product_info.naver_high_price = naver_price[2]
if naver_price[0]: # 리턴값이 있는 경우 사용
product_info.naver_low_price = naver_price[0]
product_info.naver_avg_price = naver_price[1]
product_info.naver_high_price = naver_price[2]
else: # 리턴값이 None인 경우 기본값인 100원 사용
product_info.naver_low_price = 100
product_info.naver_avg_price = 100
product_info.naver_high_price = 100
# product_info_text = NS_info(products)
product_info_card = NS_info_with_HTML(products)
# logger.debug(f"수집된 정보 \n {product_info_card} \n")

View File

@ -30,15 +30,21 @@ def modify_price_page(driver, product_infos):
time.sleep(2) # 페이지 로딩 대기.
try:
plus_fee_xpath="//div[@id='productMainContentContainerId']/div/div/div/div/div[2]/div/div/div[8]/div/div/div[3]/div/div/div/div/div[2]/input"
plus_fee_element = return_element(driver, 'XPATH', plus_fee_xpath, 10)
plus_fee_text = plus_fee_element.text()
option_high_price = product_infos.option_high_price
option_low_price = product_infos.option_low_price
# tao_high_price = product_infos.tao_high_price # 디버깅을 위해 선택된 옵션가격이 아닌 기존의 원래가격을 가져옴
# tao_low_price = product_infos.tao_low_price # 디버깅을 위해 선택된 옵션가격이 아닌 기존의 원래가격을 가져옴
naver_low_price = product_infos.naver_low_price
naver_avg_price = product_infos.naver_avg_price
naver_high_price = product_infos.naver_high_price
# naver_low_price = product_infos.naver_low_price
# naver_avg_price = product_infos.naver_avg_price
# naver_high_price = product_infos.naver_high_price
w_delv_fee = product_infos.w_delv_fee
packing_fee = product_infos.packing_fee
@ -47,8 +53,9 @@ def modify_price_page(driver, product_infos):
"option_high_price": option_high_price,
"delv_fee": w_delv_fee,
"packing_fee": packing_fee,
"ns_low_price": naver_low_price,
"ns_high_price": naver_high_price
# "ns_low_price": naver_low_price,
# "ns_high_price": naver_high_price,
"plus_fee_text": plus_fee_text,
}
logger.debug(f"가격계산 INPUT 요소 : {inputs}")
except Exception as e:
@ -62,7 +69,7 @@ def modify_price_page(driver, product_infos):
final_margin_rate = outputs["final_margin_rate"]
seller_cost = outputs["seller_cost"]
plus_margin = outputs["plus_margin"]
ns_avg_price = outputs["ns_avg_price"]
# ns_avg_price = outputs["ns_avg_price"]
return_fee = round((selling_price*0.4) / 1000) * 1000
@ -77,7 +84,7 @@ def modify_price_page(driver, product_infos):
logger.debug(f"결정된 상품가격: {selling_price}원, 최종 마진율: {final_margin_rate:.2f}%")
logger.debug(f"판매자 원가: {seller_cost}")
logger.debug(f"더하기 마진: {plus_margin}")
logger.debug(f"네이버 평균가: {ns_avg_price}")
# logger.debug(f"네이버 평균가: {ns_avg_price}원")
except Exception as e:
logger.error(f"가격계산 OUTPUT 요소 계산 중 에러 발생 {e}", exc_info=True)
@ -93,8 +100,8 @@ def modify_price_page(driver, product_infos):
try:
logger.debug("더하기마진 수정")
plus_fee_xpath="//div[@id='productMainContentContainerId']/div/div/div/div/div[2]/div/div/div[8]/div/div/div[3]/div/div/div/div/div[2]/input"
plus_fee_element = return_element(driver, 'XPATH', plus_fee_xpath, 10)
# plus_fee_xpath="//div[@id='productMainContentContainerId']/div/div/div/div/div[2]/div/div/div[8]/div/div/div[3]/div/div/div/div/div[2]/input"
# # plus_fee_element = return_element(driver, 'XPATH', plus_fee_xpath, 10)
plus_fee_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
driver.execute_script("arguments[0].value = '';", plus_fee_element) # 기존 가격 삭제 JS
logger.debug("기존가격 삭제")
@ -110,8 +117,11 @@ def modify_price_page(driver, product_infos):
fore_delv_fee_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
driver.execute_script("arguments[0].value = '';", fore_delv_fee_element) # 기존 가격 삭제 JS
logger.debug("기존가격 삭제")
fore_delv_fee_element.send_keys(w_delv_fee) # 새 가격 입력
# fore_delv_fee_element.send_keys(w_delv_fee) # 새 가격 입력
fore_delv_fee_element.send_keys(0) # 더하기마진을 최종가격으로 가져오면서 배송비는 0원으로 계산됨. 더하기 마진에 배송비가 모두 포함됨.
# logger.debug(f"해외배송비 수정 완료 : {w_delv_fee}")
logger.debug(f"해외배송비 수정 완료 : {w_delv_fee}")
logger.debug("더하기마진을 최종가격으로 가져오면서 배송비는 0원으로 계산됨. 더하기 마진에 배송비가 모두 포함됨.")
except Exception as e:
logger.error(f"해외배송비 수정 중 에러 발생 {e}", exc_info=True)

View File

@ -0,0 +1,69 @@
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_fee_text = inputs["plus_fee_text"]
target_price = round(plus_fee_text * 0.98 / 100) * 100
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
mall_cost = round((target_price * 0.13)/100) * 100
logger.debug(f"seller_cost : {seller_cost}, mall_cost : {mall_cost}")
plus_margin = target_price - seller_cost - mall_cost
logger.debug(f"plus_margin : {plus_margin}")
final_margin_rate = (plus_margin/target_price)*100
logger.debug(f"final_margin_rate : {final_margin_rate}[%]")
selling_price = target_price
# 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