From 9da91ff3d4ceaea049edd9d4d9a3ff3f4c1ec4b8 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Thu, 16 Oct 2025 01:02:33 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=AE=9E=E7=8E=B0=E7=82=B9?= =?UTF-8?q?=E5=88=B8=E5=95=86=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 8 +-- farm/shop.py | 139 ++++++++++++--------------------------------------- 2 files changed, 36 insertions(+), 111 deletions(-) diff --git a/command.py b/command.py index 5549c72..d5d6b1b 100644 --- a/command.py +++ b/command.py @@ -201,9 +201,9 @@ async def _(session: Uninfo, res: Match[tuple[str, ...]]): page = int(raw[1]) if filterKey is None: - image = await g_pShopManager.getSeedShopImage(page) + image = await g_pShopManager.getSeedShopImage(page, 0, 0) else: - image = await g_pShopManager.getSeedShopImage(filterKey, page) + image = await g_pShopManager.getSeedShopImage(filterKey, page, 0) await MessageUtils.build_message(image).send() @@ -755,8 +755,8 @@ async def _(session: Uninfo, res: Match[tuple[str, ...]]): page = int(raw[1]) if filterKey is None: - image = await g_pShopManager.getVipSeedShopImage(page) + image = await g_pShopManager.getSeedShopImage(page, 0, 1) else: - image = await g_pShopManager.getVipSeedShopImage(filterKey, page) + image = await g_pShopManager.getSeedShopImage(filterKey, page, 1) await MessageUtils.build_message(image).send() diff --git a/farm/shop.py b/farm/shop.py index d73bb38..de0ceb7 100644 --- a/farm/shop.py +++ b/farm/shop.py @@ -8,7 +8,9 @@ from ..dbService import g_pDBService class CShopManager: @classmethod - async def getSeedShopImage(cls, filterKey: str | int = 1, num: int = 1) -> bytes: + async def getSeedShopImage( + cls, filterKey: str | int = 1, num: int = 1, isVip: int = 0 + ) -> bytes: """获取商店页面 Args: @@ -45,17 +47,33 @@ class CShopManager: # 查询所有可购买作物,并根据筛选关键字过滤 plants = await g_pDBService.plant.listPlants() filteredPlants = [] - for plant in plants: - # 只留下农场币购买的种子 - if plant["isVip"] == 1: - continue - # 跳过未解锁购买的种子 - if plant["isBuy"] == 0: - continue - # 字符串筛选 - if filterStr and filterStr not in plant["name"]: - continue - filteredPlants.append(plant) + + # 如果是点券商店 + if isVip: + columnName[2] = "点券" + for plant in plants: + # 只留下点券购买的种子 + if plant["isVip"] == 0: + continue + # 跳过未解锁购买的种子 + if plant["isBuy"] == 0: + continue + # 字符串筛选 + if filterStr and filterStr not in plant["name"]: + continue + filteredPlants.append(plant) + else: + for plant in plants: + # 只留下农场币购买的种子 + if plant["isVip"] == 1: + continue + # 跳过未解锁购买的种子 + if plant["isBuy"] == 0: + continue + # 字符串筛选 + if filterStr and filterStr not in plant["name"]: + continue + filteredPlants.append(plant) # 计算分页 totalCount = len(filteredPlants) @@ -89,6 +107,8 @@ class CShopManager: sell, # 是否可上架交易行 ] ) + if isVip: + dataList[-1][2] = plant["vipBuy"] # 点券种子单价 # 页码标题 title = f"种子商店 页数: {page}/{pageCount}" @@ -228,100 +248,5 @@ class CShopManager: name=name, point=totalPoint, num=currentPoint + totalPoint ) - @classmethod - async def getVipSeedShopImage(cls, filterKey: str | int = 1, num: int = 1) -> bytes: - """获取点券商店页面 - - Args: - filterKey (str|int): - - 字符串: 根据关键字筛选种子名称 - - 整数: 翻至对应页(无筛选) - num (int, optional): 当 filterKey 为字符串时,用于指定页码。Defaults to 1. - - Returns: - bytes: 返回商店图片bytes - """ - # 解析参数:区分筛选关键字和页码 - filterStr = None - if isinstance(filterKey, int): - page = filterKey - else: - filterStr = filterKey - page = num - - # 表头定义 - columnName = [ - "-", - "种子名称", - "点券", - "解锁等级", - "果实单价", - "收获经验", - "收获数量", - "成熟时间(小时)", - "收获次数", - "是否可以上架交易行", - ] - - # 查询所有可购买作物,并根据筛选关键字过滤 - plants = await g_pDBService.plant.listPlants() - filteredPlants = [] - for plant in plants: - # 只留下点券购买的种子 - if plant["isVip"] == 0: - continue - # 跳过未解锁购买的种子 - if plant["isBuy"] == 0: - continue - # 字符串筛选 - if filterStr and filterStr not in plant["name"]: - continue - filteredPlants.append(plant) - - # 计算分页 - totalCount = len(filteredPlants) - pageCount = math.ceil(totalCount / 15) if totalCount else 1 - startIndex = (page - 1) * 15 - pageItems = filteredPlants[startIndex : startIndex + 15] - - # 构建数据行 - dataList = [] - for plant in pageItems: - # 图标处理 - icon = "" - iconPath = g_sResourcePath / f"plant/{plant['name']}/icon.png" - if iconPath.exists(): - icon = (iconPath, 33, 33) - - # 交易行标记 - sell = "可以" if plant["sell"] else "不可以" - - dataList.append( - [ - icon, - plant["name"], # 种子名称 - plant["vipBuy"], # 点券种子单价 - plant["level"], # 解锁等级 - plant["price"], # 果实单价 - plant["experience"], # 收获经验 - plant["harvest"], # 收获数量 - plant["time"], # 成熟时间(小时) - plant["crop"], # 收获次数 - sell, # 是否可上架交易行 - ] - ) - - # 页码标题 - title = f"种子商店 页数: {page}/{pageCount}" - - # 渲染表格并返回图片bytes - result = await ImageTemplate.table_page( - title, - "购买示例:@小真寻 购买种子 澳洲青苹果 5", - columnName, - dataList, - ) - return result.pic2bytes() - g_pShopManager = CShopManager()