From 1961bc6ecd0cea2e1d36b0854ae42981f30365f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?computer=5C=E5=B0=BC=E5=8D=A1?= <203267346@qq.com> Date: Fri, 8 Aug 2025 18:24:15 +0800 Subject: [PATCH] 111 --- assets/Script/JiaZai.ts | 36 +------------------------- assets/Script/module/Tool/GameTool.ts | 37 ++++++++++++++++++++++++++- assets/Script/monthlyCard.ts | 17 ++++++------ 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index f209d99..c310041 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -263,7 +263,7 @@ export default class JiaZai extends cc.Component { // this.openHeath(); this.uploadToCloud(cc.fx.GameConfig.GM_INFO.level + 1); console.log("________________1"); - this.getMonthlyCardValidityDays(); + // this.getMonthlyCardValidityDays(); this.rewarded(); //判断过期 @@ -1005,41 +1005,7 @@ export default class JiaZai extends cc.Component { }) } - //获取月卡有效期距离今天的天数 - getMonthlyCardValidityDays(): Promise<{ days: number, time: number }> { - console.log("________________2"); - return new Promise((resolve, reject) => { - Utils.getMonthlyCard((data) => { - console.log("月卡返回时间:", data); - if (data) { - if (data.code === 1) { - const validityTime = data.data.monthCardTime; // 后端返回的到期时间戳(毫秒) - const today = new Date(); - today.setHours(0, 0, 0, 0); - const todayMidnight = today.getTime(); - const expiryDate = new Date(validityTime); - expiryDate.setHours(0, 0, 0, 0); - const expiryMidnight = expiryDate.getTime(); - const diffMs = expiryMidnight - todayMidnight; - const days = Math.floor(diffMs / 86400000); - const remainingDays = Math.max(0, days); - cc.fx.GameConfig.GM_INFO.monthTime = remainingDays; - let obj = { - days: remainingDays, - time: validityTime, - } - resolve(obj); - } else { - // resolve(0); // 或 reject(data) 根据需要 - } - } - else { - // resolve(0); // 或 reject(data) 根据需要 - } - }); - }); - } //获取有没有分享信息 getShareInfo() { diff --git a/assets/Script/module/Tool/GameTool.ts b/assets/Script/module/Tool/GameTool.ts index efc7796..c85f8ff 100644 --- a/assets/Script/module/Tool/GameTool.ts +++ b/assets/Script/module/Tool/GameTool.ts @@ -1460,8 +1460,43 @@ var GameTool = { } } - } + }, + //获取月卡有效期距离今天的天数 + getMonthlyCardValidityDays(): Promise<{ days: number, time: number }> { + console.log("________________2"); + return new Promise((resolve, reject) => { + Utils.getMonthlyCard((data) => { + console.log("月卡返回时间:", data); + if (data) { + if (data.code === 1) { + const validityTime = data.data.monthCardTime; // 后端返回的到期时间戳(毫秒) + const today = new Date(); + today.setHours(0, 0, 0, 0); + const todayMidnight = today.getTime(); + const expiryDate = new Date(validityTime); + expiryDate.setHours(0, 0, 0, 0); + const expiryMidnight = expiryDate.getTime(); + const diffMs = expiryMidnight - todayMidnight; + const days = Math.floor(diffMs / 86400000); + const remainingDays = Math.max(0, days); + cc.fx.GameConfig.GM_INFO.monthTime = remainingDays; + let obj = { + days: remainingDays, + time: validityTime, + } + resolve(obj); + + } else { + // resolve(0); // 或 reject(data) 根据需要 + } + } + else { + // resolve(0); // 或 reject(data) 根据需要 + } + }); + }); + } //判断本地缓存关卡等级是否大于服务器存储 //返回true本地缓存大于服务器存储,false本地缓存小于等于服务器存储 diff --git a/assets/Script/monthlyCard.ts b/assets/Script/monthlyCard.ts index 4c76dea..b499b43 100644 --- a/assets/Script/monthlyCard.ts +++ b/assets/Script/monthlyCard.ts @@ -186,20 +186,19 @@ export default class NewClass extends cc.Component { cc.fx.GameConfig.GM_INFO.hp_Max = 7; cc.fx.GameConfig.GM_INFO.hp = 7; this.home = 1; + cc.fx.GameTool.getMonthlyCardValidityDays().then(days => { + cc.fx.GameConfig.GM_INFO.monthTime = days.days; + //本地储存当前服务器时间 + let dateStr = new Date(days.time); + cc.fx.StorageMessage.setStorage("mCardDate", dateStr); + NumberToImage.numberToImageNodes(days.days, 35, 20, "month_", this.monthCardTime, true); + + }); // cc.fx.GameTool.changeCoin(6000); const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 const jiazaiComp = jiazaiNode.getComponent(JiaZai); - if (jiazaiComp) { console.log("获取到JiaZai组件", jiazaiComp); - jiazaiComp.getMonthlyCardValidityDays().then(days => { - cc.fx.GameConfig.GM_INFO.monthTime = days.days; - //本地储存当前服务器时间 - let dateStr = new Date(days.time); - cc.fx.StorageMessage.setStorage("mCardDate", dateStr); - NumberToImage.numberToImageNodes(days.days, 35, 20, "month_", this.monthCardTime, true); - - }); setTimeout(() => { jiazaiComp.setHealthInfo(false); jiazaiComp.startTimeCutDown();