应该可以跑了,还没完全测试
This commit is contained in:
1 parent
7096384161
commit
9dbd544b47
11 files changed
+263
-76
No files matched your search
@@ -44,5 +44,15 @@ impl<T: StorageEngine> CrudHandler<T> {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn get_last_checkin_time(&self, user_id: &str) -> Result<Option<u64>> {
|
||||
let key = user_id.as_bytes();
|
||||
if let Some(value_bytes) = self.engine.get_raw(key).await? {
|
||||
let value: db::user_state::UserState = serde_json::from_slice(&value_bytes)?;
|
||||
Ok(Some(value.checkin_unix_mills))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
//TODO:补全其他方法,比如统计……
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct UserState {
|
||||
pub is_checkin_today: bool,
|
||||
pub level: UserLevel,
|
||||
pub checkin_unix_second: u64,
|
||||
pub checkin_unix_mills: u64,
|
||||
pub checkin_times_in_month: usize,
|
||||
pub checkin_days: Vec<u32>, //每月在哪天签到了
|
||||
}
|
||||
@@ -36,7 +36,7 @@ impl UserState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
is_checkin_today: false,
|
||||
checkin_unix_second: 0,
|
||||
checkin_unix_mills: 0 as u64,
|
||||
checkin_times_in_month: 0,
|
||||
checkin_days: Vec::new(),
|
||||
level: UserLevel::Bronze,
|
||||
@@ -45,9 +45,9 @@ impl UserState {
|
||||
|
||||
pub fn checkin(&mut self) {
|
||||
self.is_checkin_today = true;
|
||||
let unix_time = tokio::time::Instant::now().elapsed().as_secs();
|
||||
let unix_time = tokio::time::Instant::now().elapsed().as_millis() as u64;
|
||||
|
||||
self.checkin_unix_second = unix_time;
|
||||
self.checkin_unix_mills = unix_time;
|
||||
self.checkin_times_in_month += 1;
|
||||
let day = chrono::Utc::now().day();
|
||||
if !self.checkin_days.contains(&day) {
|
||||
|
||||
Reference in new issue
Block a user