🐛 将获取用户基本信息的地方全部转交给Player类
This commit is contained in:
+12
-16
@@ -175,29 +175,25 @@ class CUserDB(CSqlManager):
|
||||
|
||||
return level, totalExpNextLevel, currentExp
|
||||
|
||||
async def getUserSoilByUid(self, uid: str) -> int:
|
||||
"""获取用户解锁土地数量
|
||||
async def updateStealCountByUid(
|
||||
self, uid: str, stealTime: str, stealCount: int
|
||||
) -> bool:
|
||||
"""根据用户Uid更新剩余偷菜次数
|
||||
|
||||
Args:
|
||||
uid (str): 用户Uid
|
||||
stealTime (str): 偷菜日期
|
||||
stealCount (int): 新剩余偷菜次数
|
||||
|
||||
Returns:
|
||||
int: 解锁土地数量,失败返回-1
|
||||
bool: 是否更新成功
|
||||
"""
|
||||
if not uid:
|
||||
return -1
|
||||
if not uid or stealCount < 0:
|
||||
return False
|
||||
|
||||
records = await self.select("user", where={"uid": uid}, columns=["soil"])
|
||||
|
||||
if not records:
|
||||
return -1
|
||||
|
||||
try:
|
||||
soil = int(records[0].get("soil", 3))
|
||||
except Exception:
|
||||
soil = 3
|
||||
|
||||
return soil
|
||||
return await self.update(
|
||||
"user", {"stealTime": stealTime, "stealCount": stealCount}, {"uid": uid}
|
||||
)
|
||||
|
||||
async def updateFieldByUid(self, uid: str, field: str, value) -> bool:
|
||||
"""更新单字段信息
|
||||
|
||||
@@ -124,6 +124,10 @@ class CUserSignDB(CSqlManager):
|
||||
bool: 0: 签到失败 1: 签到成功 2: 重复签到
|
||||
"""
|
||||
try:
|
||||
player = await g_pToolManager.getPlayerByUid(uid)
|
||||
if not player:
|
||||
return 0
|
||||
|
||||
if not signDate:
|
||||
signDate = g_pToolManager.dateTime().date().today().strftime("%Y-%m-%d")
|
||||
|
||||
@@ -233,17 +237,11 @@ class CUserSignDB(CSqlManager):
|
||||
exp += 9999
|
||||
|
||||
# 向数据库更新
|
||||
currentExp = await g_pDBService.user.getUserExpByUid(uid)
|
||||
await g_pDBService.user.updateUserExpByUid(uid, currentExp + exp)
|
||||
|
||||
currentPoint = await g_pDBService.user.getUserPointByUid(uid)
|
||||
await g_pDBService.user.updateUserPointByUid(uid, currentPoint + point)
|
||||
await player.addExp(exp)
|
||||
await player.addPoint("point", point)
|
||||
|
||||
if vipPoint > 0:
|
||||
currentVipPoint = await g_pDBService.user.getUserVipPointByUid(uid)
|
||||
await g_pDBService.user.updateUserVipPointByUid(
|
||||
uid, currentVipPoint + vipPoint
|
||||
)
|
||||
await player.addPoint("vipPoint", vipPoint)
|
||||
|
||||
return 1
|
||||
except Exception as e:
|
||||
|
||||
@@ -2,9 +2,9 @@ import math
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
from ...utils.config import g_bIsDebug
|
||||
from ...utils.tool import g_pToolManager
|
||||
from ..dbService import g_pDBService
|
||||
from ..utils.config import g_bIsDebug
|
||||
from ..utils.tool import g_pToolManager
|
||||
from .database import CSqlManager
|
||||
|
||||
|
||||
@@ -117,56 +117,6 @@ class CUserSoilDB(CSqlManager):
|
||||
columns = [description[0] for description in cursor.description]
|
||||
return dict(zip(columns, row))
|
||||
|
||||
@classmethod
|
||||
async def migrateOldFarmData(cls) -> bool:
|
||||
"""迁移旧土地数据到新表 userSoil 并删除旧表
|
||||
|
||||
Returns:
|
||||
bool: 如果旧表不存在则返回 False,否则迁移并删除后返回 True
|
||||
"""
|
||||
# 检查旧表是否存在
|
||||
cursor = await cls.m_pDB.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='soil'"
|
||||
)
|
||||
if not await cursor.fetchone():
|
||||
return False
|
||||
|
||||
async with cls._transaction():
|
||||
users = await g_pDBService.user.getAllUsers()
|
||||
|
||||
for uid in users:
|
||||
farmInfo = await cls.getUserFarmByUid(uid)
|
||||
for i in range(1, 31):
|
||||
key = f"soil{i}"
|
||||
data = farmInfo.get(key)
|
||||
if not data:
|
||||
continue
|
||||
|
||||
if data == ",,,4,":
|
||||
continue
|
||||
|
||||
parts = data.split(",")
|
||||
if len(parts) < 3:
|
||||
continue
|
||||
|
||||
name = parts[0]
|
||||
pt = int(parts[1])
|
||||
mt = int(parts[2])
|
||||
|
||||
await cls.m_pDB.execute(
|
||||
"""
|
||||
INSERT INTO userSoil
|
||||
(uid,soilIndex,plantName,plantTime,matureTime,harvestCount)
|
||||
VALUES (?,?,?,?,?,?)
|
||||
""",
|
||||
(uid, i, name, pt, mt, 0),
|
||||
)
|
||||
|
||||
await cls.m_pDB.execute("DROP TABLE soil")
|
||||
|
||||
logger.info("数据库迁移完毕!")
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
async def insertUserSoil(cls, soilInfo: dict):
|
||||
"""插入一条新的 userSoil 记录
|
||||
|
||||
Reference in New Issue
Block a user