|
@@ -7,19 +7,46 @@ from datetime import datetime
|
|
|
import uuid
|
|
import uuid
|
|
|
import time
|
|
import time
|
|
|
import os
|
|
import os
|
|
|
|
|
+import configparser
|
|
|
|
|
|
|
|
class PhoneQueryApp:
|
|
class PhoneQueryApp:
|
|
|
def __init__(self, root):
|
|
def __init__(self, root):
|
|
|
self.root = root
|
|
self.root = root
|
|
|
self.root.title("手机数据查询系统")
|
|
self.root.title("手机数据查询系统")
|
|
|
- self.root.geometry("1200x800")
|
|
|
|
|
|
|
+ self.root.geometry("1300x850")
|
|
|
|
|
+
|
|
|
|
|
+ # 配置文件
|
|
|
|
|
+ self.config_file = "config.ini"
|
|
|
|
|
+ self.token = self.load_token()
|
|
|
|
|
|
|
|
# 商品数据
|
|
# 商品数据
|
|
|
self.current_products = []
|
|
self.current_products = []
|
|
|
self.is_loading_cycles = False
|
|
self.is_loading_cycles = False
|
|
|
- self.collected_items = []
|
|
|
|
|
|
|
+ self.current_page = 0
|
|
|
|
|
+ self.total_pages = 0
|
|
|
|
|
+ self.page_size = 30
|
|
|
|
|
+ self.current_keyword = ""
|
|
|
|
|
+
|
|
|
|
|
+ # 筛选选项映射
|
|
|
|
|
+ self.memory_map = {
|
|
|
|
|
+ "1T": 187,
|
|
|
|
|
+ "512G": 192,
|
|
|
|
|
+ "256G": 209,
|
|
|
|
|
+ "128G": 210
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ self.battery_map = {
|
|
|
|
|
+ "100%": 1680,
|
|
|
|
|
+ "95%-99%": 5699,
|
|
|
|
|
+ "90%-95%": 5700,
|
|
|
|
|
+ "85%-90%": 5697,
|
|
|
|
|
+ "80%-85%": 5698,
|
|
|
|
|
+ "70%-80%": 6159,
|
|
|
|
|
+ "70%以下": 6160,
|
|
|
|
|
+ "不支持": 1627
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- # 状况标签映射(tagId -> 名称)
|
|
|
|
|
|
|
+ # 状况标签映射
|
|
|
self.condition_tags = {
|
|
self.condition_tags = {
|
|
|
10: "屏幕完美",
|
|
10: "屏幕完美",
|
|
|
11: "机身无痕",
|
|
11: "机身无痕",
|
|
@@ -33,27 +60,37 @@ class PhoneQueryApp:
|
|
|
21: "原厂部件"
|
|
21: "原厂部件"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- # 从文件读取cookie
|
|
|
|
|
- self.cookie = self.load_cookie()
|
|
|
|
|
-
|
|
|
|
|
- # 创建界面
|
|
|
|
|
self.create_widgets()
|
|
self.create_widgets()
|
|
|
|
|
+ self.result_tree.bind("<Button-3>", self.show_context_menu)
|
|
|
|
|
|
|
|
- def load_cookie(self):
|
|
|
|
|
- """从cookie.txt文件读取cookie"""
|
|
|
|
|
- cookie_file = "cookie.txt"
|
|
|
|
|
- if os.path.exists(cookie_file):
|
|
|
|
|
|
|
+ def load_token(self):
|
|
|
|
|
+ """从配置文件加载Token"""
|
|
|
|
|
+ if os.path.exists(self.config_file):
|
|
|
try:
|
|
try:
|
|
|
- with open(cookie_file, 'r', encoding='utf-8') as f:
|
|
|
|
|
- cookie = f.read().strip()
|
|
|
|
|
- print(f"已加载cookie: {cookie[:50]}...")
|
|
|
|
|
- return cookie
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- print(f"读取cookie文件失败: {e}")
|
|
|
|
|
- return ""
|
|
|
|
|
- else:
|
|
|
|
|
- print("cookie.txt文件不存在,请创建并放入cookie")
|
|
|
|
|
- return ""
|
|
|
|
|
|
|
+ config = configparser.ConfigParser()
|
|
|
|
|
+ config.read(self.config_file)
|
|
|
|
|
+ return config.get('Settings', 'token', fallback='dccf18b052ef46d78d4feb796182d5df')
|
|
|
|
|
+ except:
|
|
|
|
|
+ return 'dccf18b052ef46d78d4feb796182d5df'
|
|
|
|
|
+ return 'dccf18b052ef46d78d4feb796182d5df'
|
|
|
|
|
+
|
|
|
|
|
+ def save_token(self):
|
|
|
|
|
+ """保存Token到配置文件"""
|
|
|
|
|
+ try:
|
|
|
|
|
+ config = configparser.ConfigParser()
|
|
|
|
|
+ if os.path.exists(self.config_file):
|
|
|
|
|
+ config.read(self.config_file)
|
|
|
|
|
+ if not config.has_section('Settings'):
|
|
|
|
|
+ config.add_section('Settings')
|
|
|
|
|
+ config.set('Settings', 'token', self.token_var.get())
|
|
|
|
|
+ with open(self.config_file, 'w') as f:
|
|
|
|
|
+ config.write(f)
|
|
|
|
|
+ self.token = self.token_var.get()
|
|
|
|
|
+ messagebox.showinfo("成功", "Token已保存")
|
|
|
|
|
+ return True
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ messagebox.showerror("错误", f"保存Token失败: {e}")
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
def get_headers(self):
|
|
def get_headers(self):
|
|
|
"""获取请求头"""
|
|
"""获取请求头"""
|
|
@@ -62,7 +99,7 @@ class PhoneQueryApp:
|
|
|
"content-type": "application/json;charset=UTF-8",
|
|
"content-type": "application/json;charset=UTF-8",
|
|
|
"ahs-app-version": "7.49.3",
|
|
"ahs-app-version": "7.49.3",
|
|
|
"Ahs-Timestamp": str(int(datetime.now().timestamp())),
|
|
"Ahs-Timestamp": str(int(datetime.now().timestamp())),
|
|
|
- "Ahs-Token": "dccf18b052ef46d78d4feb796182d5df",
|
|
|
|
|
|
|
+ "Ahs-Token": self.token,
|
|
|
"Ahs-Session-Id": str(uuid.uuid4()),
|
|
"Ahs-Session-Id": str(uuid.uuid4()),
|
|
|
"Ahs-App-Id": "10007",
|
|
"Ahs-App-Id": "10007",
|
|
|
"Ahs-Device-Id": "3166e003-4ba7-4b57-8158-30859d81c7d5",
|
|
"Ahs-Device-Id": "3166e003-4ba7-4b57-8158-30859d81c7d5",
|
|
@@ -70,8 +107,7 @@ class PhoneQueryApp:
|
|
|
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 26_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.74(0x18004a2c) NetType/WIFI Language/zh_CN",
|
|
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 26_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.74(0x18004a2c) NetType/WIFI Language/zh_CN",
|
|
|
"Referer": "https://servicewechat.com/wx7e490492b4c23e98/1055/page-frame.html",
|
|
"Referer": "https://servicewechat.com/wx7e490492b4c23e98/1055/page-frame.html",
|
|
|
"Accept": "*/*",
|
|
"Accept": "*/*",
|
|
|
- "Accept-Encoding": "gzip, deflate, br",
|
|
|
|
|
- # "Cookie": self.cookie
|
|
|
|
|
|
|
+ "Accept-Encoding": "gzip, deflate, br"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
def create_widgets(self):
|
|
def create_widgets(self):
|
|
@@ -82,11 +118,24 @@ class PhoneQueryApp:
|
|
|
self.root.columnconfigure(0, weight=1)
|
|
self.root.columnconfigure(0, weight=1)
|
|
|
self.root.rowconfigure(0, weight=1)
|
|
self.root.rowconfigure(0, weight=1)
|
|
|
main_frame.columnconfigure(0, weight=1)
|
|
main_frame.columnconfigure(0, weight=1)
|
|
|
- main_frame.rowconfigure(2, weight=1)
|
|
|
|
|
|
|
+ main_frame.rowconfigure(5, weight=1)
|
|
|
|
|
+
|
|
|
|
|
+ # Token设置区域
|
|
|
|
|
+ token_frame = ttk.LabelFrame(main_frame, text="Token设置", padding="10")
|
|
|
|
|
+ token_frame.grid(row=0, column=0, sticky=(tk.W, tk.E), pady=(0, 10))
|
|
|
|
|
+ token_frame.columnconfigure(1, weight=1)
|
|
|
|
|
+
|
|
|
|
|
+ ttk.Label(token_frame, text="Ahs-Token:", font=("Arial", 10)).grid(row=0, column=0, sticky=tk.W, padx=(0, 10))
|
|
|
|
|
+ self.token_var = tk.StringVar(value=self.token)
|
|
|
|
|
+ self.token_entry = ttk.Entry(token_frame, textvariable=self.token_var, width=60, font=("Arial", 10))
|
|
|
|
|
+ self.token_entry.grid(row=0, column=1, sticky=(tk.W, tk.E), padx=(0, 10))
|
|
|
|
|
+
|
|
|
|
|
+ self.save_token_btn = ttk.Button(token_frame, text="保存Token", command=self.save_token, width=12)
|
|
|
|
|
+ self.save_token_btn.grid(row=0, column=2)
|
|
|
|
|
|
|
|
# 查询区域
|
|
# 查询区域
|
|
|
query_frame = ttk.LabelFrame(main_frame, text="查询条件", padding="10")
|
|
query_frame = ttk.LabelFrame(main_frame, text="查询条件", padding="10")
|
|
|
- query_frame.grid(row=0, column=0, sticky=(tk.W, tk.E), pady=(0, 10))
|
|
|
|
|
|
|
+ query_frame.grid(row=1, column=0, sticky=(tk.W, tk.E), pady=(0, 10))
|
|
|
query_frame.columnconfigure(1, weight=1)
|
|
query_frame.columnconfigure(1, weight=1)
|
|
|
|
|
|
|
|
ttk.Label(query_frame, text="机型:", font=("Arial", 11)).grid(row=0, column=0, sticky=tk.W, padx=(0, 10))
|
|
ttk.Label(query_frame, text="机型:", font=("Arial", 11)).grid(row=0, column=0, sticky=tk.W, padx=(0, 10))
|
|
@@ -97,26 +146,48 @@ class PhoneQueryApp:
|
|
|
self.search_btn = ttk.Button(query_frame, text="搜索", command=self.search_products, width=15)
|
|
self.search_btn = ttk.Button(query_frame, text="搜索", command=self.search_products, width=15)
|
|
|
self.search_btn.grid(row=0, column=2)
|
|
self.search_btn.grid(row=0, column=2)
|
|
|
|
|
|
|
|
- # 筛选区域
|
|
|
|
|
- filter_frame = ttk.LabelFrame(main_frame, text="筛选条件", padding="10")
|
|
|
|
|
- filter_frame.grid(row=1, column=0, sticky=(tk.W, tk.E), pady=(0, 10))
|
|
|
|
|
|
|
+ # ==================== 筛选区域 ====================
|
|
|
|
|
+ # 第一行:内存 + 电池效率(各占一半)
|
|
|
|
|
+ filter_row1 = ttk.Frame(main_frame)
|
|
|
|
|
+ filter_row1.grid(row=2, column=0, sticky=(tk.W, tk.E), pady=(0, 5))
|
|
|
|
|
+ filter_row1.columnconfigure(0, weight=1)
|
|
|
|
|
+ filter_row1.columnconfigure(1, weight=1)
|
|
|
|
|
|
|
|
- # 第一行:价格区间 和 成色
|
|
|
|
|
- # 价格区间
|
|
|
|
|
- price_frame = ttk.LabelFrame(filter_frame, text="价格区间", padding="5")
|
|
|
|
|
- price_frame.grid(row=0, column=0, sticky=(tk.W, tk.E), padx=5, pady=5)
|
|
|
|
|
|
|
+ # 内存筛选
|
|
|
|
|
+ memory_frame = ttk.LabelFrame(filter_row1, text="内存(多选)", padding="5")
|
|
|
|
|
+ memory_frame.grid(row=0, column=0, sticky=(tk.W, tk.E), padx=(0, 5))
|
|
|
|
|
|
|
|
- self.price_vars = {}
|
|
|
|
|
- price_options = ["0-1499", "1500-1999", "2000-2999", "3000-3999", "4000以上"]
|
|
|
|
|
- for i, option in enumerate(price_options):
|
|
|
|
|
|
|
+ self.memory_vars = {}
|
|
|
|
|
+ memory_options = ["1T", "512G", "256G", "128G"]
|
|
|
|
|
+ for i, option in enumerate(memory_options):
|
|
|
var = tk.BooleanVar()
|
|
var = tk.BooleanVar()
|
|
|
- self.price_vars[option] = var
|
|
|
|
|
- cb = ttk.Checkbutton(price_frame, text=option, variable=var)
|
|
|
|
|
- cb.grid(row=0, column=i, sticky=tk.W, padx=10, pady=2)
|
|
|
|
|
|
|
+ self.memory_vars[option] = var
|
|
|
|
|
+ cb = ttk.Checkbutton(memory_frame, text=option, variable=var)
|
|
|
|
|
+ cb.grid(row=0, column=i, sticky=tk.W, padx=15, pady=3)
|
|
|
|
|
|
|
|
- # 成色
|
|
|
|
|
- fineness_frame = ttk.LabelFrame(filter_frame, text="成色", padding="5")
|
|
|
|
|
- fineness_frame.grid(row=0, column=1, sticky=(tk.W, tk.E), padx=5, pady=5)
|
|
|
|
|
|
|
+ # 电池效率筛选
|
|
|
|
|
+ battery_frame = ttk.LabelFrame(filter_row1, text="电池效率(多选)", padding="5")
|
|
|
|
|
+ battery_frame.grid(row=0, column=1, sticky=(tk.W, tk.E), padx=(5, 0))
|
|
|
|
|
+
|
|
|
|
|
+ self.battery_vars = {}
|
|
|
|
|
+ battery_options = ["100%", "95%-99%", "90%-95%", "85%-90%", "80%-85%", "70%-80%", "70%以下", "不支持"]
|
|
|
|
|
+ for i, option in enumerate(battery_options):
|
|
|
|
|
+ var = tk.BooleanVar()
|
|
|
|
|
+ self.battery_vars[option] = var
|
|
|
|
|
+ row = i // 4
|
|
|
|
|
+ col = i % 4
|
|
|
|
|
+ cb = ttk.Checkbutton(battery_frame, text=option, variable=var)
|
|
|
|
|
+ cb.grid(row=row, column=col, sticky=tk.W, padx=10, pady=3)
|
|
|
|
|
+
|
|
|
|
|
+ # 第二行:成色 + 状况标签(各占一半)
|
|
|
|
|
+ filter_row2 = ttk.Frame(main_frame)
|
|
|
|
|
+ filter_row2.grid(row=3, column=0, sticky=(tk.W, tk.E), pady=(0, 5))
|
|
|
|
|
+ filter_row2.columnconfigure(0, weight=1)
|
|
|
|
|
+ filter_row2.columnconfigure(1, weight=1)
|
|
|
|
|
+
|
|
|
|
|
+ # 成色筛选
|
|
|
|
|
+ fineness_frame = ttk.LabelFrame(filter_row2, text="成色(多选)", padding="5")
|
|
|
|
|
+ fineness_frame.grid(row=0, column=0, sticky=(tk.W, tk.E), padx=(0, 5))
|
|
|
|
|
|
|
|
self.fineness_vars = {}
|
|
self.fineness_vars = {}
|
|
|
fineness_options = ["全新仅拆封", "准新机", "99新", "95新", "9成新", "8成新", "7成新"]
|
|
fineness_options = ["全新仅拆封", "准新机", "99新", "95新", "9成新", "8成新", "7成新"]
|
|
@@ -124,95 +195,118 @@ class PhoneQueryApp:
|
|
|
var = tk.BooleanVar()
|
|
var = tk.BooleanVar()
|
|
|
self.fineness_vars[option] = var
|
|
self.fineness_vars[option] = var
|
|
|
cb = ttk.Checkbutton(fineness_frame, text=option, variable=var)
|
|
cb = ttk.Checkbutton(fineness_frame, text=option, variable=var)
|
|
|
- cb.grid(row=0, column=i, sticky=tk.W, padx=10, pady=2)
|
|
|
|
|
|
|
+ cb.grid(row=0, column=i, sticky=tk.W, padx=10, pady=3)
|
|
|
|
|
|
|
|
- # 第二行:状况标签(占满整行)
|
|
|
|
|
- condition_frame = ttk.LabelFrame(filter_frame, text="状况标签", padding="5")
|
|
|
|
|
- condition_frame.grid(row=1, column=0, columnspan=2, sticky=(tk.W, tk.E), padx=5, pady=5)
|
|
|
|
|
|
|
+ # 状况标签筛选
|
|
|
|
|
+ condition_frame = ttk.LabelFrame(filter_row2, text="状况标签(多选)", padding="5")
|
|
|
|
|
+ condition_frame.grid(row=0, column=1, sticky=(tk.W, tk.E), padx=(5, 0))
|
|
|
|
|
|
|
|
self.condition_vars = {}
|
|
self.condition_vars = {}
|
|
|
- # 将状况标签分成两行显示,每行5个
|
|
|
|
|
condition_items = list(self.condition_tags.items())
|
|
condition_items = list(self.condition_tags.items())
|
|
|
for i, (tag_id, tag_name) in enumerate(condition_items):
|
|
for i, (tag_id, tag_name) in enumerate(condition_items):
|
|
|
var = tk.BooleanVar()
|
|
var = tk.BooleanVar()
|
|
|
self.condition_vars[tag_id] = var
|
|
self.condition_vars[tag_id] = var
|
|
|
- row = i // 5 # 每行5个
|
|
|
|
|
|
|
+ row = i // 5
|
|
|
col = i % 5
|
|
col = i % 5
|
|
|
cb = ttk.Checkbutton(condition_frame, text=tag_name, variable=var)
|
|
cb = ttk.Checkbutton(condition_frame, text=tag_name, variable=var)
|
|
|
- cb.grid(row=row, column=col, sticky=tk.W, padx=10, pady=2)
|
|
|
|
|
-
|
|
|
|
|
- filter_frame.columnconfigure(0, weight=1)
|
|
|
|
|
- filter_frame.columnconfigure(1, weight=1)
|
|
|
|
|
|
|
+ cb.grid(row=row, column=col, sticky=tk.W, padx=10, pady=3)
|
|
|
|
|
|
|
|
- # 结果显示区域
|
|
|
|
|
- result_frame = ttk.LabelFrame(main_frame, text="查询结果", padding="10")
|
|
|
|
|
- result_frame.grid(row=2, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
|
|
|
|
|
|
|
+ # ==================== 结果显示区域 ====================
|
|
|
|
|
+ result_frame = ttk.LabelFrame(main_frame, text="查询结果(可多选商品,点击批量收藏)", padding="10")
|
|
|
|
|
+ result_frame.grid(row=4, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
|
|
|
result_frame.columnconfigure(0, weight=1)
|
|
result_frame.columnconfigure(0, weight=1)
|
|
|
result_frame.rowconfigure(0, weight=1)
|
|
result_frame.rowconfigure(0, weight=1)
|
|
|
|
|
|
|
|
- columns = ("名称", "价格", "循环次数", "成色", "内存", "颜色", "网络制式")
|
|
|
|
|
- self.result_tree = ttk.Treeview(result_frame, columns=columns, show="headings", height=15)
|
|
|
|
|
|
|
+ # 添加电池效率列
|
|
|
|
|
+ columns = ("名称", "价格", "电池效率", "循环次数", "成色", "内存", "颜色", "网络制式")
|
|
|
|
|
+ self.result_tree = ttk.Treeview(result_frame, columns=columns, show="headings", height=15, selectmode="extended")
|
|
|
|
|
|
|
|
self.result_tree.heading("名称", text="名称")
|
|
self.result_tree.heading("名称", text="名称")
|
|
|
self.result_tree.heading("价格", text="价格")
|
|
self.result_tree.heading("价格", text="价格")
|
|
|
|
|
+ self.result_tree.heading("电池效率", text="电池效率")
|
|
|
self.result_tree.heading("循环次数", text="循环次数")
|
|
self.result_tree.heading("循环次数", text="循环次数")
|
|
|
self.result_tree.heading("成色", text="成色")
|
|
self.result_tree.heading("成色", text="成色")
|
|
|
self.result_tree.heading("内存", text="内存")
|
|
self.result_tree.heading("内存", text="内存")
|
|
|
self.result_tree.heading("颜色", text="颜色")
|
|
self.result_tree.heading("颜色", text="颜色")
|
|
|
self.result_tree.heading("网络制式", text="网络制式")
|
|
self.result_tree.heading("网络制式", text="网络制式")
|
|
|
|
|
|
|
|
- self.result_tree.column("名称", width=400)
|
|
|
|
|
- self.result_tree.column("价格", width=100)
|
|
|
|
|
- self.result_tree.column("循环次数", width=100)
|
|
|
|
|
- self.result_tree.column("成色", width=100)
|
|
|
|
|
- self.result_tree.column("内存", width=80)
|
|
|
|
|
- self.result_tree.column("颜色", width=100)
|
|
|
|
|
- self.result_tree.column("网络制式", width=100)
|
|
|
|
|
|
|
+ self.result_tree.column("名称", width=350)
|
|
|
|
|
+ self.result_tree.column("价格", width=90)
|
|
|
|
|
+ self.result_tree.column("电池效率", width=100)
|
|
|
|
|
+ self.result_tree.column("循环次数", width=90)
|
|
|
|
|
+ self.result_tree.column("成色", width=90)
|
|
|
|
|
+ self.result_tree.column("内存", width=70)
|
|
|
|
|
+ self.result_tree.column("颜色", width=90)
|
|
|
|
|
+ self.result_tree.column("网络制式", width=90)
|
|
|
|
|
|
|
|
scrollbar = ttk.Scrollbar(result_frame, orient=tk.VERTICAL, command=self.result_tree.yview)
|
|
scrollbar = ttk.Scrollbar(result_frame, orient=tk.VERTICAL, command=self.result_tree.yview)
|
|
|
self.result_tree.configure(yscrollcommand=scrollbar.set)
|
|
self.result_tree.configure(yscrollcommand=scrollbar.set)
|
|
|
self.result_tree.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
|
|
self.result_tree.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
|
|
|
scrollbar.grid(row=0, column=1, sticky=(tk.N, tk.S))
|
|
scrollbar.grid(row=0, column=1, sticky=(tk.N, tk.S))
|
|
|
|
|
|
|
|
- # 底部收藏栏
|
|
|
|
|
|
|
+ # ==================== 底部按钮栏 ====================
|
|
|
bottom_frame = ttk.Frame(main_frame)
|
|
bottom_frame = ttk.Frame(main_frame)
|
|
|
- bottom_frame.grid(row=3, column=0, sticky=(tk.W, tk.E), pady=(10, 0))
|
|
|
|
|
|
|
+ bottom_frame.grid(row=5, column=0, sticky=(tk.W, tk.E), pady=(10, 5))
|
|
|
|
|
|
|
|
- ttk.Label(bottom_frame, text="循环次数小于:", font=("Arial", 10)).pack(side=tk.LEFT, padx=(0, 5))
|
|
|
|
|
- self.cycle_threshold = ttk.Entry(bottom_frame, width=10, font=("Arial", 10))
|
|
|
|
|
- self.cycle_threshold.pack(side=tk.LEFT, padx=(0, 5))
|
|
|
|
|
- self.cycle_threshold.insert(0, "600")
|
|
|
|
|
- ttk.Label(bottom_frame, text="次的机型自动收藏", font=("Arial", 10)).pack(side=tk.LEFT, padx=(0, 20))
|
|
|
|
|
|
|
+ self.check_price_btn = ttk.Button(bottom_frame, text="获取循环次数", command=self.check_prices, width=18)
|
|
|
|
|
+ self.check_price_btn.pack(side=tk.LEFT, padx=(0, 10))
|
|
|
|
|
|
|
|
- self.collect_btn = ttk.Button(bottom_frame, text="启动", command=self.start_collect, width=10)
|
|
|
|
|
- self.collect_btn.pack(side=tk.LEFT)
|
|
|
|
|
|
|
+ self.batch_collect_btn = ttk.Button(bottom_frame, text="批量收藏所选商品", command=self.batch_collect, width=20)
|
|
|
|
|
+ self.batch_collect_btn.pack(side=tk.LEFT, padx=(0, 20))
|
|
|
|
|
|
|
|
self.progress_var = tk.StringVar()
|
|
self.progress_var = tk.StringVar()
|
|
|
self.progress_var.set("")
|
|
self.progress_var.set("")
|
|
|
ttk.Label(bottom_frame, textvariable=self.progress_var, font=("Arial", 9)).pack(side=tk.LEFT, padx=(20, 0))
|
|
ttk.Label(bottom_frame, textvariable=self.progress_var, font=("Arial", 9)).pack(side=tk.LEFT, padx=(20, 0))
|
|
|
|
|
|
|
|
- self.collect_count_var = tk.StringVar()
|
|
|
|
|
- self.collect_count_var.set("")
|
|
|
|
|
- ttk.Label(bottom_frame, textvariable=self.collect_count_var, font=("Arial", 9), foreground="green").pack(side=tk.LEFT, padx=(10, 0))
|
|
|
|
|
|
|
+ # ==================== 分页栏 ====================
|
|
|
|
|
+ pagination_frame = ttk.Frame(main_frame)
|
|
|
|
|
+ pagination_frame.grid(row=6, column=0, sticky=(tk.W, tk.E), pady=(0, 5))
|
|
|
|
|
+
|
|
|
|
|
+ self.prev_btn = ttk.Button(pagination_frame, text="上一页", command=self.prev_page, width=10)
|
|
|
|
|
+ self.prev_btn.pack(side=tk.LEFT, padx=(0, 10))
|
|
|
|
|
+
|
|
|
|
|
+ self.next_btn = ttk.Button(pagination_frame, text="下一页", command=self.next_page, width=10)
|
|
|
|
|
+ self.next_btn.pack(side=tk.LEFT, padx=(0, 20))
|
|
|
|
|
+
|
|
|
|
|
+ ttk.Label(pagination_frame, text="第").pack(side=tk.LEFT)
|
|
|
|
|
+ self.page_entry = ttk.Entry(pagination_frame, width=8)
|
|
|
|
|
+ self.page_entry.pack(side=tk.LEFT, padx=(5, 5))
|
|
|
|
|
+ ttk.Label(pagination_frame, text="页").pack(side=tk.LEFT)
|
|
|
|
|
+
|
|
|
|
|
+ self.jump_btn = ttk.Button(pagination_frame, text="跳转", command=self.jump_to_page, width=8)
|
|
|
|
|
+ self.jump_btn.pack(side=tk.LEFT, padx=(10, 20))
|
|
|
|
|
+
|
|
|
|
|
+ self.page_info_var = tk.StringVar()
|
|
|
|
|
+ self.page_info_var.set("第 0 / 0 页")
|
|
|
|
|
+ page_label = ttk.Label(pagination_frame, textvariable=self.page_info_var, font=("Arial", 9))
|
|
|
|
|
+ page_label.pack(side=tk.LEFT)
|
|
|
|
|
+
|
|
|
|
|
+ # ==================== 状态栏 ====================
|
|
|
|
|
+ status_frame = ttk.Frame(main_frame)
|
|
|
|
|
+ status_frame.grid(row=7, column=0, sticky=(tk.W, tk.E), pady=(5, 0))
|
|
|
|
|
|
|
|
- # 状态栏
|
|
|
|
|
self.status_var = tk.StringVar()
|
|
self.status_var = tk.StringVar()
|
|
|
self.status_var.set("就绪")
|
|
self.status_var.set("就绪")
|
|
|
- status_bar = ttk.Label(main_frame, textvariable=self.status_var, relief=tk.SUNKEN)
|
|
|
|
|
- status_bar.grid(row=4, column=0, sticky=(tk.W, tk.E), pady=(10, 0))
|
|
|
|
|
-
|
|
|
|
|
- def get_selected_prices(self):
|
|
|
|
|
- price_map = {
|
|
|
|
|
- "0-1499": (0, 1499),
|
|
|
|
|
- "1500-1999": (1500, 1999),
|
|
|
|
|
- "2000-2999": (2000, 2999),
|
|
|
|
|
- "3000-3999": (3000, 3999),
|
|
|
|
|
- "4000以上": (4000, 20000)
|
|
|
|
|
- }
|
|
|
|
|
- for option, var in self.price_vars.items():
|
|
|
|
|
|
|
+ status_bar = ttk.Label(status_frame, textvariable=self.status_var, relief=tk.SUNKEN)
|
|
|
|
|
+ status_bar.pack(side=tk.LEFT, fill=tk.X, expand=True)
|
|
|
|
|
+
|
|
|
|
|
+ self.update_pagination_buttons()
|
|
|
|
|
+
|
|
|
|
|
+ def get_selected_memory(self):
|
|
|
|
|
+ """获取选中的内存PPV ID列表"""
|
|
|
|
|
+ selected = []
|
|
|
|
|
+ for option, var in self.memory_vars.items():
|
|
|
|
|
+ if var.get():
|
|
|
|
|
+ selected.append(self.memory_map[option])
|
|
|
|
|
+ return selected
|
|
|
|
|
+
|
|
|
|
|
+ def get_selected_battery(self):
|
|
|
|
|
+ """获取选中的电池效率PPV ID列表"""
|
|
|
|
|
+ selected = []
|
|
|
|
|
+ for option, var in self.battery_vars.items():
|
|
|
if var.get():
|
|
if var.get():
|
|
|
- return price_map[option]
|
|
|
|
|
- return (0, 20000)
|
|
|
|
|
|
|
+ selected.append(self.battery_map[option])
|
|
|
|
|
+ return selected
|
|
|
|
|
|
|
|
def get_selected_fineness(self):
|
|
def get_selected_fineness(self):
|
|
|
fineness_map = {
|
|
fineness_map = {
|
|
@@ -228,63 +322,94 @@ class PhoneQueryApp:
|
|
|
for option, var in self.fineness_vars.items():
|
|
for option, var in self.fineness_vars.items():
|
|
|
if var.get():
|
|
if var.get():
|
|
|
selected.append(fineness_map[option])
|
|
selected.append(fineness_map[option])
|
|
|
- return selected if selected else [99, 100, 111, 95, 90, 80, 70]
|
|
|
|
|
|
|
+ return selected
|
|
|
|
|
|
|
|
def get_selected_condition_tags(self):
|
|
def get_selected_condition_tags(self):
|
|
|
- """获取选中的状况标签ID列表"""
|
|
|
|
|
selected = []
|
|
selected = []
|
|
|
for tag_id, var in self.condition_vars.items():
|
|
for tag_id, var in self.condition_vars.items():
|
|
|
if var.get():
|
|
if var.get():
|
|
|
selected.append(tag_id)
|
|
selected.append(tag_id)
|
|
|
return selected
|
|
return selected
|
|
|
|
|
|
|
|
- def search_products(self):
|
|
|
|
|
|
|
+ def get_battery_efficiency(self, condition_labels):
|
|
|
|
|
+ """从conditionLabels中提取电池效率"""
|
|
|
|
|
+ if not condition_labels:
|
|
|
|
|
+ return ""
|
|
|
|
|
+
|
|
|
|
|
+ for label in condition_labels:
|
|
|
|
|
+ if label.get('group') in ['原厂电池', '第三方电池']:
|
|
|
|
|
+ return label.get('label', '')
|
|
|
|
|
+ return ""
|
|
|
|
|
+
|
|
|
|
|
+ def search_products(self, page=0):
|
|
|
keyword = self.model_entry.get().strip()
|
|
keyword = self.model_entry.get().strip()
|
|
|
if not keyword:
|
|
if not keyword:
|
|
|
messagebox.showwarning("警告", "请输入机型")
|
|
messagebox.showwarning("警告", "请输入机型")
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
|
|
+ self.current_keyword = keyword
|
|
|
|
|
+ self.current_page = page
|
|
|
|
|
+
|
|
|
for item in self.result_tree.get_children():
|
|
for item in self.result_tree.get_children():
|
|
|
self.result_tree.delete(item)
|
|
self.result_tree.delete(item)
|
|
|
self.current_products.clear()
|
|
self.current_products.clear()
|
|
|
- self.collected_items.clear()
|
|
|
|
|
self.progress_var.set("")
|
|
self.progress_var.set("")
|
|
|
- self.collect_count_var.set("")
|
|
|
|
|
- self.collect_btn.config(state="normal")
|
|
|
|
|
|
|
+ self.check_price_btn.config(state="normal")
|
|
|
|
|
+ self.batch_collect_btn.config(state="normal")
|
|
|
|
|
|
|
|
self.status_var.set("正在搜索...")
|
|
self.status_var.set("正在搜索...")
|
|
|
self.search_btn.config(state="disabled")
|
|
self.search_btn.config(state="disabled")
|
|
|
|
|
+ self.prev_btn.config(state="disabled")
|
|
|
|
|
+ self.next_btn.config(state="disabled")
|
|
|
|
|
+ self.jump_btn.config(state="disabled")
|
|
|
|
|
|
|
|
- thread = threading.Thread(target=self.do_search, args=(keyword,))
|
|
|
|
|
|
|
+ thread = threading.Thread(target=self.do_search, args=(keyword, page))
|
|
|
thread.daemon = True
|
|
thread.daemon = True
|
|
|
thread.start()
|
|
thread.start()
|
|
|
|
|
|
|
|
- def do_search(self, keyword):
|
|
|
|
|
|
|
+ def do_search(self, keyword, page):
|
|
|
try:
|
|
try:
|
|
|
- min_price, max_price = self.get_selected_prices()
|
|
|
|
|
|
|
+ # 获取筛选条件
|
|
|
|
|
+ memory_ids = self.get_selected_memory()
|
|
|
|
|
+ battery_ids = self.get_selected_battery()
|
|
|
fineness_ids = self.get_selected_fineness()
|
|
fineness_ids = self.get_selected_fineness()
|
|
|
condition_tags = self.get_selected_condition_tags()
|
|
condition_tags = self.get_selected_condition_tags()
|
|
|
|
|
|
|
|
request_data = {
|
|
request_data = {
|
|
|
- "minPrice": min_price,
|
|
|
|
|
- "maxPrice": max_price,
|
|
|
|
|
"sortValue": "sort_composite",
|
|
"sortValue": "sort_composite",
|
|
|
- "gaeaPricePpvIds": {},
|
|
|
|
|
- "gaeaFinenessIds": fineness_ids,
|
|
|
|
|
- "conditionTagList": condition_tags, # 使用选中的状况标签
|
|
|
|
|
"scene": "search",
|
|
"scene": "search",
|
|
|
"keyword": keyword,
|
|
"keyword": keyword,
|
|
|
"sirReq": False,
|
|
"sirReq": False,
|
|
|
"cityId": 324,
|
|
"cityId": 324,
|
|
|
- "pageIndex": 0,
|
|
|
|
|
- "pageSize": 50
|
|
|
|
|
|
|
+ "pageIndex": page,
|
|
|
|
|
+ "pageSize": self.page_size
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ # 添加内存筛选(使用 gaeaSkuPpvIds)
|
|
|
|
|
+ if memory_ids:
|
|
|
|
|
+ request_data["gaeaSkuPpvIds"] = {
|
|
|
|
|
+ "22": memory_ids # 22是内存的ppnId
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # 添加电池效率筛选(使用 gaeaPricePpvIds)
|
|
|
|
|
+ if battery_ids:
|
|
|
|
|
+ request_data["gaeaPricePpvIds"] = {
|
|
|
|
|
+ "473": battery_ids # 473是电池效率的ppnId
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # 添加成色筛选
|
|
|
|
|
+ if fineness_ids:
|
|
|
|
|
+ request_data["gaeaFinenessIds"] = fineness_ids
|
|
|
|
|
+
|
|
|
|
|
+ # 添加状况标签筛选
|
|
|
|
|
+ if condition_tags:
|
|
|
|
|
+ request_data["conditionTagList"] = condition_tags
|
|
|
|
|
+
|
|
|
url = "https://dubai-mp.aihuishou.com/ahs-yanxuan-service/products/search-goods-v2"
|
|
url = "https://dubai-mp.aihuishou.com/ahs-yanxuan-service/products/search-goods-v2"
|
|
|
response = requests.post(url, json=request_data, headers=self.get_headers(), timeout=30)
|
|
response = requests.post(url, json=request_data, headers=self.get_headers(), timeout=30)
|
|
|
result = response.json()
|
|
result = response.json()
|
|
|
-
|
|
|
|
|
- self.root.after(0, self.display_results, result)
|
|
|
|
|
|
|
+ print("请求参数:", json.dumps(request_data, ensure_ascii=False))
|
|
|
|
|
+ self.root.after(0, self.display_results, result, page)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
self.root.after(0, self.show_error, str(e))
|
|
self.root.after(0, self.show_error, str(e))
|
|
@@ -294,32 +419,42 @@ class PhoneQueryApp:
|
|
|
sale_goods_no = product.get('saleGoodsNo', '')
|
|
sale_goods_no = product.get('saleGoodsNo', '')
|
|
|
product_no = product.get('productNo', '')
|
|
product_no = product.get('productNo', '')
|
|
|
|
|
|
|
|
|
|
+ # 提取颜色
|
|
|
color = ""
|
|
color = ""
|
|
|
- memory = product.get('memoryDesc', '')
|
|
|
|
|
-
|
|
|
|
|
- if '黑色' in name:
|
|
|
|
|
- color = "黑色"
|
|
|
|
|
- elif '白色' in name:
|
|
|
|
|
- color = "白色"
|
|
|
|
|
- elif '蓝色' in name:
|
|
|
|
|
- color = "蓝色"
|
|
|
|
|
- elif '原色' in name:
|
|
|
|
|
- color = "原色"
|
|
|
|
|
-
|
|
|
|
|
|
|
+ color_keywords = ['黑色', '白色', '蓝色', '原色', '金色', '银色', '石墨色', '紫色', '绿色', '粉色', '红色', '黄色', '暗紫色', '深空黑色']
|
|
|
|
|
+ for keyword in color_keywords:
|
|
|
|
|
+ if keyword in name:
|
|
|
|
|
+ color = keyword
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ # 获取电池效率
|
|
|
|
|
+ condition_labels = product.get('conditionLabels', [])
|
|
|
|
|
+ battery_efficiency = self.get_battery_efficiency(condition_labels)
|
|
|
|
|
+
|
|
|
|
|
+ # 如果conditionLabels中没有,从productTag中获取
|
|
|
|
|
+ if not battery_efficiency:
|
|
|
|
|
+ product_tags = product.get('productTag', [])
|
|
|
|
|
+ for tag in product_tags:
|
|
|
|
|
+ if '电池' in tag:
|
|
|
|
|
+ battery_efficiency = tag
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
'name': name[:50],
|
|
'name': name[:50],
|
|
|
'price': product.get('price', 0),
|
|
'price': product.get('price', 0),
|
|
|
|
|
+ 'battery_efficiency': battery_efficiency,
|
|
|
'cycle_count': '',
|
|
'cycle_count': '',
|
|
|
'fineness': product.get('gaeaFinenessName', ''),
|
|
'fineness': product.get('gaeaFinenessName', ''),
|
|
|
- 'memory': memory,
|
|
|
|
|
|
|
+ 'memory': product.get('memoryDesc', ''),
|
|
|
'color': color,
|
|
'color': color,
|
|
|
'network': "全网通",
|
|
'network': "全网通",
|
|
|
'saleGoodsNo': sale_goods_no,
|
|
'saleGoodsNo': sale_goods_no,
|
|
|
'productNo': product_no
|
|
'productNo': product_no
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- def display_results(self, result):
|
|
|
|
|
|
|
+ def display_results(self, result, page):
|
|
|
self.search_btn.config(state="normal")
|
|
self.search_btn.config(state="normal")
|
|
|
|
|
+ self.jump_btn.config(state="normal")
|
|
|
|
|
|
|
|
if result.get('code') != 0:
|
|
if result.get('code') != 0:
|
|
|
self.status_var.set(f"查询失败: {result.get('resultMessage', '未知错误')}")
|
|
self.status_var.set(f"查询失败: {result.get('resultMessage', '未知错误')}")
|
|
@@ -327,16 +462,33 @@ class PhoneQueryApp:
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
data = result.get('data', [])
|
|
data = result.get('data', [])
|
|
|
|
|
+ total_count = result.get('totalCount', 0)
|
|
|
|
|
+
|
|
|
|
|
+ if total_count > 0:
|
|
|
|
|
+ self.total_pages = (total_count + self.page_size - 1) // self.page_size
|
|
|
|
|
+ else:
|
|
|
|
|
+ if len(data) < self.page_size:
|
|
|
|
|
+ self.total_pages = page + 1
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.total_pages = page + 2
|
|
|
|
|
+
|
|
|
if not data:
|
|
if not data:
|
|
|
self.status_var.set("未找到相关产品")
|
|
self.status_var.set("未找到相关产品")
|
|
|
messagebox.showinfo("提示", "未找到相关产品")
|
|
messagebox.showinfo("提示", "未找到相关产品")
|
|
|
|
|
+ self.update_pagination_buttons()
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
for product in data:
|
|
for product in data:
|
|
|
info = self.parse_product_info(product)
|
|
info = self.parse_product_info(product)
|
|
|
item_id = self.result_tree.insert("", tk.END, values=(
|
|
item_id = self.result_tree.insert("", tk.END, values=(
|
|
|
- info['name'], f"¥{info['price']}", info['cycle_count'],
|
|
|
|
|
- info['fineness'], info['memory'], info['color'], info['network']
|
|
|
|
|
|
|
+ info['name'],
|
|
|
|
|
+ f"¥{info['price']}",
|
|
|
|
|
+ info['battery_efficiency'],
|
|
|
|
|
+ info['cycle_count'],
|
|
|
|
|
+ info['fineness'],
|
|
|
|
|
+ info['memory'],
|
|
|
|
|
+ info['color'],
|
|
|
|
|
+ info['network']
|
|
|
))
|
|
))
|
|
|
self.current_products.append({
|
|
self.current_products.append({
|
|
|
'item_id': item_id,
|
|
'item_id': item_id,
|
|
@@ -345,8 +497,48 @@ class PhoneQueryApp:
|
|
|
'info': info
|
|
'info': info
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- self.status_var.set(f"共找到 {len(data)} 条结果")
|
|
|
|
|
|
|
+ self.status_var.set(f"第 {page + 1} 页,共找到 {len(data)} 条结果")
|
|
|
|
|
+ self.update_pagination_buttons()
|
|
|
|
|
|
|
|
|
|
+ def update_pagination_buttons(self):
|
|
|
|
|
+ self.page_info_var.set(f"第 {self.current_page + 1} / {self.total_pages if self.total_pages > 0 else 1} 页")
|
|
|
|
|
+
|
|
|
|
|
+ if self.current_page <= 0:
|
|
|
|
|
+ self.prev_btn.config(state="disabled")
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.prev_btn.config(state="normal")
|
|
|
|
|
+ self.next_btn.config(state="normal")
|
|
|
|
|
+
|
|
|
|
|
+ if self.total_pages > 0 and self.current_page >= self.total_pages - 1:
|
|
|
|
|
+ self.next_btn.config(state="disabled")
|
|
|
|
|
+ else:
|
|
|
|
|
+ if len(self.current_products) >= self.page_size:
|
|
|
|
|
+ self.next_btn.config(state="normal")
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.next_btn.config(state="disabled")
|
|
|
|
|
+
|
|
|
|
|
+ def prev_page(self):
|
|
|
|
|
+ if self.current_page > 0:
|
|
|
|
|
+ self.search_products(self.current_page - 1)
|
|
|
|
|
+
|
|
|
|
|
+ def next_page(self):
|
|
|
|
|
+ if self.total_pages == 0 or self.current_page < self.total_pages - 1:
|
|
|
|
|
+ self.search_products(self.current_page + 1)
|
|
|
|
|
+
|
|
|
|
|
+ def jump_to_page(self):
|
|
|
|
|
+ try:
|
|
|
|
|
+ page_num = int(self.page_entry.get().strip())
|
|
|
|
|
+ if page_num < 1:
|
|
|
|
|
+ messagebox.showwarning("警告", "页码必须大于0")
|
|
|
|
|
+ return
|
|
|
|
|
+ if self.total_pages > 0 and page_num > self.total_pages:
|
|
|
|
|
+ messagebox.showwarning("警告", f"页码不能超过 {self.total_pages}")
|
|
|
|
|
+ return
|
|
|
|
|
+ self.search_products(page_num - 1)
|
|
|
|
|
+ self.page_entry.delete(0, tk.END)
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ messagebox.showwarning("警告", "请输入有效的页码")
|
|
|
|
|
+
|
|
|
def get_cycle_count(self, sale_goods_no):
|
|
def get_cycle_count(self, sale_goods_no):
|
|
|
"""获取商品的电池循环次数"""
|
|
"""获取商品的电池循环次数"""
|
|
|
try:
|
|
try:
|
|
@@ -372,7 +564,6 @@ class PhoneQueryApp:
|
|
|
return ''
|
|
return ''
|
|
|
|
|
|
|
|
def add_to_collection(self, item_no):
|
|
def add_to_collection(self, item_no):
|
|
|
- """调用收藏接口添加收藏"""
|
|
|
|
|
try:
|
|
try:
|
|
|
url = "https://dubai-mp.aihuishou.com/ahs-yanxuan-service/collect/save"
|
|
url = "https://dubai-mp.aihuishou.com/ahs-yanxuan-service/collect/save"
|
|
|
payload = json.dumps({"itemNo": item_no, "type": 1})
|
|
payload = json.dumps({"itemNo": item_no, "type": 1})
|
|
@@ -381,7 +572,6 @@ class PhoneQueryApp:
|
|
|
response = requests.post(url, data=payload, headers=headers, timeout=10)
|
|
response = requests.post(url, data=payload, headers=headers, timeout=10)
|
|
|
result = response.json()
|
|
result = response.json()
|
|
|
|
|
|
|
|
- # 根据实际返回判断:code为200且data为True表示成功
|
|
|
|
|
if result.get('code') == 200 and result.get('data') == True:
|
|
if result.get('code') == 200 and result.get('data') == True:
|
|
|
return True, "收藏成功"
|
|
return True, "收藏成功"
|
|
|
else:
|
|
else:
|
|
@@ -389,84 +579,142 @@ class PhoneQueryApp:
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
return False, str(e)
|
|
return False, str(e)
|
|
|
|
|
|
|
|
- def start_collect(self):
|
|
|
|
|
- if not self.current_products:
|
|
|
|
|
- messagebox.showwarning("警告", "请先搜索商品")
|
|
|
|
|
|
|
+ def batch_collect(self):
|
|
|
|
|
+ selected_items = self.result_tree.selection()
|
|
|
|
|
+ if not selected_items:
|
|
|
|
|
+ messagebox.showwarning("警告", "请先选择要收藏的商品(可多选)")
|
|
|
return
|
|
return
|
|
|
- if self.is_loading_cycles:
|
|
|
|
|
- messagebox.showinfo("提示", "正在处理中,请稍候...")
|
|
|
|
|
|
|
+
|
|
|
|
|
+ result = messagebox.askyesno("确认收藏", f"确定要收藏选中的 {len(selected_items)} 个商品吗?")
|
|
|
|
|
+ if not result:
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- if not self.cookie:
|
|
|
|
|
- result = messagebox.askyesno("提示", "未找到cookie.txt文件或cookie为空,是否继续?")
|
|
|
|
|
- if not result:
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ thread = threading.Thread(target=self.process_batch_collect, args=(selected_items,))
|
|
|
|
|
+ thread.daemon = True
|
|
|
|
|
+ thread.start()
|
|
|
|
|
+
|
|
|
|
|
+ def process_batch_collect(self, selected_items):
|
|
|
|
|
+ self.batch_collect_btn.config(state="disabled")
|
|
|
|
|
+ self.check_price_btn.config(state="disabled")
|
|
|
|
|
+
|
|
|
|
|
+ success_count = 0
|
|
|
|
|
+ fail_count = 0
|
|
|
|
|
+ total = len(selected_items)
|
|
|
|
|
+
|
|
|
|
|
+ for i, item_id in enumerate(selected_items):
|
|
|
|
|
+ product = None
|
|
|
|
|
+ for p in self.current_products:
|
|
|
|
|
+ if p['item_id'] == item_id:
|
|
|
|
|
+ product = p
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if product:
|
|
|
|
|
+ item_no = product['productNo'] or product['saleGoodsNo']
|
|
|
|
|
+ self.root.after(0, lambda txt=f"收藏中: {i+1}/{total}": self.progress_var.set(txt))
|
|
|
|
|
+
|
|
|
|
|
+ success, msg = self.add_to_collection(item_no)
|
|
|
|
|
+
|
|
|
|
|
+ if success:
|
|
|
|
|
+ success_count += 1
|
|
|
|
|
+ else:
|
|
|
|
|
+ fail_count += 1
|
|
|
|
|
+ print(f"收藏失败: {product['info']['name']} - {msg}")
|
|
|
|
|
+
|
|
|
|
|
+ time.sleep(0.2)
|
|
|
|
|
+
|
|
|
|
|
+ self.root.after(0, lambda: self.finish_batch_collect(success_count, fail_count, total))
|
|
|
|
|
+
|
|
|
|
|
+ def finish_batch_collect(self, success_count, fail_count, total):
|
|
|
|
|
+ self.batch_collect_btn.config(state="normal")
|
|
|
|
|
+ self.check_price_btn.config(state="normal")
|
|
|
|
|
+ self.progress_var.set("")
|
|
|
|
|
+
|
|
|
|
|
+ if fail_count == 0:
|
|
|
|
|
+ self.status_var.set(f"批量收藏完成!成功收藏 {success_count} 个商品")
|
|
|
|
|
+ messagebox.showinfo("批量收藏完成", f"成功收藏 {success_count} 个商品!")
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.status_var.set(f"批量收藏完成:成功 {success_count},失败 {fail_count}")
|
|
|
|
|
+ messagebox.showwarning("批量收藏完成", f"成功收藏 {success_count} 个商品\n失败 {fail_count} 个商品")
|
|
|
|
|
|
|
|
- try:
|
|
|
|
|
- threshold = int(self.cycle_threshold.get().strip())
|
|
|
|
|
- except ValueError:
|
|
|
|
|
- messagebox.showerror("错误", "请输入有效的循环次数")
|
|
|
|
|
|
|
+ def check_prices(self):
|
|
|
|
|
+ if not self.current_products:
|
|
|
|
|
+ messagebox.showwarning("警告", "请先搜索商品")
|
|
|
|
|
+ return
|
|
|
|
|
+ if self.is_loading_cycles:
|
|
|
|
|
+ messagebox.showinfo("提示", "正在获取中,请稍候...")
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- thread = threading.Thread(target=self.process_collect, args=(threshold,))
|
|
|
|
|
|
|
+ thread = threading.Thread(target=self.process_check_prices)
|
|
|
thread.daemon = True
|
|
thread.daemon = True
|
|
|
thread.start()
|
|
thread.start()
|
|
|
|
|
|
|
|
- def process_collect(self, threshold):
|
|
|
|
|
- """处理收藏:获取循环次数并收藏符合条件的商品"""
|
|
|
|
|
|
|
+ def process_check_prices(self):
|
|
|
self.is_loading_cycles = True
|
|
self.is_loading_cycles = True
|
|
|
- self.collect_btn.config(state="disabled")
|
|
|
|
|
- self.collected_items.clear()
|
|
|
|
|
|
|
+ self.check_price_btn.config(state="disabled")
|
|
|
|
|
+ self.batch_collect_btn.config(state="disabled")
|
|
|
|
|
|
|
|
total = len(self.current_products)
|
|
total = len(self.current_products)
|
|
|
- collected_count = 0
|
|
|
|
|
|
|
|
|
|
for i, product in enumerate(self.current_products):
|
|
for i, product in enumerate(self.current_products):
|
|
|
- self.root.after(0, lambda txt=f"处理: {i+1}/{total}": self.progress_var.set(txt))
|
|
|
|
|
- self.root.after(0, lambda i=i: self.status_var.set(f"正在获取循环次数 ({i+1}/{total})..."))
|
|
|
|
|
|
|
+ self.root.after(0, lambda txt=f"获取中: {i+1}/{total}": self.progress_var.set(txt))
|
|
|
|
|
|
|
|
cycle_count = self.get_cycle_count(product['saleGoodsNo'])
|
|
cycle_count = self.get_cycle_count(product['saleGoodsNo'])
|
|
|
|
|
|
|
|
if cycle_count:
|
|
if cycle_count:
|
|
|
values = list(self.result_tree.item(product['item_id'], 'values'))
|
|
values = list(self.result_tree.item(product['item_id'], 'values'))
|
|
|
- values[2] = cycle_count
|
|
|
|
|
|
|
+ values[3] = cycle_count
|
|
|
self.root.after(0, lambda pid=product['item_id'], vals=values: self.result_tree.item(pid, values=vals))
|
|
self.root.after(0, lambda pid=product['item_id'], vals=values: self.result_tree.item(pid, values=vals))
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- cycle_num = int(cycle_count)
|
|
|
|
|
-
|
|
|
|
|
- if cycle_num < threshold:
|
|
|
|
|
- item_no = product['productNo'] or product['saleGoodsNo']
|
|
|
|
|
- success, msg = self.add_to_collection(item_no)
|
|
|
|
|
-
|
|
|
|
|
- if success:
|
|
|
|
|
- collected_count += 1
|
|
|
|
|
- self.collected_items.append(f"{product['info']['name']} ({cycle_num}次)")
|
|
|
|
|
- self.root.after(0, lambda: self.status_var.set(f"✓ 已收藏: {product['info']['name'][:30]}"))
|
|
|
|
|
- except ValueError:
|
|
|
|
|
- pass
|
|
|
|
|
|
|
|
|
|
time.sleep(0.3)
|
|
time.sleep(0.3)
|
|
|
|
|
|
|
|
- self.root.after(0, lambda: self.finish_collect(collected_count, threshold))
|
|
|
|
|
|
|
+ self.root.after(0, self.finish_check_prices)
|
|
|
|
|
|
|
|
- def finish_collect(self, collected_count, threshold):
|
|
|
|
|
|
|
+ def finish_check_prices(self):
|
|
|
self.is_loading_cycles = False
|
|
self.is_loading_cycles = False
|
|
|
- self.collect_btn.config(state="normal")
|
|
|
|
|
|
|
+ self.check_price_btn.config(state="normal")
|
|
|
|
|
+ self.batch_collect_btn.config(state="normal")
|
|
|
self.progress_var.set("")
|
|
self.progress_var.set("")
|
|
|
- self.collect_count_var.set(f"已收藏: {collected_count} 件")
|
|
|
|
|
- self.status_var.set(f"完成!处理 {len(self.current_products)} 条,收藏 {collected_count} 件")
|
|
|
|
|
-
|
|
|
|
|
- if collected_count > 0:
|
|
|
|
|
- detail = "\n".join(self.collected_items[:5])
|
|
|
|
|
- if len(self.collected_items) > 5:
|
|
|
|
|
- detail += f"\n... 等共{collected_count}件"
|
|
|
|
|
- messagebox.showinfo("收藏完成", f"已成功收藏 {collected_count} 件商品\n\n{detail}")
|
|
|
|
|
- else:
|
|
|
|
|
- messagebox.showinfo("完成", f"没有找到循环次数小于 {threshold} 的商品")
|
|
|
|
|
|
|
+ self.status_var.set(f"完成!已获取 {len(self.current_products)} 条商品的循环次数")
|
|
|
|
|
+ messagebox.showinfo("完成", f"已成功获取 {len(self.current_products)} 条商品的循环次数")
|
|
|
|
|
+
|
|
|
|
|
+ def show_context_menu(self, event):
|
|
|
|
|
+ item = self.result_tree.identify_row(event.y)
|
|
|
|
|
+ if not item:
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ self.result_tree.selection_set(item)
|
|
|
|
|
+ values = self.result_tree.item(item, 'values')
|
|
|
|
|
+ product_name = values[0]
|
|
|
|
|
+ battery = values[2]
|
|
|
|
|
+ cycle_count = values[3]
|
|
|
|
|
+
|
|
|
|
|
+ menu = tk.Menu(self.root, tearoff=0)
|
|
|
|
|
+ menu.add_command(label=f"收藏: {product_name[:30]}", command=lambda: self.collect_single_item(item))
|
|
|
|
|
+ if battery:
|
|
|
|
|
+ menu.add_command(label=f"电池: {battery}", command=None, state="disabled")
|
|
|
|
|
+ if cycle_count:
|
|
|
|
|
+ menu.add_command(label=f"循环次数: {cycle_count}", command=None, state="disabled")
|
|
|
|
|
+ menu.add_separator()
|
|
|
|
|
+ menu.add_command(label="取消", command=None)
|
|
|
|
|
+ menu.post(event.x_root, event.y_root)
|
|
|
|
|
+
|
|
|
|
|
+ def collect_single_item(self, item):
|
|
|
|
|
+ for product in self.current_products:
|
|
|
|
|
+ if product['item_id'] == item:
|
|
|
|
|
+ item_no = product['productNo'] or product['saleGoodsNo']
|
|
|
|
|
+ success, msg = self.add_to_collection(item_no)
|
|
|
|
|
+
|
|
|
|
|
+ if success:
|
|
|
|
|
+ self.status_var.set(f"✓ 收藏成功: {product['info']['name'][:30]}")
|
|
|
|
|
+ messagebox.showinfo("收藏成功", f"已成功收藏\n{product['info']['name']}")
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.status_var.set(f"✗ 收藏失败: {msg}")
|
|
|
|
|
+ messagebox.showerror("收藏失败", f"收藏失败\n{product['info']['name']}\n错误: {msg}")
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
def show_error(self, error_msg):
|
|
def show_error(self, error_msg):
|
|
|
self.search_btn.config(state="normal")
|
|
self.search_btn.config(state="normal")
|
|
|
|
|
+ self.jump_btn.config(state="normal")
|
|
|
self.status_var.set(f"查询失败: {error_msg}")
|
|
self.status_var.set(f"查询失败: {error_msg}")
|
|
|
messagebox.showerror("错误", f"查询失败: {error_msg}")
|
|
messagebox.showerror("错误", f"查询失败: {error_msg}")
|
|
|
|
|
|