This commit is contained in:
super
2026-04-27 09:20:04 +08:00
22 changed files with 8820 additions and 1537 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -483,8 +483,8 @@ class AmzoneApprove(AmamzonBase):
load_ele = self.tab.eles("xpath://div[contains(@class,'Loader-module__loader')]",timeout=5)
if len(load_ele) > 0:
load_ele[0].wait.deleted(timeout=3, raise_err=False)
time.sleep(0.5)
time.sleep(0.5)
# 获取当前页码
try:
page_pamel = self.tab.eles('xpath://kat-pagination',timeout=5)
@@ -1040,7 +1040,8 @@ class ApproveTask:
for country_code in country_codes:
# 检查是否收到暂停请求
if task_id in runing_task and runing_task[task_id].get("stop_requested", False):
self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING")
self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "ERROR")
driver.close_store()
break
# 打开店铺
@@ -1058,12 +1059,14 @@ class ApproveTask:
import traceback
self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR")
self.log(traceback.format_exc(), "ERROR")
if "与页面的连接已断开" in e:
if "与页面的连接已断开" in str(e):
iskill = True
# 更新已处理国家数
if task_id in runing_task:
runing_task[task_id]["processed_countries"] += 1
self.log(f"{task_id}任务处理完成")
# 最后回传,标记完成
try:
self.post_result(task_id, shop_name, country_code, "", "", is_done=True)

View File

