月卡
This commit is contained in:
parent
3366342098
commit
39a369adfa
|
@ -215,7 +215,6 @@ export default class JiaZai extends cc.Component {
|
||||||
this.monthH();
|
this.monthH();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//打开heath弹窗,创建预制体
|
|
||||||
// 打开heath弹窗,创建预制体并启动自己的倒计时
|
// 打开heath弹窗,创建预制体并启动自己的倒计时
|
||||||
openHeath() {
|
openHeath() {
|
||||||
let health = cc.instantiate(this.health);
|
let health = cc.instantiate(this.health);
|
||||||
|
@ -872,23 +871,37 @@ export default class JiaZai extends cc.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取月卡有效期距离今天的天数
|
//获取月卡有效期距离今天的天数
|
||||||
//获取月卡有效期距离今天的天数
|
getMonthlyCardValidityDays() {
|
||||||
getMonthlyCardValidityDays(callback) {
|
|
||||||
const nowTime = Date.now(); // 毫秒
|
|
||||||
Utils.getMonthlyCard((data) => {
|
Utils.getMonthlyCard((data) => {
|
||||||
if (data.code === 1) {
|
if (data.code === 1) {
|
||||||
const validityTime = data.data.monthCardTime; // 毫秒
|
const validityTime = data.data.monthCardTime; // 后端返回的到期时间戳(毫秒)
|
||||||
const diffMs = validityTime - nowTime;
|
|
||||||
const days = Math.floor(diffMs / 86400000);
|
|
||||||
cc.fx.GameConfig.GM_INFO.monthTime = days;
|
|
||||||
console.log('剩余天数', days);
|
|
||||||
|
|
||||||
callback(days); // 把结果通过回调返回
|
// 获取今天的零点时间戳
|
||||||
|
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); // 86400000 = 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
|
// 确保天数不为负数
|
||||||
|
const remainingDays = Math.max(0, days);
|
||||||
|
|
||||||
|
cc.fx.GameConfig.GM_INFO.monthTime = remainingDays;
|
||||||
|
console.log('月卡剩余天数 (零点刷新):', remainingDays);
|
||||||
} else {
|
} else {
|
||||||
callback(0); // 失败时返回 0
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// update (dt) {}
|
// update (dt) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user