import cloud from '@lafjs/cloud'; const db = cloud.database(); import Utils from "@/Utils"; export default async function (ctx: FunctionContext) { const action = ctx.body.action; const uid = ctx.body.uid; if (!action) { return { code: 0, data: null, msg: "未获取到action" }; } if (!uid) { return { code: 0, data: null, msg: "未获取到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校验失败" }; } } switch (action) { case 'save': let monthCardTime = Date.now() + 2592000000; //console.log("购买月卡到期:"+monthCardTime); if (!monthCardTime) { return { code: 0, data: null, msg: "未获取到monthCardTime" }; } // let res1 = await db.collection("users").where({ _id: uid }).getOne(); // if(res1.data.monthCardTime&&res1.data.monthCardTime>Date.now()){ // return { code: 0, data: { monthCardTime: res1.data.monthCardTime },msg:"月卡还在有效期,不能提前充值"} // } let ret = await db.collection(dbname).where({ _id: uid }).update({ monthCardTime: monthCardTime,monthCardReward:0}); return { code: 1, data: { monthCardTime: monthCardTime, monthCardReward: 0}, msg: "月卡记录成功" } case 'read': let time=res.data?.monthCardTime||0; let monthCardReward=res.data?.monthCardReward||0; if(time