@@ -0,0 +1,714 @@
import json
import sys
import os
import io
# sys.stdout.reconfigure(encoding='utf-8')
import time
import re
import traceback
from datetime import datetime
from DrissionPage import Chromium, ChromiumOptions
import requests
from amazon.del_brand import AmamzonBase, kill_process
from amazon.tool import show_notification, get_shop_info, remove_special_characters, split_currency_values
from config import runing_task, runing_shop, base_dir, DELETE_BRAND_API_BASE
class AmzonePStatus(AmamzonBase):
mark_name = "状态查询"
def SwitchPage(self):
"""
切换至 管理所有库存页面
1、等待 //navigation-favorites-bar[@class="hydrated"] 出现
"""
navigation = self.tab.ele('xpath://navigation-favorites-bar[@class="hydrated"]')
navigation.wait.displayed(raise_err=False)
page_btn = navigation.sr('xpath://internal-fav-bar-links[@data-internal="navigation"]').sr(
'xpath://a[@data-page-id="ezdpc-gui-inventory-mons"]')
page_btn.wait.displayed(raise_err=False)
page_btn.click(timeout=5)
self.tab.wait.doc_loaded()
# 等待搜索框出现
search_region = self.tab.ele('xpath://div[@id="searchBoxContainer"]//kat-input-group')
search_region.wait.displayed(raise_err=False, timeout=60)
def search_asin(self, asin):
search_region = self.tab.ele('xpath://div[@id="searchBoxContainer"]//kat-input-group')
search_region.wait.displayed(raise_err=False)
time.sleep(0.6)
search_input = self.tab.ele("xpath://kat-input[contains(@class,'SearchBox-module__searchInput')]").sr(
'xpath://span[@class="container"]//input[@part="input"]')
search_input.input(asin, clear=True)
sku_ls = []
for _ in range(3):
search_btn = self.tab.ele("xpath://kat-icon[@name='search']")
search_btn.click()
load_ele = self.tab.ele("xpath://div[contains(@class,'Loader-module__loader')]")
# load_ele.wait.hidden(timeout=3, raise_err=False)
load_ele.wait.deleted(timeout=3, raise_err=False)
time.sleep(0.5)
sku_ls = self.tab.eles("xpath://div[@data-sku]", timeout=3)
if len(sku_ls) > 0:
break
return sku_ls
def search_asin_action(self, asin: str):
load_ele = self.tab.eles("xpath://div[contains(@class,'Loader-module__loader')]", timeout=5)
if len(load_ele) > 0:
load_ele[0].wait.deleted(timeout=3, raise_err=False)
time.sleep(0.5)
sku_ls = self.search_asin(asin=asin)
print(f"{self.mark_name}{asin} 搜索到 {len(sku_ls)} 个SKU")
def clear_tab(self):
all_tab = self.browser.get_tabs()
close_tab = []
for tab in all_tab:
tab_id = tab if isinstance(tab, str) else tab.tab_id
if self.tab.tab_id == tab_id:
continue
close_tab.append(tab)
print("需要关闭的标签页", close_tab)
print("当前操作的tab_id", self.tab.tab_id)
self.browser.close_tabs(close_tab)
def run_page_action(self, appoint_asin: str = None):
"""
miniprice_info :
{
"B0DSJGJBWV" : "19.81" # asin : 最低价
}
"""
print(f"{self.mark_name}】,开始执行")
num = 0
retry_num = 0
already_asin = set()
get_page_faild = 0
while retry_num < 3: # 最多重试3次
try:
print(self.mark_name, "指定asin操作", appoint_asin)
self.search_asin_action(asin=appoint_asin)
load_ele = self.tab.eles("xpath://div[contains(@class,'Loader-module__loader')]", timeout=5)
if len(load_ele) > 0:
load_ele[0].wait.deleted(timeout=3, raise_err=False)
time.sleep(0.5)
# 获取当前页码
try:
page_pamel = self.tab.eles('xpath://kat-pagination', timeout=5)
if len(page_pamel) > 0:
current_page = page_pamel[0].sr('xpath:.//ul[@class="pages"]//li[@aria-current="true"]').text
# 总页数
total_page = page_pamel[0].sr.eles(
'xpath:.//ul[@class="pages"]//span[@class="page__inner"][last()]')
if len(total_page) > 0:
total_page = total_page[-1].text
else:
total_page = 0
print(f"{self.mark_name}】当前页码: {current_page} / 总页数: {total_page}")
get_page_faild = 0
except Exception as e:
print("{self.mark_name}", "获取页码失败", e)
get_page_faild += 1
if get_page_faild > 2:
show_notification(f"{self.mark_name}】获取页码失败超3次停止任务")
break
sku_ls = self.tab.eles("xpath://div[@data-sku]", timeout=10)
print(f"{self.mark_name}】获取到 {len(sku_ls)}")
# for sku_ele in sku_ls[0:2]:
if len(sku_ls) == 0:
yield (appoint_asin,"查询不到")
break
for sku_ele in sku_ls:
asin = sku_ele.ele(
'xpath:.//div[contains(@class,"JanusSplitBox-module__container")]//div[contains(@class,"JanusSplitBox-module__panel--") and contains(string(.),"ASIN")]/..//div[last()]',
timeout=3).text
print(f"{self.mark_name}】ASIN {asin} 找到....")
if asin in already_asin:
print(f"{self.mark_name}{asin} 已经处理过了,跳过")
continue
# 状态
status_ele = sku_ele.eles('xpath:.//div[contains(@class,"Status-module__container")]//kat-label')
if len(status_ele) > 0:
statu = status_ele[0].attr("emphasis")
else:
statu = "未获取到状态"
already_asin.add(asin)
yield (asin,statu)
print(f"{self.mark_name}",(asin,statu))
# 判断是否存在需要翻页的情况
page_pamel = self.tab.eles('xpath://kat-pagination', timeout=5)
if len(page_pamel) == 0:
break
next_page_btn = page_pamel[0].sr('xpath:.//span[@part="pagination-nav-right"]')
class_str = next_page_btn.attr('class')
if "end" in class_str:
break
next_page_btn.click()
num += 1
print(f"{self.mark_name}】【程序计算】正在翻页,已翻 {num} 页...")
already_asin = set()
except Exception as e:
print(f"{self.mark_name}】处理跟价操作异常", e)
traceback.print_exc()
retry_num += 1
self.tab.refresh()
self.tab.wait.doc_loaded(raise_err=False, timeout=120)
class StatusTask:
country_info = {
"DE": "德国",
"FR": "法国",
"ES": "西班牙",
"IT": "意大利",
"UK": "英国"
}
def __init__(self, user_info: dict = None):
"""初始化审批任务处理器
Args:
user_info: 用户信息字典,包含 company, username, password
"""
self.user_info = user_info or {}
self.running = True
def log(self, message: str, level: str = "INFO"):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if level == "ERROR":
show_notification(message, "error")
print(f"[{timestamp}] [PriceTask] [{level}] {message}")
def process_task(self, task_data: dict):
"""处理审批任务主入口
Args:
task_data: 任务数据
"""
try:
data = task_data.get("data", {})
task_id = data.get("taskId")
items = data.get("items", [])[0]
shop_name = items.get("shop_name")
queryAsins = items.get("queryAsins", [])
user_id = data.get("user_id")
stage_index = data.get("stage_index")
final_stage = bool(data.get("final_stage", True))
# 用于测试
limit = data.get("limit", None)
if not task_id:
self.log("任务ID为空跳过", "WARNING")
return
# if not items:
# self.log("店铺列表为空,跳过", "WARNING")
# return
if not queryAsins:
self.log("queryAsins 列表为空,跳过", "WARNING")
return
self.log(f"开始处理审批任务 {task_id},共 1 个店铺,{len(queryAsins)} 个国家")
from config import runing_task
runing_task[task_id] = {
"status": "running",
"start_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"total_shops": 1,
"processed_shops": 0,
"total_countries": len(queryAsins),
"processed_countries": 0,
"total_asins": 0,
"processed_asins": 0,
"success_count": 0,
"failed_count": 0,
"stop_requested": False
}
# 检查是否收到暂停请求
if task_id in runing_task and runing_task[task_id].get("stop_requested", False):
self.log(f"检测到任务 {task_id} 的暂停请求,停止处理", "WARNING")
runing_task[task_id]["status"] = "stopped"
return
self.log(f"开始处理店铺: {shop_name}")
show_notification(f"开始处理店铺: {shop_name}", "info")
try:
self.process_shop(items, queryAsins, task_id, user_id, stage_index,
final_stage, limit=limit)
# self.process_shop(shop_item, country_codes, task_id,risk_listing_filter)
# 更新已处理店铺数
if task_id in runing_task:
runing_task[task_id]["processed_shops"] += 1
except Exception as e:
import traceback
self.log(f"处理店铺 {shop_name} 失败: {str(e)}", "ERROR")
self.log(traceback.format_exc(), "ERROR")
# 更新任务状态
if task_id in runing_task:
if runing_task[task_id].get("stop_requested", False):
runing_task[task_id]["status"] = "stopped"
self.log(f"任务 {task_id} 已被暂停!")
else:
runing_task[task_id]["status"] = "completed"
self.log(f"任务 {task_id} 处理完成!")
except Exception as e:
import traceback
self.log(f"任务处理失败: {traceback.format_exc()}", "ERROR")
if task_id:
from config import runing_task
if task_id in runing_task:
runing_task[task_id]["status"] = "failed"
runing_task[task_id]["error"] = str(e)
def open_shop(self, max_retries, company_name, shop_name, iskill=False):
error_info = ""
driver = None
for retry in range(max_retries):
try:
self.log(f"尝试打开店铺 {shop_name} (第 {retry + 1}/{max_retries} 次)")
if iskill:
self.log("重试前先杀掉浏览器进程...")
kill_process("v6")
kill_process("v5")
time.sleep(2)
# 组装用户信息并创建驱动
user_info = {
**self.user_info,
"company": company_name
}
driver = AmzonePStatus(user_info)
browser = driver.open_shop(shop_name)
if browser and browser != "店铺不存在":
self.log(f"成功打开店铺 {shop_name}")
else:
self.log(f"打开店铺失败: {browser}", "WARNING")
driver = None
continue
# 判断是否需要登录
need_login = driver.need_login()
print("【是否需要登录】:", need_login)
if need_login:
self.log(f"店铺 {shop_name} 需要登录,正在登录...")
# 获取店铺凭证
response = get_shop_info(shop_name)
print("【获取店铺凭证返回】:", response.text)
shop_data = response.json()
if not shop_data:
mes = f"获取店铺凭证失败,响应数据: {shop_data.get('message', '未知错误')}"
self.log(mes, "ERROR")
show_notification(mes, "ERROR")
continue
password = shop_data["data"]["password"]
login_success = driver.login(password)
if login_success:
self.log(f"店铺 {shop_name} 登录成功,正在重新打开店铺...")
browser = driver.open_shop(shop_name)
if browser and browser != "店铺不存在":
self.log(f"成功打开店铺 {shop_name} 登录后")
break
else:
self.log(f"登录后打开店铺失败: {browser}", "WARNING")
driver = None
else:
self.log(f"店铺 {shop_name} 登录失败", "WARNING")
driver = None
else:
break
except Exception as e:
import traceback
self.log(f"打开店铺异常: {traceback.format_exc()}", "INFO")
driver = None
error_info = str(e)
time.sleep(10)
# 如果还有重试机会,等待后继续
if retry < max_retries - 1:
time.sleep(3)
# 检查是否成功打开
if not driver or not browser or browser == "店铺不存在":
error_msg = f"店铺 {shop_name} 打开失败,已重试 {max_retries} 次,跳过该店铺,{error_info}"
self.log(error_msg, "ERROR")
# 从执行列表中移除
if shop_name in runing_shop:
del runing_shop[shop_name]
return driver
return driver
def process_shop(self, shop_item: dict, country_codes: list, task_id: int,
user_id=None, stage_index=None, final_stage: bool = True, limit: str = None):
"""处理单个店铺
Args:
shop_item: 店铺信息
country_codes: 国家代码列表
task_id: 任务ID
risk_listing_filter: 风险商品筛选条件
"""
shop_name = shop_item.get("shopName", "未知店铺")
company_name = shop_item.get("companyName", "")
if not company_name:
self.log(f"店铺 {shop_name} 的公司名称为空,跳过", "WARNING")
return
if task_id in runing_task:
runing_task[task_id]["current_shop"] = shop_name
# 将店铺添加到正在执行中的店铺列表
start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
runing_shop[shop_name] = start_time
self.log(f"店铺 {shop_name} 已添加到执行列表,账号: {company_name},开始时间: {start_time}")
# 店铺打开重试最多3次
max_retries = 3
iskill = False
# 处理每个国家
for value in country_codes:
country_code = value.get("country")
all_asin = value.get("asins")
# 打开店铺
driver = self.open_shop(max_retries=max_retries, company_name=company_name,
shop_name=shop_name, iskill=iskill)
if driver is None:
self.log(f"任务 {task_id} 启动店铺失败,结束任务", "ERROR")
for country_code in country_codes:
self.post_result(task_id, shop_name, country_code, "", "", is_done=True)
return
# 检查是否收到暂停请求
if task_id in runing_task and runing_task[task_id].get("stop_requested", False):
self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "ERROR")
driver.close_store()
break
try:
self.process_country(driver, country_code, task_id, shop_name,all_asin=all_asin )
except Exception as e:
import traceback
self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR")
self.log(traceback.format_exc(), "ERROR")
if "与页面的连接已断开" in str(e):
iskill = True
# 更新已处理国家数
if task_id in runing_task:
runing_task[task_id]["processed_countries"] += 1
# 关闭店铺
driver.close_store()
self.log(f"{task_id}任务处理完成")
# 最后回传,标记完成
try:
# self.post_result(task_id, shop_name, country_code, "", "", is_done=True)
if final_stage:
self.post_result(task_id, shop_name, country_code, "", "", is_done=True)
else:
self.post_stage_finished(task_id, user_id, stage_index)
except Exception as e:
self.log(f"回传结果失败: {str(e)}", "ERROR")
# 从正在执行中的店铺列表中移除
if shop_name in runing_shop:
del runing_shop[shop_name]
self.log(f"店铺 {shop_name} 已从执行列表中移除")
def process_country(self, driver: AmzonePStatus, country_code: str, task_id: int, shop_name: str,
all_asin:list,
limit: str = None):
"""处理单个国家的审批任务
Args:
driver: AmzoneApprove驱动实例
country_code: 国家代码(如 UK, DE, FR 等)
task_id: 任务ID
shop_name: 店铺名称
risk_listing_filter: 风险商品筛选条件
"""
# 转换国家代码为中文名称
country_name = self.country_info.get(country_code, country_code)
info_mes = f"开始处理国家: {country_name} ({country_code})"
self.log(info_mes)
show_notification(info_mes, "info")
# 更新当前处理的国家
if task_id in runing_task:
runing_task[task_id]["current_country"] = country_name
# 切换国家最多重试3次
max_retries = 3
switch_success = False
for retry in range(max_retries):
try:
self.log(f"尝试切换到国家 {country_name} (第 {retry + 1}/{max_retries} 次)")
if retry > 1:
# 刷新不行就重新打开店铺
self.log("重试前重新打开店铺...")
try:
driver.close_store()
time.sleep(3)
driver.open_shop(shop_name)
except Exception as e:
self.log(f"关闭重新打开店铺: {str(e)}", "WARNING")
# 如果不是第一次尝试,先刷新页面
if retry > 0:
self.log("重试前刷新页面...")
try:
driver.tab.refresh()
time.sleep(3)
except Exception as e:
self.log(f"刷新页面失败: {str(e)}", "WARNING")
switch_success = driver.SwitchingCountries(country_name)
if switch_success:
self.log(f"成功切换到国家 {country_name}")
break
else:
self.log(f"切换到国家 {country_name} 失败", "WARNING")
except Exception as e:
import traceback
self.log(f"切换国家 {country_name} 异常: {str(e)}", "ERROR")
self.log(traceback.format_exc(), "ERROR")
# 如果还有重试机会,等待后继续
if retry < max_retries - 1:
time.sleep(2)
# 如果切换失败,直接返回
if not switch_success:
error_message = f"切换到国家 {country_name} 失败,已重试 {max_retries} 次,跳过该国家"
self.log(error_message, "ERROR")
if task_id in runing_task:
runing_task[task_id]["processed_countries"] += 1
return
# 切换到库存管理页面
for retry in range(max_retries):
try:
driver.SwitchPage()
self.log(f"已切换到库存管理页面")
except Exception as e:
import traceback
self.log(f"切换页面失败: {str(e)}", "ERROR")
self.log(traceback.format_exc(), "ERROR")
if retry >= max_retries - 1:
if task_id in runing_task:
runing_task[task_id]["processed_countries"] += 1
self.log(f"切换页面失败重试退出", "ERROR")
return
# 处理所有需要审批的商品通过yield获取结果
# 指定 asin
for ap_asin in all_asin:
print(f"{driver.mark_name}】开始处理 ->",ap_asin)
for asin, status in driver.run_page_action(
appoint_asin=ap_asin
):
# 检查是否收到暂停请求
if task_id in runing_task and runing_task[task_id].get("stop_requested", False):
self.log(f"检测到任务 {task_id} 的暂停请求停止处理ASIN", "WARNING")
break
self.log(f"ASIN {asin} 处理结果: {status}")
# 更新任务状态
if task_id in runing_task:
runing_task[task_id]["current_asin"] = asin
runing_task[task_id]["processed_asins"] += 1
runing_task[task_id]["failed_count"] += 1
# 回传结果到API
try:
self.post_result(task_id, shop_name, country_code, asin, status)
except Exception as e:
self.log(f"回传结果失败: {str(e)}", "ERROR")
self.log(f"国家 {country_name} 处理完成")
def post_stage_finished(self, task_id: int, user_id, stage_index):
# import requests
# from config import DELETE_BRAND_API_BASE
if user_id in (None, "", 0):
raise ValueError("user_id is required for stage completion callback")
if stage_index is None:
raise ValueError("stage_index is required for stage completion callback")
url = f"{DELETE_BRAND_API_BASE}/api/shop-match/tasks/{task_id}/stage-finished"
payload = {"stage_index": stage_index}
params = {"user_id": user_id}
max_retries = 3
for retry in range(max_retries):
try:
self.log(f"Attempting stage completion callback ({retry + 1}/{max_retries})")
response = requests.post(
url,
params=params,
json=payload,
headers={"Content-Type": "application/json"},
timeout=30,
verify=False,
)
self.log(f"Stage completion callback response: {response.text}")
data = response.json() if response.text else {}
if response.status_code == 200 and isinstance(data, dict) and data.get("success"):
self.log(f"Stage completion callback succeeded: task={task_id}, stage={stage_index}")
return
self.log(f"Stage completion callback failed, status={response.status_code}", "WARNING")
except Exception as e:
self.log(f"Stage completion callback exception: {str(e)}", "ERROR")
if retry < max_retries - 1:
time.sleep(2)
raise RuntimeError(f"Stage completion callback failed after retries: task={task_id}, stage={stage_index}")
def post_result(self, task_id: int, shop_name: str, country_code: str, asin: str, status: dict,
is_done: bool = False):
"""回传处理结果到API
Args:
task_id: 任务ID
shop_name: 店铺名称
country_code: 国家代码
asin: ASIN
status: 处理状态
"""
url = f"{DELETE_BRAND_API_BASE}/api/query-asin/tasks/{task_id}/result"
payload = {
"shops": [
{
"shopName": shop_name,
"countryResults": [
{
"country": country_code,
"items": [
{
"asin": asin,
"status": status
}
]
}
],
"shopDone": is_done,
"submissionId": f"{int(time.time())}"
}
]
}
if is_done:
payload["shops"][0]["success"] = is_done
max_retries = 3
for retry in range(max_retries):
try:
print("================【跟价】=====================")
self.log(f"尝试回传结果 (第 {retry + 1}/{max_retries} 次)")
self.log(f"回传URL: {url}")
self.log(f"回传数据: {payload}")
response = requests.post(
url,
json=payload,
headers={"Content-Type": "application/json"},
timeout=30,
verify=False
)
self.log(f"回传结果: {response.text}")
data = response.json() if response.text else {}
if response.status_code == 200 and isinstance(data, dict) and data.get("success"):
self.log(f"结果回传成功: {asin} - {status}")
return
else:
self.log(f"结果回传失败,状态码: {response.status_code}", "WARNING")
print("=====================================")
except Exception as e:
self.log(f"调用API异常: {str(e)}", "ERROR")
print("=====================================")
# 如果还有重试机会,等待后继续
if retry < max_retries - 1:
time.sleep(2)
self.log(f"已达到最大重试次数,结果回传最终失败", "ERROR")
raise RuntimeError("已达到最大重试次数,结果回传最终失败")
if __name__ == '__main__':
# 使用示例
user_info = {
"company": "rongchuang123",
"username": "自动化_Robot",
"password": "#20zsg25"
}
shop_name = "魏振峰"
country = "德国"
kill_process('v6')
driver = AmzonePStatus(user_info)
browser = driver.open_shop(shop_name)
sw_suc = driver.SwitchingCountries(country)
driver.SwitchPage()
risk_listing_filter = "Active"
_shopMallName = "WEIZHENFENG168"
ap_asin = "B0F1N18XFW"
skip_asin = []
for _ in range(3):
try:
sku_ls = driver.search(filter_type=risk_listing_filter)
break
except Exception as e:
print(e)
driver.tab.refresh()
if len(sku_ls) > 0:
print("有数据,开始操作")
for asin, status in driver.run_page_action(
current_shop_name=_shopMallName,
appoint_asin=ap_asin, skip_asin=skip_asin
):
print(f"ASIN {asin} 的处理结果: {status}")
print("已完成操作")

