From f9c2c5f37d5124c2a0dc7e42538dbaf8da2f463f Mon Sep 17 00:00:00 2001 From: BestLemoon <53417050+BestLemoon@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:13:53 +0800 Subject: [PATCH] Add delivery_info --- menu/SelectProfileTable.py | 44 ++++++++++++++++++++++++++++++++++---- menu/TicketOptions.py | 24 +++++++++++++++------ util/JsonUtil.py | 7 ++++++ 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/menu/SelectProfileTable.py b/menu/SelectProfileTable.py index b5dd398..33ddcd8 100644 --- a/menu/SelectProfileTable.py +++ b/menu/SelectProfileTable.py @@ -3,19 +3,24 @@ from config import cookies_config_path from util.BiliRequest import BiliRequest -from util.JsonUtil import ProfileInfo +from util.JsonUtil import ProfileInfo, AddrInfo class SelectProfileTable: - def __init__(self, master, data, max_selections, onSubmitPersons): + def __init__(self, master, data, addr_data, max_selections,onSubmitPersons,onSubmitAddr): self.profileInfo = ProfileInfo(data) + self.addrInfo = AddrInfo(addr_data) self.master = master self.onSubmitPersons = onSubmitPersons + self.onSubmitAddr = onSubmitAddr self.master.title("选人") self.persons = self.profileInfo.get_persons() + self.addrs = self.addrInfo.get_addrs() self.max_selections = max_selections self.selected_indices = set() + self.addr_indices=set() + # select person self.listbox = tk.Listbox(master, selectmode=tk.MULTIPLE, width=50) self.listbox.grid(row=0, column=0, padx=10, pady=10, sticky=tk.W) for person in self.persons: @@ -23,9 +28,20 @@ def __init__(self, master, data, max_selections, onSubmitPersons): self.listbox.insert(tk.END, f"{name}") self.listbox.itemconfig(tk.END, {'fg': "black"}) + # select address + self.addr_listbox = tk.Listbox(master, selectmode=tk.SINGLE, width=50) + self.addr_listbox.grid(row=1, column=0, padx=10, pady=10, sticky=tk.W) + for addr in self.addrs: + name = addr['name'] + self.addr_listbox.insert(tk.END, f"{name}") + self.addr_listbox.itemconfig(tk.END, {'fg': "black"}) + self.detail_text = tk.Text(master, height=10, width=40) self.detail_text.grid(row=0, column=1, padx=10, pady=10, sticky=tk.W) + self.addr_text=tk.Text(master, height=10, width=40) + self.addr_text.grid(row=1, column=1, padx=10, pady=10, sticky=tk.W) + self.submit_button = ttk.Button(master, text="提交", command=self.submit_booking) self.submit_button.grid(row=2, column=0, columnspan=2, pady=10) @@ -33,8 +49,10 @@ def __init__(self, master, data, max_selections, onSubmitPersons): self.displayed_number_label.grid(row=2, column=0, pady=10) self.listbox.bind('<>', self.display_ticket_details) + self.addr_listbox.bind('<>', self.display_address_details) - def display_ticket_details(self, event): + + def display_ticket_details(self,event): selected_indices = self.listbox.curselection() if selected_indices: self.selected_indices = set(selected_indices) @@ -47,10 +65,26 @@ def display_ticket_details(self, event): self.detail_text.delete(1.0, tk.END) self.detail_text.insert(tk.END, details) + def display_address_details(self,event): + addr_indices = self.addr_listbox.curselection() + if addr_indices: + self.addr_indices = set(addr_indices) + details = "" + for index in addr_indices: + selected_ticket = self.addrs[index] + details += f"名字: {selected_ticket['name']}\n" \ + f"电话: {selected_ticket['phone']}\n" \ + f"地址: {selected_ticket['prov'] + selected_ticket['city'] + selected_ticket['area'] + selected_ticket['addr']}\n\n" + + self.addr_text.delete(1.0, tk.END) + self.addr_text.insert(tk.END, details) + def submit_booking(self): if len(self.selected_indices) == self.max_selections: persons = [self.persons[index] for index in self.selected_indices] + addr=[self.addrs[index] for index in self.addr_indices] self.onSubmitPersons(persons) + self.onSubmitAddr(addr) self.master.destroy() self.master.quit() # Exit the mainloop else: @@ -63,7 +97,9 @@ def submit_booking(self): _request = BiliRequest(cookies_config_path=cookies_config_path) res = _request.get(url="https://show.bilibili.com/api/ticket/buyer/list?is_default&projectId=74924") print(res.text) + addr_res = _request.get(url="https://show.bilibili.com/api/ticket/addr/list") + print(addr_res.text) root = tk.Tk() - app = SelectProfileTable(root, res.json(), max_selections=3) + app = SelectProfileTable(root, res.json(), addr_res.json(), max_selections=3,onSubmitPersons=lambda x: print(x)) root.mainloop() diff --git a/menu/TicketOptions.py b/menu/TicketOptions.py index c977379..7c54716 100644 --- a/menu/TicketOptions.py +++ b/menu/TicketOptions.py @@ -30,25 +30,32 @@ def onSubmitTicket(buy_info): url=f"https://show.bilibili.com/api/ticket/order/prepare?project_id={projectId}", data=token_payload) logging.info(f"res.text: {res.text}") token = "" - # if "token" in res.json()["data"]: - # token = res.json()["data"]["token"] + if "token" in res.json()["data"]: + token = res.json()["data"]["token"] order_info = _request.get( url=f"https://show.bilibili.com/api/ticket/order/confirmInfo?token={token}&voucher=&project_id={projectId}") contact_info = order_info.json()["data"].get("contact_info", {}) - + logging.info(f"contact_info: {contact_info}") ts = int(time.time()) * 1000 buyer_info = [] + delivery_info = {} res = _request.get(url=f"https://show.bilibili.com/api/ticket/buyer/list?is_default&projectId={projectId}") print(res.text) + addr_res = _request.get(url="https://show.bilibili.com/api/ticket/addr/list") + print(addr_res.text) root = tk.Toplevel() def update_buyer_info(x): nonlocal buyer_info buyer_info = x - selectProfileTable = SelectProfileTable(root, res.json(), max_selections=buy_info["count"], - onSubmitPersons=update_buyer_info) + def update_addr_info(x): + nonlocal delivery_info + delivery_info = x[0] + + selectProfileTable = SelectProfileTable(root, res.json(), addr_res.json(), max_selections=buy_info["count"], + onSubmitPersons=update_buyer_info, onSubmitAddr=update_addr_info) root.mainloop() # "isBuyerInfoVerified": true, # "isBuyerValid": true @@ -67,8 +74,11 @@ def update_buyer_info(x): "pay_money": order_info.json()["data"].get("pay_money", ""), "timestamp": ts, "buyer_info": buyer_info, - "buyer": contact_info.get("username", ""), - "tel": contact_info.get("tel", "") + "buyer": buyer_info[0]["name"], + "tel": buyer_info[0]["tel"], + "deliver_info": {"name": delivery_info["name"], "tel": delivery_info["phone"], "addr_id": delivery_info["id"], + "addr": delivery_info["prov"] + delivery_info["city"] + delivery_info["area"] + delivery_info[ + "addr"]} } logging.info(order_config) diff --git a/util/JsonUtil.py b/util/JsonUtil.py index 5f2ce3b..161a51f 100644 --- a/util/JsonUtil.py +++ b/util/JsonUtil.py @@ -21,3 +21,10 @@ def __init__(self, data): def get_persons(self): return self.personList + +class AddrInfo: + def __init__(self, data): + self.addrList = data["data"]["addr_list"] + + def get_addrs(self): + return self.addrList \ No newline at end of file