diff --git a/game-server/app/services/timeTaskService.ts b/game-server/app/services/timeTaskService.ts index b625b654d..f51583f38 100644 --- a/game-server/app/services/timeTaskService.ts +++ b/game-server/app/services/timeTaskService.ts @@ -294,19 +294,8 @@ export async function reportOneOnline(roleId: string, userCode: string, sid: str user = await UserModel.updatePlayTime(userCode, guestTimeInc, result.total); // 记录时间 guestTime = user.guestTime; - } - if(result.code != ADDICTION_PREVENTION_CODE.SUCCESS && result.age != -1) { // 未成年人防沉迷 - pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, { - isGuest, - guestTime, // 游客已体验时间 - hasAuthenticated, // 是否进行过实名认证 - isAdult, // 是否已成年 - todayPlayTime: result.total, // 今天已游戏时长 - type: result.code - } ), [{uid: roleId, sid: sid}]); - } else { - if ((isGuest || !hasAuthenticated) && guestTime > GUEST_MAX_TIME) { + if ( guestTime > GUEST_MAX_TIME ) { pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, { isGuest, guestTime, // 游客已体验时间 @@ -316,5 +305,18 @@ export async function reportOneOnline(roleId: string, userCode: string, sid: str type: ADDICTION_PREVENTION_CODE.GUEST, } ), [{uid: roleId, sid: sid}]); } + } else { + if(result.code != ADDICTION_PREVENTION_CODE.SUCCESS && result.age != -1) { // 未成年人防沉迷 + user = await UserModel.updatePlayTime(userCode, 0, result.total, result.code); // 记录时间 + + pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, { + isGuest, + guestTime, // 游客已体验时间 + hasAuthenticated, // 是否进行过实名认证 + isAdult, // 是否已成年 + todayPlayTime: result.total, // 今天已游戏时长 + type: result.code + } ), [{uid: roleId, sid: sid}]); + } } } \ No newline at end of file diff --git a/shared/db/User.ts b/shared/db/User.ts index 89945beb1..2fbd7b198 100644 --- a/shared/db/User.ts +++ b/shared/db/User.ts @@ -57,6 +57,8 @@ export default class User extends BaseModel { pi: string; // 已通过实名认证用户唯一标识 @prop({ required: false, default: 0 }) todayPlayTime: number; // 今日游戏时间 + @prop({ required: false, default: 0 }) + todayPlayType: number; // 未成年防沉迷类型 @prop({ required: false }) reportTime: Date; // 汇报时间 @@ -215,8 +217,10 @@ export default class User extends BaseModel { } - public static async updatePlayTime(userCode: string, guestTimeInc: number, todayPlayTime: number, lean = true) { - const user: UserType = await UserModel.findOneAndUpdate({ userCode }, { $inc: { guestTime: guestTimeInc }, $set: { todayPlayTime, reportTime: new Date() }}, { new: true }).lean(lean); + public static async updatePlayTime(userCode: string, guestTimeInc: number, todayPlayTime: number, todayPlayType?: number) { + let update = { todayPlayTime, todayPlayType, reportTime: new Date() }; + if(todayPlayType) update.todayPlayType; + const user: UserType = await UserModel.findOneAndUpdate({ userCode }, { $inc: { guestTime: guestTimeInc }, $set: update}, { new: true }).lean(); return user; } } diff --git a/web-server/app/service/Auth.ts b/web-server/app/service/Auth.ts index 2b2eaac5e..61637c47f 100644 --- a/web-server/app/service/Auth.ts +++ b/web-server/app/service/Auth.ts @@ -4,7 +4,7 @@ import { DEFAULT_HEROES } from '@consts'; import { HeroModel } from '@db/Hero'; import { RoleModel } from '@db/Role'; import { UserModel, UserType } from '@db/User'; -import { STATUS, GET_SMS_TYPE } from '@consts'; +import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts'; import { smsModel } from '@db/Sms'; import { Service } from 'egg'; import Counter from '@db/Counter'; @@ -95,9 +95,15 @@ export default class Auth extends Service { let age = getAge(user.birthday); let isAdult = age >= ADULT_AGE; let todayPlayTime = user.todayPlayTime; + let type = user.todayPlayType; if(shouldRefresh(user.reportTime, new Date(), 0)) { todayPlayTime = 0; + type = 0; } + if((user.isGuest || !user.hasAuthenticated) && user.guestTime > GUEST_MAX_TIME) { + type = ADDICTION_PREVENTION_CODE.GUEST; + } + return { tel: user.tel, isGuest: !!user.isGuest, @@ -105,7 +111,7 @@ export default class Auth extends Service { hasAuthenticated: !!user.hasAuthenticated, // 是否进行过实名认证 isAdult, // 是否已成年 todayPlayTime, // 今天已游戏时长 - + type, // 防沉迷类型 hasSetPw: user.hasSetPw, // 是否设置了密码 token: user.token, // 用户token userCode: user.userCode // 用户标识 diff --git a/web-server/config/config.local.ts b/web-server/config/config.local.ts index 62fa1e623..261f18707 100644 --- a/web-server/config/config.local.ts +++ b/web-server/config/config.local.ts @@ -40,7 +40,7 @@ export default (appInfo: EggAppInfo) => { }, }; - config.decodeParm = false; + config.decodeParm = true; config.static = { prefix: '/',