6907
app/amazon/detail_spider.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,8 @@ from amazon.del_brand import AmazoneDriver, kill_process
from amazon.approve import ApproveTask
from amazon.match_action import MatchTak
from amazon.price_match import PriceTask
from amazon.asin_status import StatusTask
from amazon.detail_spider import SpiderTask
from amazon.tool import get_shop_info,show_notification
@@ -55,7 +57,9 @@ class TaskMonitor:
task_type_info = {
"product-risk-resolve-run" : "产品风险审批",
"shop-match-run" : "匹配价格",
"price-track-run" : "跟价"
"price-track-run" : "跟价",
"query-asin-run" : "状态查询",
"appearance-patent-run" : "亚马逊采集",
}
try:
while self.running:
@@ -122,7 +126,9 @@ class TaskMonitor:
TASK_INFO = {
"产品风险审批" : ApproveTask,
"匹配价格" : MatchTak,
"跟价" : PriceTask
"跟价" : PriceTask,
"状态查询" : StatusTask,
"亚马逊采集" : SpiderTask,
}
self.log(f"线程 {id(task_data)} 开始处理产品风险审批任务...")
# 创建ApproveTask实例并处理任务

View File

@@ -445,13 +445,13 @@ class MatchTak:
import traceback
self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR")
self.log(traceback.format_exc(), "ERROR")
if "与页面的连接已断开" in e:
if "与页面的连接已断开" in str(e):
iskill = True
# 更新已处理国家数
if task_id in runing_task:
runing_task[task_id]["processed_countries"] += 1
self.log(f"{task_id}任务处理完成")
# 最后回传,标记完成
try:
# self.post_result(task_id, shop_name, country_code, "", "", is_done=True)

