✨ 完成对数据库的翻新

This commit is contained in:
2025-04-27 17:00:58 +08:00
parent 72baa5d095
commit b5334dfc01
16 changed files with 358 additions and 92 deletions
+10 -10
View File
@@ -51,7 +51,7 @@ class CFarmManager:
return f"充值{point}农场币成功,手续费{tax}金币,当前农场币:{number}"
@classmethod
async def drawFarmByUid(cls, uid: str, name: str) -> bytes:
async def drawFarmByUid(cls, uid: str) -> bytes:
"""绘制用户农场
Args:
@@ -72,7 +72,9 @@ class CFarmManager:
await grass.resize(0, soilSize[0], soilSize[1])
soilPos = g_pJsonManager.m_pSoil['soil']
soilUnlock = await g_pSqlManager.getUserSoilByUid(uid)
userInfo = await g_pSqlManager.getUserInfoByUid(uid)
soilUnlock = int(userInfo['soil'])
x = 0
y = 0
@@ -128,7 +130,7 @@ class CFarmManager:
await img.paste(frame, (75, 44))
#用户名
nameImg = await BuildImage.build_text_image(name, size = 24, font_color = (77, 35, 4))
nameImg = await BuildImage.build_text_image(userInfo['name'], size = 24, font_color = (77, 35, 4))
await img.paste(nameImg, (300, 92))
#经验值
@@ -148,12 +150,10 @@ class CFarmManager:
await img.paste(levelImg, (660, 187))
#金币
point = await g_pSqlManager.getUserPointByUid(uid)
pointImg = await BuildImage.build_text_image(str(point), size = 24, font_color = (253, 253, 253))
pointImg = await BuildImage.build_text_image(str(userInfo['point']), size = 24, font_color = (253, 253, 253))
await img.paste(pointImg, (330, 255))
#点券
bonds = await g_pSqlManager.getUserPointByUid(uid)
#点券 TODO
bondsImg = await BuildImage.build_text_image("0", size = 24, font_color = (253, 253, 253))
await img.paste(bondsImg, (570, 255))
@@ -473,14 +473,14 @@ class CFarmManager:
if plant is None:
result = await ImageTemplate.table_page(
"作物仓库",
"播种示例:@小真寻 出售作物 大白菜 [数量]",
"出售示例:@小真寻 出售作物 大白菜 [数量]",
column_name,
data_list,
)
return result.pic2bytes()
sell = ""
for name, count in plant.items(): # 使用 .items() 来遍历字典
for name, count in plant.items():
plantInfo = g_pJsonManager.m_pPlant['plant'][name]
icon = ""
icon_path = g_sResourcePath / f"plant/{name}/icon.png"
@@ -507,7 +507,7 @@ class CFarmManager:
result = await ImageTemplate.table_page(
"作物仓库",
"播种示例:@小真寻 出售作物 大白菜 [数量]",
"出售示例:@小真寻 出售作物 大白菜 [数量]",
column_name,
data_list,
)
+27 -27
View File
@@ -23,7 +23,7 @@ class CShopManager:
column_name = [
"-",
"种子名称",
"种子单价"
"种子单价",
"解锁等级",
"果实单价",
"收获经验",
@@ -132,39 +132,39 @@ class CShopManager:
Returns:
str:
"""
plantDict = await g_pSqlManager.getUserPlantByUid(uid)
if not plantDict:
if not isinstance(name, str) or name.strip() == "":
name = ""
plant = await g_pSqlManager.getUserPlantByUid(uid)
if not plant:
return "你仓库没有可以出售的作物"
totalPoint = 0
point = 0
totalSold = 0
isAll = (num == -1)
if not name:
for plantName, count in plantDict.items():
if name == "":
for plantName, count in plant.items():
plantInfo = g_pJsonManager.m_pPlant['plant'][plantName]
totalPoint += plantInfo['price'] * count
await g_pSqlManager.deleteUserPlantByName(uid, plantName)
point += plantInfo['price'] * count
await g_pSqlManager.updateUserPlantByName(uid, plantName, 0)
else:
currentCount = plantDict.get(name)
if currentCount is None:
return f"出售作物{name}出错:你没有这种作物"
if name not in plant:
return f"出售作物{name}出错:仓库中不存在该作物"
available = plant[name]
sellAmount = available if isAll else min(available, num)
if sellAmount <= 0:
return f"出售作物{name}出错:数量不足"
await g_pSqlManager.updateUserPlantByName(uid, name, available - sellAmount)
totalSold = sellAmount
if num == -1:
sellCount = currentCount
else:
if num > currentCount:
return f"出售作物{name}出错:数量不足"
sellCount = num
totalPoint = point if name == "" else totalSold * g_pJsonManager.m_pPlant['plant'][name]['price']
currentPoint = await g_pSqlManager.getUserPointByUid(uid)
await g_pSqlManager.updateUserPointByUid(uid, currentPoint + totalPoint)
plantInfo = g_pJsonManager.m_pPlant['plant'][name]
totalPoint = plantInfo['price'] * sellCount
await g_pSqlManager.addUserPlantByUid(uid, name, -sellCount)
point = await g_pSqlManager.getUserPointByUid(uid)
await g_pSqlManager.updateUserPointByUid(uid, point + totalPoint)
if not name:
return f"成功出售所有作物,获得农场币:{totalPoint},当前农场币:{point + totalPoint}"
if name == "":
return f"成功出售所有作物,获得农场币:{totalPoint},当前农场币:{currentPoint + totalPoint}"
else:
return f"成功出售{name},获得农场币:{totalPoint},当前农场币:{point + totalPoint}"
return f"成功出售{name},获得农场币:{totalPoint},当前农场币:{currentPoint + totalPoint}"
g_pShopManager = CShopManager()