import cloud from '@lafjs/cloud' const db = cloud.database(); import Utils from "@/Utils"; export default async function (ctx: FunctionContext) { const uid = ctx.body.uid; let dbname = "users"; const gameName = ctx.body.gameName; if (gameName == "iaa") { dbname = "usersAd"; } let res = await db.collection(dbname).where({ _id: uid }).getOne(); const token1 = ctx.body.token; if (res.data && res.data.token) { let istoken = Utils.checkToken(token1, res.data.token); if (!istoken) { return { code: 0, data: null, msg: "token校验失败" }; } } let monthCardTime = Number(res.data.monthCardTime) || 0; if (monthCardTime < Date.now()) { return { code: 0, data: null, msg: "月卡已到期,无法继续领取奖励" }; } const now = new Date(Date.now() + 8 * 3600000); now.setHours(0, 0, 0, 0); // 设置为 0 点 0 分 0 秒 0 毫秒 const timestamp = now.getTime() - 8 * 3600000; let monthCardReward = Number(res.data.monthCardReward) || 0; if (monthCardReward > timestamp) { return { code: 0, data: { monthCardReward: monthCardReward }, msg: "今天已经领取" }; } else { await db.collection(dbname).where({ _id: uid }).update({ monthCardReward: Date.now() }) return { code: 1, data: { monthCardReward: Date.now() }, msg: "可以领取" }; } }