View File

@@ -17,6 +17,97 @@ from amazon.tool import show_notification,get_shop_info,remove_special_character
from config import runing_task, runing_shop,base_dir,DELETE_BRAND_API_BASE
class RepricingLogic:
@staticmethod
def situation_1_general_decrease(my_price, rank1_price, is_first_time=False):
"""
情况1常规递减跟价 (最左侧独立长图块)
当不是自己购物车时,按总价当作第一名递减。
"""
if is_first_time:
return rank1_price - 0.3
diff = abs(my_price - rank1_price)
# 精简了原图中长串的阶梯逻辑
if diff <= 0.3:
return rank1_price - 0.5
elif diff <= 0.8:
return rank1_price - 0.7
elif diff <= 10.5:
# 0.8 到 10.5 之间原图逻辑全部是“减1”
return rank1_price - 1.0
else:
return None # 相差10.5以上,跳过
@staticmethod
def situation_2_own_buybox(my_price, rank2_price):
"""
情况2已经是自己购物车
逻辑:判断与第二名的差价,如果拉开足够差距,则稍微降一点点(减0.5)保持优势,防止卖太便宜。
"""
diff = abs(rank2_price - my_price)
# 1. 绝对差价2欧以上
if diff >= 2.0:
return rank2_price - 0.3
# 2. 产品售价区间判定 (是否要提高价格)
if (20 <= my_price < 30 and diff >= 4) or \
(30 <= my_price < 60 and diff >= 8) or \
(60 <= my_price <= 150 and diff >= 15):
return rank2_price - 0.3 # 满足区间大差价,提价至第二名之下
return my_price # 不满足条件则保持原价
@staticmethod
def situation_3_not_own_buybox(my_price, rank1_price):
"""
情况3不是自己购物车 (常规情况)
"""
diff = abs(my_price - rank1_price)
if diff <= 0.3:
return rank1_price - 0.5
elif 0.5 <= diff <= 0.8:
return rank1_price - 0.7
elif 0.8 < diff <= 2.5:
return rank1_price - 1.0
elif diff > 2.5: # 2.5-3.5以上跳过
return None
return rank1_price - 0.3 # 默认按第一名减0.3
@staticmethod
def situation_4_encounter_amz_us_1st(my_price, amz_us_price):
"""
情况4第一名是 Amazon US 卖家
"""
diff = abs(my_price - amz_us_price)
if diff <= 3:
return amz_us_price - 2
elif 4 <= diff <= 6:
return amz_us_price - 3
elif 8 <= diff <= 12:
return None # 跳过不跟价
return amz_us_price - 3 # 默认直接按照 Amazon US 减去3
@staticmethod
def situation_5_im_1st_amz_us_2nd(my_price, amz_us_price):
"""
情况5自己是第一名第二名是 Amazon US 卖家
"""
diff = abs(amz_us_price - my_price)
if diff <= 7:
return None # 相差5以内跳过 (保持原价)
else:
return amz_us_price - 5
def calculate_target_price(
front_end_data,current_Price,current_shop_name,
recommended_price,recommended_shipping
@@ -35,54 +126,44 @@ def calculate_target_price(
# --- Step 2: 紫鸟后台特殊判定 (最高优先级) ---
if recommended_shipping > 0:
backend_base_price = recommended_price
backend_shipping = recommended_shipping
total_price = backend_base_price + backend_shipping
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) # 实际第一名价格
return RepricingLogic.situation_1_general_decrease(my_price,price_1,is_my_buybox)
# backend_base_price = recommended_price
# backend_shipping = recommended_shipping
# total_price = backend_base_price + backend_shipping
#
# if is_my_buybox:
# # 🌟【逻辑更新】:如果是自己的购物车,直接跳过,不做任何价格调整
# return None
# else:
# # 不是自己的购物车:直接将紫鸟的总和作为"第一名"价格,强制抛入阶梯跟价逻辑
# return calculate_standard_competitor_pricing(my_price, total_price)
if is_my_buybox:
# 🌟【逻辑更新】:如果是自己的购物车,直接跳过,不做任何价格调整
return None
else:
# 不是自己的购物车:直接将紫鸟的总和作为"第一名"价格,强制抛入阶梯跟价逻辑
return calculate_standard_competitor_pricing(my_price, total_price)
# # 第一名是自己, 第二名 Amazon US 卖家 的情况
shop_name_1 = front_end_data.get("top_sellers")[0].get("shop_name")
shop_name_2 = front_end_data.get("top_sellers")[1].get("shop_name") if len(front_end_data.get("top_sellers")) >=2 else ""
if shop_name_1 == current_shop_name and "Amazon" in shop_name_2:
price_2 = float(front_end_data.get("top_sellers")[1].get("price")) # 实际第二名价格
return RepricingLogic.situation_5_im_1st_amz_us_2nd(my_price,price_2)
# --- Step 3: 常规核心分流逻辑 (如果没有紫鸟后台数据) ---
# 分支 A第一名是 Amazon US 卖家 (特殊强敌优先)
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) # 实际第一名价格
if "Amazon." in cart_seller:
diff = abs(my_price - price_1)
if diff <= 5.0 or my_price > price_1:
return price_1 - 5.0
elif 5.0 < diff <= 8.0:
return price_1 - 3.0
elif 8.0 < diff <= 12.0:
return None # 跳过,不跟价
if "Amazon" in shop_name_1:
return RepricingLogic.isituation_4_encounter_amz_us_1st(my_price,price_1)
# 分支 B不是 Amazon US且目前是自己的购物车
elif is_my_buybox:
price_2 = float(front_end_data.get("top_sellers")[1].get("price")) # 实际第二名价格
diff_with_2nd = price_2 - my_price
if diff_with_2nd >= 2.0:
return price_2 - 0.3
else:
# 提价区间判定
if (20 <= my_price <= 30) and diff_with_2nd >= 4:
return price_2 - 0.3
elif (30 <= my_price <= 60) and diff_with_2nd >= 8:
return price_2 - 0.3
elif (60 <= my_price <= 150) and diff_with_2nd >= 15:
return price_2 - 0.3
else:
return None
return RepricingLogic.situation_2_own_buybox(my_price,price_2)
# 分支 C不是 Amazon US也不是自己的购物车
else:
# 正常情况下的普通跟价,调用阶梯逻辑
return calculate_standard_competitor_pricing(my_price, price_1)
return RepricingLogic.situation_3_not_own_buybox(my_price, price_1)
# =====================================================================
@@ -96,7 +177,7 @@ def calculate_standard_competitor_pricing(my_current_price, target_competitor_pr
diff = abs(my_current_price - target_competitor_price)
# 根据阶梯执行跟价扣减
if diff <= 0.3:
if 0 < diff < 0.5:
return base_target - 0.5
elif 0.5 <= diff <= 0.8:
return base_target - 0.7
@@ -104,10 +185,12 @@ def calculate_standard_competitor_pricing(my_current_price, target_competitor_pr
return base_target - 1.0
elif 1.5 <= diff <= 2.5:
return base_target - 1.0
elif diff > 2.5:
return my_current_price # 差距过大,跳过不跟价
elif 2.5 < diff <= 3 :
return None # 差距过大,跳过不跟价
# elif diff > 3:
# return base_target
else:
return base_target
@@ -519,8 +602,8 @@ class AmzonePriceMatch(AmamzonBase):
current_country_ele = self.tab.ele('xpath://div[@class="dropdown-account-switcher-header-label"]/span[last()]',
timeout=20)
current_country = current_country_ele.text.strip()
while retry_num < 3: # 最多重试3次
max_retry_num = 5
while retry_num < max_retry_num: # 最多重试3次
try:
if appoint_asin is not None:
print(self.mark_name,"指定asin操作",appoint_asin)
@@ -536,7 +619,7 @@ class AmzonePriceMatch(AmamzonBase):
page_pamel = self.tab.eles('xpath://kat-pagination', timeout=5)
if len(page_pamel) > 0:
current_page = page_pamel[0].sr('xpath:.//ul[@class="pages"]//li[@aria-current="true"]').text
# yield (None,{"page":int(current_page.strip())})
# 总页数
total_page = page_pamel[0].sr.eles(
'xpath:.//ul[@class="pages"]//span[@class="page__inner"][last()]')
@@ -555,6 +638,14 @@ class AmzonePriceMatch(AmamzonBase):
sku_ls = self.tab.eles("xpath://div[@data-sku]", timeout=10)
print(f"{self.mark_name}】获取到 {len(sku_ls)}")
if len(sku_ls) == 0:
retry_num += 1
print(f"没有获取到 ASIN 商品,重试{retry_num}/{max_retry_num}")
self.tab.refresh()
self.tab.wait.doc_loaded(raise_err=False, timeout=120)
continue
# for sku_ele in sku_ls[0:2]:
for sku_ele in sku_ls:
@@ -586,18 +677,16 @@ class AmzonePriceMatch(AmamzonBase):
# 如果紫鸟里当前价格低于最低价则删除,否则跳过
if mode == "status" and miniprice_info.get(asin):
backend_price = float(miniprice_info.get(asin))
if float(current_price) < backend_price:
if float(current_price) <= backend_price:
# yield (asin, {
# "statu": "删除(当前价格低于最低价)",
# "deleteSkipAsin": True,
# "removeAsin": asin,
# })
yield (asin, {
"statu": "删除(当前价格低于最低价)",
"deleteSkipAsin": True,
"removeAsin": asin,
})
continue
else:
yield (asin, {
"statu": "跳过(当前价格不低于最低价)",
"deleteSkipAsin": True,
"removeAsin": asin,
"statu": "跳过(当前价格低于或等于最低价)",
"currentPrice": current_price,
"minimumPrice": bottom_price, # 最低价格
})
continue
@@ -626,6 +715,7 @@ class AmzonePriceMatch(AmamzonBase):
chrome = ChromeAmzone(tab=new_tab)
front_end_data = chrome.run(country=current_country)
chrome.close()
self.clear_tab()
print(self.mark_name,"亚马逊前台抓取到数据",front_end_data)
if front_end_data is None or len(front_end_data.get("top_sellers")) == 0:
yield (asin, {
@@ -688,8 +778,28 @@ class AmzonePriceMatch(AmamzonBase):
"firstPlace": price_1,
"secondPlace": price_2,
"cartShopName" : cartShopName,
"shippingFee" : f"{shipping_fee}",
"priceChangeStatus" : "改价成功",
})
else:
recommendedPrice = recommend_price + shipping_fee
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) if len(
front_end_data.get("top_sellers")) >= 2 else "" # 实际第一名价格
price_2 = float(front_end_data.get("top_sellers")[1].get("price")) if len(
front_end_data.get("top_sellers")) >= 2 else "" # 实际第二名价格
cartShopName = front_end_data.get("cart_seller")
yield (asin, {
"statu": "跳过,无需改价",
"currentPrice": current_price,
"recommendedPrice": f"{recommendedPrice}",
"minimumPrice": bottom_price, # 最低价格
"firstPlace": price_1,
"secondPlace": price_2,
"cartShopName": cartShopName,
"shippingFee": f"{shipping_fee}",
"priceChangeStatus": "跳过,无需改价",
})
already_asin.add(asin)
# 判断是否存在需要翻页的情况
@@ -704,6 +814,7 @@ class AmzonePriceMatch(AmamzonBase):
num += 1
print(f"{self.mark_name}】【程序计算】正在翻页,已翻 {num} 页...")
already_asin = set()
retry_num = 0
except Exception as e:
print(f"{self.mark_name}】处理跟价操作异常", e)
@@ -924,6 +1035,11 @@ class PriceTask:
skip_asins_by_country = shop_item.get("skip_asins_by_country",{})
asin_rows_by_country = shop_item.get("asin_rows_by_country",{})
skip_asin_details_by_country = shop_item.get("skip_asin_details_by_country",{})
minimum_price_by_country_and_asin = shop_item.get("minimum_price_by_country_and_asin",{})
if len(minimum_price_by_country_and_asin) > 0:
country_codes = minimum_price_by_country_and_asin.keys()
# 指定ASIN的情况
mode = shop_item.get("mode")
if not company_name:
@@ -955,20 +1071,25 @@ class PriceTask:
# 检查是否收到暂停请求
if task_id in runing_task and runing_task[task_id].get("stop_requested", False):
self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING")
self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "ERROR")
driver.close_store()
break
skip_asin = skip_asins_by_country.get(country_code,[]) #需要跳过的asin
appoint_asin = asin_rows_by_country.get(country_code,[])
miniprice_info = {i.get('asin'):i.get('minimumPrice') for i in skip_asin_details_by_country.get(country_code,[])}
if mode == "status":
miniprice_info = {i.get('asin'):i.get('minimumPrice') for i in skip_asin_details_by_country.get(country_code,[])}
else:
miniprice_info = minimum_price_by_country_and_asin.get(country_code,{})
try:
self.process_country(driver, country_code, task_id, shop_name, risk_listing_filter,
shopMallName=shopMallName,skip_asin=skip_asin, limit=limit,
appoint_asin=appoint_asin,mode=mode,miniprice_info=miniprice_info)
appoint_asin=appoint_asin,mode=mode,miniprice_info=miniprice_info,
)
except Exception as e:
import traceback
self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR")
self.log(traceback.format_exc(), "ERROR")
if "与页面的连接已断开" in e:
if "与页面的连接已断开" in str(e):
iskill = True
# 更新已处理国家数
if task_id in runing_task:
@@ -986,6 +1107,7 @@ class PriceTask:
self.post_stage_finished(task_id, user_id, stage_index)
except Exception as e:
self.log(f"回传结果失败: {str(e)}", "ERROR")
self.log(f"{task_id}任务处理完成")
# 从正在执行中的店铺列表中移除
if shop_name in runing_shop:
@@ -994,8 +1116,7 @@ class PriceTask:
def process_country(self, driver: AmzonePriceMatch, country_code: str, task_id: int, shop_name: str,
risk_listing_filter: str,shopMallName:str,skip_asin:list,appoint_asin:list,mode:str,
miniprice_info:dict={},
limit: str = None):
miniprice_info:dict={}, limit: str = None):
"""处理单个国家的审批任务
Args:
@@ -1113,36 +1234,39 @@ class PriceTask:
for i in range(max_range):
if len(appoint_asin) > i:
_shopMallName = appoint_asin[i]["shopMallName"]
ap_asin = appoint_asin[i]["shopMallName"]
ap_asin = appoint_asin[i]["asin"]
else:
_shopMallName = shopMallName
ap_asin = None
for _ in range(max_retries):
for asin, status in driver.run_page_action(
current_shop_name=_shopMallName,
appoint_asin=ap_asin,skip_asin=skip_asin,mode=mode,
miniprice_info=miniprice_info
):
if asin is None:
continue
# 检查是否收到暂停请求
if task_id in runing_task and runing_task[task_id].get("stop_requested", False):
self.log(f"检测到任务 {task_id} 的暂停请求停止处理ASIN", "WARNING")
break
for asin, status in driver.run_page_action(
current_shop_name=_shopMallName,
appoint_asin=ap_asin,skip_asin=skip_asin,mode=mode,
miniprice_info=miniprice_info
):
# 检查是否收到暂停请求
if task_id in runing_task and runing_task[task_id].get("stop_requested", False):
self.log(f"检测到任务 {task_id} 的暂停请求停止处理ASIN", "WARNING")
break
self.log(f"ASIN {asin} 处理结果: {status}")
self.log(f"ASIN {asin} 处理结果: {status}")
# 更新任务状态
if task_id in runing_task:
runing_task[task_id]["current_asin"] = asin
runing_task[task_id]["processed_asins"] += 1
# 更新任务状态
if task_id in runing_task:
runing_task[task_id]["current_asin"] = asin
runing_task[task_id]["processed_asins"] += 1
runing_task[task_id]["failed_count"] += 1
runing_task[task_id]["failed_count"] += 1
# 回传结果到API
try:
self.post_result(task_id, shop_name, country_code, asin, status,shopMallName)
except Exception as e:
self.log(f"回传结果失败: {str(e)}", "ERROR")
# 回传结果到API
try:
self.post_result(task_id, shop_name, country_code, asin, status,shopMallName)
except Exception as e:
self.log(f"回传结果失败: {str(e)}", "ERROR")
break
self.log(f"国家 {country_name} 处理完成")
@@ -1197,18 +1321,6 @@ class PriceTask:
"""
url = f"{DELETE_BRAND_API_BASE}/api/price-track/tasks/{task_id}/result"
"""
(asin,{
"statu" : "改价成功",
"currentPrice" : current_price,
"recommendedPrice" : f"{recommendedPrice}",
"minimumPrice" : bottom_price, #最低价格
"firstPlace": price_1,
"secondPlace": price_2,
"cartShopName" : current_shop_name,
"priceChangeStatus" : "改价成功",
})
"""
payload = {
"shops": [
@@ -1229,6 +1341,7 @@ class PriceTask:
"deleteSkipAsin": status.get("deleteSkipAsin",False),
"removeAsin": status.get("removeAsin") if status.get("removeAsin") else "",
# "modifyCount": "2",
"shippingFee" : status.get("shippingFee") if status.get("shippingFee") else "",
"status": status.get("statu")
}
]
@@ -1277,34 +1390,44 @@ class PriceTask:
if __name__ == '__main__':
# 使用示例
user_info = {
"company": "rongchuang123",
"username": "自动化_Robot",
"password": "#20zsg25"
}
shop_name = "魏振峰"
country = "德国"
kill_process('v6')
driver = AmzonePriceMatch(user_info)
browser = driver.open_shop(shop_name)
sw_suc = driver.SwitchingCountries(country)
driver.SwitchPage()
risk_listing_filter = "Active"
_shopMallName = "WEIZHENFENG168"
ap_asin ="B0F1N18XFW"
skip_asin = []
for _ in range(3):
try:
sku_ls = driver.search(filter_type=risk_listing_filter)
break
except Exception as e:
print(e)
driver.tab.refresh()
if len(sku_ls) > 0:
print("有数据,开始操作")
for asin, status in driver.run_page_action(
current_shop_name=_shopMallName,
appoint_asin=ap_asin,skip_asin=skip_asin
):
print(f"ASIN {asin} 的处理结果: {status}")
print("已完成操作")
# user_info = {
# "company": "尾号5578的公司115",
# "username": "自动化_Robot",
# "password": "#20zsg25"
# }
# shop_name = "刘建煌"
# country = "德国"
# kill_process('v6')
# driver = AmzonePriceMatch(user_info)
# browser = driver.open_shop(shop_name)
# sw_suc = driver.SwitchingCountries(country)
# driver.SwitchPage()
# risk_listing_filter = "Active"
# _shopMallName = "Jianhuang 888"
# ap_asin ="B0BGHRP6BS"
# skip_asin = []
# for _ in range(3):
# try:
# sku_ls = driver.search(filter_type=risk_listing_filter)
# break
# except Exception as e:
# print(e)
# driver.tab.refresh()
# if len(sku_ls) > 0:
# print("有数据,开始操作")
# for asin, status in driver.run_page_action(
# current_shop_name=_shopMallName,
# appoint_asin=ap_asin,skip_asin=skip_asin,mode="asin"
# ):
# print(f"ASIN {asin} 的处理结果: {status}")
# print("已完成操作")
front_end_data = {"top_sellers": [{"rank": 1, "price": "36.81", "stock": "5", "shop_name": "Windera"}, {"rank": 2, "price": "36.50", "stock": "100", "shop_name": "Jianhuang 888"}], "cart_seller": "Windera", "timestamp": "2026-04-25 09:32:58"}
current_Price = 36.50
current_shop_name = "Jianhuang 888"
recommended_price = 36.81
recommended_shipping = 0
calculate_target_price(
front_end_data, current_Price, current_shop_name,
recommended_price, recommended_shipping
)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,16 +1,19 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>格式转换 - 数富AI</title>
<script type="module" crossorigin src="/assets/convert.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/convert-BKSNvX8i.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>格式转换 - 数富AI</title>
<script type="module" crossorigin src="/assets/convert.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/convert-BKSNvX8i.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@@ -1,16 +1,19 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>数据去重 - 数富AI</title>
<script type="module" crossorigin src="/assets/dedupe.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/dedupe-DNlVfFj-.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>数据去重 - 数富AI</title>
<script type="module" crossorigin src="/assets/dedupe.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/dedupe-DNlVfFj-.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@@ -1,16 +1,19 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>删除品牌 - 数富AI</title>
<script type="module" crossorigin src="/assets/delete-brand.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/delete-brand-BP3XWKAC.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>删除品牌 - 数富AI</title>
<script type="module" crossorigin src="/assets/delete-brand.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/delete-brand-BP3XWKAC.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@@ -1,16 +1,19 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>数据拆分 - 数富AI</title>
<script type="module" crossorigin src="/assets/split.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/split-BoBVrLdC.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>数据拆分 - 数富AI</title>
<script type="module" crossorigin src="/assets/split.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/split-BoBVrLdC.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@@ -14,126 +14,126 @@
height: 100vh;
font-weight: bold;
}
.top-bar {
min-height: 88px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
padding: 10px 24px 12px;
border-bottom: 1px solid #2a2a2a;
}
.logo-area {
display: flex;
align-items: center;
gap: 16px;
min-width: 0;
padding-top: 10px;
}
.top-bar .app-name { font-size: 18px; font-weight: 600; color: #fff; }
.btn-home {
font-size: 13px;
color: #d2d2d2;
text-decoration: none;
white-space: nowrap;
}
.btn-home:hover { color: #fff; }
.nav-tabs {
flex: 1;
min-width: 0;
display: flex;
align-items: stretch;
justify-content: center;
}
.nav-tab-group {
display: flex;
align-items: stretch;
justify-content: center;
flex: 1;
gap: 0;
}
.nav-section {
flex: 1;
min-width: 0;
padding: 0 18px;
position: relative;
}
body.nav-permissions-loading .nav-section[data-column-key] {
display: none;
}
.nav-section + .nav-section::before {
content: '';
position: absolute;
left: 0;
top: 14px;
bottom: 8px;
width: 1px;
background: rgba(255, 255, 255, 0.14);
}
.nav-section-title {
margin-bottom: 10px;
text-align: center;
color: #e8dfcf;
font-size: 16px;
font-weight: 800;
letter-spacing: 0.08em;
}
.nav-section-items {
display: flex;
flex-wrap: wrap;
gap: 8px;
justify-content: center;
padding: 10px 14px;
border-radius: 14px;
background: linear-gradient(180deg, rgba(83, 74, 67, 0.92) 0%, rgba(72, 65, 59, 0.96) 100%);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.nav-item {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 28px;
padding: 0 2px;
color: #f3eee4;
font-size: 14px;
font-weight: 700;
text-decoration: none;
border-bottom: 2px solid transparent;
transition: color 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
background: transparent;
border-left: none;
border-right: none;
border-top: none;
cursor: pointer;
}
.nav-item:hover {
color: #fff;
border-bottom-color: rgba(255, 255, 255, 0.68);
}
.nav-item.active {
color: #fff;
border-bottom-color: #8dc4ff;
}
.nav-item.disabled {
color: rgba(255, 255, 255, 0.78);
opacity: 0.82;
cursor: default;
}
.top-right {
width: 60px;
flex-shrink: 0;
}
.top-bar {
min-height: 88px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
padding: 10px 24px 12px;
border-bottom: 1px solid #2a2a2a;
}
.logo-area {
display: flex;
align-items: center;
gap: 16px;
min-width: 0;
padding-top: 10px;
}
.top-bar .app-name { font-size: 18px; font-weight: 600; color: #fff; }
.btn-home {
font-size: 13px;
color: #d2d2d2;
text-decoration: none;
white-space: nowrap;
}
.btn-home:hover { color: #fff; }
.nav-tabs {
flex: 1;
min-width: 0;
display: flex;
align-items: stretch;
justify-content: center;
}
.nav-tab-group {
display: flex;
align-items: stretch;
justify-content: center;
flex: 1;
gap: 0;
}
.nav-section {
flex: 1;
min-width: 0;
padding: 0 18px;
position: relative;
}
body.nav-permissions-loading .nav-section[data-column-key] {
display: none;
}
.nav-section + .nav-section::before {
content: '';
position: absolute;
left: 0;
top: 14px;
bottom: 8px;
width: 1px;
background: rgba(255, 255, 255, 0.14);
}
.nav-section-title {
margin-bottom: 10px;
text-align: center;
color: #e8dfcf;
font-size: 16px;
font-weight: 800;
letter-spacing: 0.08em;
}
.nav-section-items {
display: flex;
flex-wrap: wrap;
gap: 8px;
justify-content: center;
padding: 10px 14px;
border-radius: 14px;
background: linear-gradient(180deg, rgba(83, 74, 67, 0.92) 0%, rgba(72, 65, 59, 0.96) 100%);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.nav-item {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 28px;
padding: 0 2px;
color: #f3eee4;
font-size: 14px;
font-weight: 700;
text-decoration: none;
border-bottom: 2px solid transparent;
transition: color 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
background: transparent;
border-left: none;
border-right: none;
border-top: none;
cursor: pointer;
}
.nav-item:hover {
color: #fff;
border-bottom-color: rgba(255, 255, 255, 0.68);
}
.nav-item.active {
color: #fff;
border-bottom-color: #8dc4ff;
}
.nav-item.disabled {
color: rgba(255, 255, 255, 0.78);
opacity: 0.82;
cursor: default;
}
.top-right {
width: 60px;
flex-shrink: 0;
}
.main-content {
display: flex;
@@ -387,47 +387,48 @@
.toast.show { opacity: 1; }
</style>
</head>
<body data-user-id="{{ user_id or '' }}" class="nav-permissions-loading">
<body data-user-id="{{ user_id or '' }}" class="nav-permissions-loading">
<header class="top-bar">
<div class="logo-area">
<span class="app-name">数富AI-亚马逊</span>
<a href="/home" class="btn-home">返回首页</a>
</div>
<nav class="nav-tabs">
<div class="nav-tab-group">
<div class="nav-section" data-column-key="brand_front_tools">
<div class="nav-section-title">前端工具</div>
<div class="nav-section-items">
<span class="nav-item disabled">采集数据</span>
<span class="nav-item disabled">变体分析</span>
<button type="button" class="nav-item active" data-panel="brandCheck">品牌检测</button>
<a class="nav-item" href="/new_web_source/dedupe.html">数据去重</a>
<a class="nav-item" href="/new_web_source/split.html">数据拆分</a>
<a class="nav-item" href="/new_web_source/convert.html">格式转换</a>
</div>
</div>
<div class="nav-section" data-column-key="brand_operation_tools">
<div class="nav-section-title">运营工具</div>
<div class="nav-section-items">
<a class="nav-item" href="/new_web_source/delete-brand.html">删除ASIN</a>
<a class="nav-item" href="/new_web_source/product-risk.html">商品风险解决</a>
<a class="nav-item" href="/new_web_source/shop-match.html">定时匹配</a>
<a class="nav-item" href="/new_web_source/price-track.html">跟价</a>
<a class="nav-item" href="/new_web_source/patrol-delete.html">巡店删除</a>
<a class="nav-item" href="/new_web_source/query-asin.html">查询ASIN</a>
<span class="nav-item disabled">取款</span>
<span class="nav-item disabled">店铺状态查询</span>
</div>
</div>
<div class="nav-section" data-column-key="brand_logistics_tools">
<div class="nav-section-title">后勤工具</div>
<div class="nav-section-items">
<span class="nav-item disabled">采购</span>
<span class="nav-item disabled">ERP</span>
</div>
</div>
</div>
</nav>
<nav class="nav-tabs">
<div class="nav-tab-group">
<div class="nav-section" data-column-key="brand_front_tools">
<div class="nav-section-title">前端工具</div>
<div class="nav-section-items">
<span class="nav-item disabled">采集数据</span>
<span class="nav-item disabled">变体分析</span>
<button type="button" class="nav-item active" data-panel="brandCheck">品牌检测</button>
<a class="nav-item" href="/new_web_source/appearance-patent.html">外观专利检测</a>
<a class="nav-item" href="/new_web_source/dedupe.html">数据去重</a>
<a class="nav-item" href="/new_web_source/split.html">数据拆分</a>
<a class="nav-item" href="/new_web_source/convert.html">格式转换</a>
</div>
</div>
<div class="nav-section" data-column-key="brand_operation_tools">
<div class="nav-section-title">运营工具</div>
<div class="nav-section-items">
<a class="nav-item" href="/new_web_source/delete-brand.html">删除ASIN</a>
<a class="nav-item" href="/new_web_source/product-risk.html">商品风险解决</a>
<a class="nav-item" href="/new_web_source/shop-match.html">定时匹配</a>
<a class="nav-item" href="/new_web_source/price-track.html">跟价</a>
<a class="nav-item" href="/new_web_source/patrol-delete.html"巡店删除</a>
<a class="nav-item" href="/new_web_source/query-asin.html">查询ASIN</a>
<span class="nav-item disabled">取款</span>
<span class="nav-item disabled">店铺状态查询</span>
</div>
</div>
<div class="nav-section" data-column-key="brand_logistics_tools">
<div class="nav-section-title">后勤工具</div>
<div class="nav-section-items">
<span class="nav-item disabled">采购</span>
<span class="nav-item disabled">ERP</span>
</div>
</div>
</div>
</nav>
<div class="top-right"></div>
</header>
@@ -540,13 +541,13 @@
<script>
(function() {
var selectedPaths = [];
var cachedTasks = [];
var api = window.pywebview && window.pywebview.api;
function getAppPermissionCacheKey(uid) {
return 'app_column_permissions:' + String(uid || '');
}
var selectedPaths = [];
var cachedTasks = [];
var api = window.pywebview && window.pywebview.api;
function getAppPermissionCacheKey(uid) {
return 'app_column_permissions:' + String(uid || '');
}
function getUid() {
return localStorage.getItem('uid') || '';
@@ -559,80 +560,80 @@
}
// 顶部栏目切换:点击当前页菜单项时显示对应 data-panel 的 tab-panel
document.querySelectorAll('.nav-item[data-panel]').forEach(function(tab) {
tab.addEventListener('click', function() {
var panelId = this.getAttribute('data-panel');
document.querySelectorAll('.nav-item[data-panel]').forEach(function(tab) {
tab.addEventListener('click', function() {
var panelId = this.getAttribute('data-panel');
if (!panelId) return;
document.querySelectorAll('.nav-item[data-panel]').forEach(function(t) { t.classList.remove('active'); });
document.querySelectorAll('.tab-panel').forEach(function(p) {
p.classList.toggle('active', p.getAttribute('data-panel') === panelId);
});
this.classList.add('active');
});
});
(function applyNavSectionPermissions() {
function finishNavPermissionLoading() {
document.body.classList.remove('nav-permissions-loading');
}
function showAllNavSections() {
document.querySelectorAll('.nav-section[data-column-key]').forEach(function(section) {
section.style.display = '';
});
}
var uid = document.body.getAttribute('data-user-id');
if (!uid) {
showAllNavSections();
finishNavPermissionLoading();
return;
}
localStorage.setItem('uid', uid);
var cacheKey = getAppPermissionCacheKey(uid);
try {
var cachedItems = JSON.parse(localStorage.getItem(cacheKey) || 'null');
if (Array.isArray(cachedItems)) {
showAllNavSections();
var cachedKeys = cachedItems.map(function(item) {
return (item.column_key || '').toLowerCase();
});
document.querySelectorAll('.nav-section[data-column-key]').forEach(function(section) {
var key = (section.getAttribute('data-column-key') || '').toLowerCase();
section.style.display = cachedKeys.indexOf(key) >= 0 ? '' : 'none';
});
finishNavPermissionLoading();
return;
}
} catch (e) {}
fetch('/api/admin/user/' + uid + '/column-permissions?menu_type=app', { credentials: 'same-origin' })
.then(function(r) { return r.json(); })
.then(function(res) {
showAllNavSections();
if (!res || !res.success || !Array.isArray(res.items)) {
finishNavPermissionLoading();
return;
}
try {
localStorage.setItem(cacheKey, JSON.stringify(res.items));
} catch (e) {}
var allowedKeys = res.items.map(function(item) {
return (item.column_key || '').toLowerCase();
});
document.querySelectorAll('.nav-section[data-column-key]').forEach(function(section) {
var key = (section.getAttribute('data-column-key') || '').toLowerCase();
section.style.display = allowedKeys.indexOf(key) >= 0 ? '' : 'none';
});
finishNavPermissionLoading();
})
.catch(function() {
showAllNavSections();
finishNavPermissionLoading();
});
})();
function showToast(msg) {
var el = document.getElementById('toast');
this.classList.add('active');
});
});
(function applyNavSectionPermissions() {
function finishNavPermissionLoading() {
document.body.classList.remove('nav-permissions-loading');
}
function showAllNavSections() {
document.querySelectorAll('.nav-section[data-column-key]').forEach(function(section) {
section.style.display = '';
});
}
var uid = document.body.getAttribute('data-user-id');
if (!uid) {
showAllNavSections();
finishNavPermissionLoading();
return;
}
localStorage.setItem('uid', uid);
var cacheKey = getAppPermissionCacheKey(uid);
try {
var cachedItems = JSON.parse(localStorage.getItem(cacheKey) || 'null');
if (Array.isArray(cachedItems)) {
showAllNavSections();
var cachedKeys = cachedItems.map(function(item) {
return (item.column_key || '').toLowerCase();
});
document.querySelectorAll('.nav-section[data-column-key]').forEach(function(section) {
var key = (section.getAttribute('data-column-key') || '').toLowerCase();
section.style.display = cachedKeys.indexOf(key) >= 0 ? '' : 'none';
});
finishNavPermissionLoading();
return;
}
} catch (e) {}
fetch('/api/admin/user/' + uid + '/column-permissions?menu_type=app', { credentials: 'same-origin' })
.then(function(r) { return r.json(); })
.then(function(res) {
showAllNavSections();
if (!res || !res.success || !Array.isArray(res.items)) {
finishNavPermissionLoading();
return;
}
try {
localStorage.setItem(cacheKey, JSON.stringify(res.items));
} catch (e) {}
var allowedKeys = res.items.map(function(item) {
return (item.column_key || '').toLowerCase();
});
document.querySelectorAll('.nav-section[data-column-key]').forEach(function(section) {
var key = (section.getAttribute('data-column-key') || '').toLowerCase();
section.style.display = allowedKeys.indexOf(key) >= 0 ? '' : 'none';
});
finishNavPermissionLoading();
})
.catch(function() {
showAllNavSections();
finishNavPermissionLoading();
});
})();
function showToast(msg) {
var el = document.getElementById('toast');
el.textContent = msg;
el.classList.add('show');
setTimeout(function() { el.classList.remove('show'); }, 2500);

File diff suppressed because it is too large Load Diff