🐛 修复签到无法正确获取作物的BUG
This commit is contained in:
+67
-1
@@ -10,6 +10,7 @@ class CUserPlantDB(CSqlManager):
|
||||
"uid": "TEXT NOT NULL", # 用户Uid
|
||||
"plant": "TEXT NOT NULL", # 作物名称
|
||||
"count": "INTEGER NOT NULL DEFAULT 0", # 数量
|
||||
"isLock": "INTEGER NOT NULL DEFAULT 0", # 是否上锁 0=没有,非0=有
|
||||
"PRIMARY KEY": "(uid, plant)",
|
||||
}
|
||||
|
||||
@@ -91,6 +92,27 @@ class CUserPlantDB(CSqlManager):
|
||||
logger.warning("getUserPlantByName 查询失败!", e=e)
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
async def checkUserPlantByName(cls, uid: str, plant: str) -> bool:
|
||||
"""根据作物名称判断用户作物仓库是否存在该作物
|
||||
|
||||
Args:
|
||||
uid (str): 用户uid
|
||||
plant (str): 作物名称
|
||||
|
||||
Returns:
|
||||
bool: 是否存在
|
||||
"""
|
||||
try:
|
||||
async with cls.m_pDB.execute(
|
||||
"SELECT * FROM userPlant WHERE uid = ? AND plant = ?", (uid, plant)
|
||||
) as cursor:
|
||||
row = await cursor.fetchone()
|
||||
return True if row else False
|
||||
except Exception as e:
|
||||
logger.warning("checkUserPlantByName 查询失败!", e=e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def updateUserPlantByName(cls, uid: str, plant: str, count: int) -> bool:
|
||||
"""更新 userPlant 表中某个作物的数量
|
||||
@@ -114,7 +136,51 @@ class CUserPlantDB(CSqlManager):
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning("updateUserPlantByName失败!", e=e)
|
||||
logger.warning("updateUserPlantByName 失败!", e=e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def lockUserPlantByName(cls, uid: str, plant: str, lock: int) -> bool:
|
||||
"""给作物加锁,防止一键售卖
|
||||
|
||||
Args:
|
||||
uid (str): 用户uid
|
||||
plant (str): 作物名称
|
||||
lock (int): 0为解锁,非0均为加锁
|
||||
|
||||
Returns:
|
||||
bool: 是否加锁成功
|
||||
"""
|
||||
try:
|
||||
async with cls._transaction():
|
||||
await cls.m_pDB.execute(
|
||||
"UPDATE userPlant SET isLock = ? WHERE uid = ? AND plant = ?",
|
||||
(lock, uid, plant),
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning("lockUserPlantByName 失败!", e=e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def checkPlantLockByName(cls, uid: str, plant: str) -> bool:
|
||||
"""根据作物名称判断是否加锁
|
||||
|
||||
Args:
|
||||
uid (str): 用户uid
|
||||
plant (str): 作物名称
|
||||
|
||||
Returns:
|
||||
bool: 是否加锁
|
||||
"""
|
||||
try:
|
||||
async with cls.m_pDB.execute(
|
||||
"SELECT isLock FROM userPlant WHERE uid = ? AND plant = ?", (uid, plant)
|
||||
) as cursor:
|
||||
row = await cursor.fetchone()
|
||||
return row[0] > 0 if row else False
|
||||
except Exception as e:
|
||||
logger.warning("checkUserPlantByName 查询失败!", e=e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -165,7 +165,6 @@ class CUserSignDB(CSqlManager):
|
||||
if row["currentMonth"] == currentMonth
|
||||
else 1
|
||||
)
|
||||
totalSignDays = row["totalSignDays"]
|
||||
lastDate = row["lastSignDate"]
|
||||
prevDate = (
|
||||
g_pToolManager.dateTime().strptime(signDate, "%Y-%m-%d")
|
||||
@@ -200,7 +199,7 @@ class CUserSignDB(CSqlManager):
|
||||
),
|
||||
)
|
||||
else:
|
||||
totalSignDays = 1
|
||||
monthSignDays = 1
|
||||
await cls.m_pDB.execute(
|
||||
"""
|
||||
INSERT INTO userSignSummary
|
||||
@@ -211,7 +210,7 @@ class CUserSignDB(CSqlManager):
|
||||
uid,
|
||||
1,
|
||||
currentMonth,
|
||||
1,
|
||||
monthSignDays,
|
||||
signDate,
|
||||
1,
|
||||
1 if isSupplement else 0,
|
||||
@@ -219,15 +218,13 @@ class CUserSignDB(CSqlManager):
|
||||
)
|
||||
|
||||
# 计算累签奖励
|
||||
reward = g_pJsonManager.m_pSign["continuou"].get(f"{totalSignDays}", None)
|
||||
|
||||
reward = g_pJsonManager.m_pSign["continuou"].get(f"{monthSignDays}", None)
|
||||
if reward:
|
||||
point += reward.get("point", 0)
|
||||
exp += reward.get("exp", 0)
|
||||
vipPoint = reward.get("vipPoint", 0)
|
||||
|
||||
plant = reward.get("plant", {})
|
||||
|
||||
if plant:
|
||||
for key, value in plant.items():
|
||||
await g_pDBService.userSeed.addUserSeedByUid(uid, key, value)
|
||||
|
||||
@@ -24,7 +24,7 @@ class CUserSoilDB(CSqlManager):
|
||||
"weedStatus": "INTEGER DEFAULT 0", # 杂草状态 0=无杂草,1=有杂草
|
||||
"waterStatus": "INTEGER DEFAULT 0", # 缺水状态 0=不缺水,1=缺水
|
||||
"harvestCount": "INTEGER DEFAULT 0", # 收获次数
|
||||
"isSoilPlanted": "INTEGER DEFAULT NULL", # 是否种植作物
|
||||
"isSoilPlanted": "INTEGER DEFAULT NULL", # 是否种植作物 0=没有,1=有
|
||||
"PRIMARY KEY": "(uid, soilIndex)",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user