✨ 新增每天00:30检查签到文件
This commit is contained in:
+7
-2
@@ -8,7 +8,7 @@ import aiosqlite
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
from ..config import g_sPlantPath
|
||||
from ..config import g_bIsDebug, g_sPlantPath
|
||||
|
||||
|
||||
class CPlantManager:
|
||||
@@ -27,7 +27,12 @@ class CPlantManager:
|
||||
async def init(cls) -> bool:
|
||||
try:
|
||||
_ = os.path.exists(g_sPlantPath)
|
||||
cls.m_pDB = await aiosqlite.connect(str(g_sPlantPath))
|
||||
|
||||
if g_bIsDebug:
|
||||
cls.m_pDB = await aiosqlite.connect(str(g_sPlantPath.parent / "plant-test.db"))
|
||||
else:
|
||||
cls.m_pDB = await aiosqlite.connect(str(g_sPlantPath))
|
||||
|
||||
cls.m_pDB.row_factory = aiosqlite.Row
|
||||
return True
|
||||
except Exception as e:
|
||||
|
||||
+48
-1
@@ -3,8 +3,8 @@ from typing import List, Union
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
from .database import CSqlManager
|
||||
from ..tool import g_pToolManager
|
||||
from .database import CSqlManager
|
||||
|
||||
|
||||
class CUserDB(CSqlManager):
|
||||
@@ -16,6 +16,7 @@ class CUserDB(CSqlManager):
|
||||
"name": "TEXT NOT NULL", #农场名称
|
||||
"exp": "INTEGER DEFAULT 0", #经验值
|
||||
"point": "INTEGER DEFAULT 0", #金币
|
||||
"vipPoint": "INTEGER DEFAULT 0", #点券
|
||||
"soil": "INTEGER DEFAULT 3", #解锁土地数量
|
||||
"stealTime": "TEXT DEFAULT NULL", #偷菜时间字符串
|
||||
"stealCount": "INTEGER DEFAULT 0" #剩余偷菜次数
|
||||
@@ -203,6 +204,52 @@ class CUserDB(CSqlManager):
|
||||
logger.error("updateUserPointByUid 事务执行失败!", e=e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def getUserVipPointByUid(cls, uid: str) -> int:
|
||||
"""获取指定用户点券
|
||||
|
||||
Args:
|
||||
uid (str): 用户Uid
|
||||
|
||||
Returns:
|
||||
int: 点券数量,失败返回 -1
|
||||
"""
|
||||
if not uid:
|
||||
return -1
|
||||
try:
|
||||
async with cls.m_pDB.execute(
|
||||
"SELECT vipPoint FROM user WHERE uid = ?", (uid,)
|
||||
) as cursor:
|
||||
row = await cursor.fetchone()
|
||||
return int(row[0]) if row and row[0] is not None else -1
|
||||
except Exception as e:
|
||||
logger.warning("getUservipPointByUid 查询失败!", e=e)
|
||||
return -1
|
||||
|
||||
@classmethod
|
||||
async def updateUserVipPointByUid(cls, uid: str, vipPoint: int) -> bool:
|
||||
"""根据用户Uid更新农场币数量
|
||||
|
||||
Args:
|
||||
uid (str): 用户Uid
|
||||
vipPoint (int): 新农场币数量
|
||||
|
||||
Returns:
|
||||
bool: 是否更新成功
|
||||
"""
|
||||
if not uid or vipPoint < 0:
|
||||
logger.warning("updateUservipPointByUid 参数校验失败!")
|
||||
return False
|
||||
try:
|
||||
async with cls._transaction():
|
||||
await cls.m_pDB.execute(
|
||||
"UPDATE user SET vipPoint = ? WHERE uid = ?", (vipPoint, uid)
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("updateUservipPointByUid 事务执行失败!", e=e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def getUserExpByUid(cls, uid: str) -> int:
|
||||
"""获取指定用户经验值
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import Optional
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils._build_image import BuildImage
|
||||
|
||||
from ..config import g_bIsDebug
|
||||
from ..dbService import g_pDBService
|
||||
from ..json import g_pJsonManager
|
||||
from ..tool import g_pToolManager
|
||||
@@ -145,6 +146,7 @@ class CUserSignDB(CSqlManager):
|
||||
|
||||
exp = random.randint(expMin, expMax)
|
||||
point = random.randint(pointMin, pointMax)
|
||||
vipPoint = 0
|
||||
|
||||
async with cls._transaction():
|
||||
await cls.m_pDB.execute(
|
||||
@@ -193,6 +195,7 @@ class CUserSignDB(CSqlManager):
|
||||
if reward:
|
||||
point += reward.get('point', 0)
|
||||
exp += reward.get('exp', 0)
|
||||
vipPoint = reward.get('vipPoint', 0)
|
||||
|
||||
plant = reward.get('plant', {})
|
||||
|
||||
@@ -200,6 +203,9 @@ class CUserSignDB(CSqlManager):
|
||||
for key, value in plant.items():
|
||||
await g_pDBService.userSeed.addUserSeedByUid(uid, key, value)
|
||||
|
||||
if g_bIsDebug:
|
||||
exp += 9999
|
||||
|
||||
#向数据库更新
|
||||
currentExp = await g_pDBService.user.getUserExpByUid(uid)
|
||||
await g_pDBService.user.updateUserExpByUid(uid, currentExp + exp)
|
||||
@@ -207,6 +213,10 @@ class CUserSignDB(CSqlManager):
|
||||
currentPoint = await g_pDBService.user.getUserPointByUid(uid)
|
||||
await g_pDBService.user.updateUserPointByUid(uid, currentPoint + point)
|
||||
|
||||
if vipPoint > 0:
|
||||
currentVipPoint = await g_pDBService.user.getUserVipPointByUid(uid)
|
||||
await g_pDBService.user.updateUserVipPointByUid(uid, currentVipPoint + vipPoint)
|
||||
|
||||
return 1
|
||||
except Exception as e:
|
||||
logger.warning("执行签到失败", e=e)
|
||||
|
||||
@@ -2,6 +2,7 @@ from typing import Optional
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
from ..config import g_bIsDebug
|
||||
from ..dbService import g_pDBService
|
||||
from ..json import g_pJsonManager
|
||||
from ..tool import g_pToolManager
|
||||
@@ -29,6 +30,46 @@ class CUserSoilDB(CSqlManager):
|
||||
|
||||
await cls.ensureTableSchema("userSoil", userSoil)
|
||||
|
||||
@classmethod
|
||||
async def nextPhase(cls, uid: str, soilIndex: int):
|
||||
"""将指定地块的作物进入下个阶段
|
||||
|
||||
Args:
|
||||
soilIndex (int): 地块索引 从1开始
|
||||
"""
|
||||
if not g_bIsDebug:
|
||||
return
|
||||
|
||||
soilInfo = await cls.getUserSoil(uid, soilIndex)
|
||||
|
||||
if not soilInfo:
|
||||
return
|
||||
|
||||
plantInfo = await g_pDBService.plant.getPlantByName(soilInfo['plantName'])
|
||||
|
||||
if not plantInfo:
|
||||
return
|
||||
|
||||
currentTime = g_pToolManager.dateTime().now()
|
||||
matureTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['matureTime']))
|
||||
|
||||
phase = await g_pDBService.plant.getPlantPhaseNumberByName(soilInfo['plantName'])
|
||||
phaseList = await g_pDBService.plant.getPlantPhaseByName(soilInfo['plantName'])
|
||||
|
||||
if currentTime >= matureTime:
|
||||
return
|
||||
|
||||
plantedTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['plantTime']))
|
||||
|
||||
elapsedTime = currentTime - plantedTime
|
||||
elapsedHour = elapsedTime.total_seconds() / 3600
|
||||
|
||||
currentStage = int(elapsedHour / (plantInfo['time'] / phase))
|
||||
|
||||
t = int(soilInfo['plantTime']) - phaseList[currentStage]
|
||||
|
||||
await cls.updateUserSoil(uid, soilIndex, "plantTime", t)
|
||||
|
||||
@classmethod
|
||||
async def getUserFarmByUid(cls, uid: str) -> dict:
|
||||
"""获取指定用户的旧农场数据
|
||||
|
||||
Reference in New Issue
Block a user