
一、核心机制:生存 / 死亡规则
-
每日签到生存
用户必须每天签到,保持生存状态。
-
漏签自动死亡
超过 1 天未签到 → 系统自动判定死亡
连续签到天数 → 直接清零
-
死亡惩罚机制
漏签 = 死亡
死亡 = 连续天数归零
死亡后可通过补签卡复活
-
连续签到天数
每天连续签到 +1 天
漏签 → 清零
补签复活 → 恢复生存状态
二、用户功能
-
用户登录验证
未登录用户无法进入,强制提示登录
-
今日签到
一键签到
签到后显示:✅ 今日已生存
-
今日心情选择
支持三种心情打卡
- 开心
- 一般
- 失落
心情会保存在打卡记录里
-
补签卡系统
拥有补签卡即可复活
补签后恢复生存
补签消耗 1 张补签卡
-
个人数据统计
- 连续生存天数
- 累计签到天数
- 补签卡数量
- 当前生存 / 死亡状态
-
个人打卡历史记录
显示所有签到日期
显示当日选择的心情
按时间倒序展示
三、邮件通知系统
-
自定义接收邮箱
用户可设置自己的接收邮件
-
邮件开关
可开启 / 关闭邮件通知
-
签到成功邮件提醒
签到后自动发送通知
-
死亡警告邮件
漏签死亡时自动发送警告邮件
内容:你已死亡,连续天数清零
四、排行榜系统
-
全网站生存排行榜
按累计签到天数排名
显示前 30 名用户
-
死亡状态标识
死亡用户会显示红色【死亡】标签
一目了然谁存活、谁死亡
<?php
/*
Template Name: 全新生死存亡签到
*/
if (!defined('ABSPATH')) exit;
// 登录判断
if (!is_user_logged_in()) {
get_header();
echo '<div class="container"><div class="zib-widget text-center p-5"><h3>请登录</h3></div></div>';
get_footer();
exit;
}
$user = wp_get_current_user();
$uid = $user->ID;
$today = date('Y-m-d');
$msg = '';
// 用户数据
$last_sign = get_user_meta($uid, 'last_sign_date', 1);
$sign_total = get_user_meta($uid, 'sign_total', 1) ?: 0;
$sign_streak = get_user_meta($uid, 'sign_streak', 1) ?: 0;
$is_dead = get_user_meta($uid, 'is_dead', 1) ?: 'no';
$card_num = get_user_meta($uid, 'card_num', 1) ?: 0;
$sign_log = get_user_meta($uid, 'sign_log', 1) ?: [];
$user_email = get_user_meta($uid, 'user_email', 1) ?: $user->user_email;
$email_open = get_user_meta($uid, 'email_open', 1) ?: 'off';
// 保存邮箱
if (isset($_POST['save_email'])) {
$e = trim($_POST['user_email']);
$o = $_POST['email_open'];
if (is_email($e)) {
update_user_meta($uid, 'user_email', $e);
update_user_meta($uid, 'email_open', $o);
$msg = '<div class="alert alert-success">保存成功</div>';
}
}
// 签到
if (isset($_POST['sign'])) {
$mood = $_POST['mood'];
if ($last_sign == $today) {
$msg = '<div class="alert alert-warning">今日已签</div>';
} else {
update_user_meta($uid, 'is_dead', 'no');
$yesterday = date('Y-m-d', strtotime('-1 day'));
$streak = $last_sign == $yesterday ? $sign_streak + 1 : 1;
update_user_meta($uid, 'last_sign_date', $today);
update_user_meta($uid, 'sign_total', $sign_total + 1);
update_user_meta($uid, 'sign_streak', $streak);
$log = $sign_log;
$log[] = [$today, $mood];
update_user_meta($uid, 'sign_log', $log);
$msg = '<div class="alert alert-success">签到成功!连续'.$streak.'天</div>';
if ($email_open == 'on') {
$title = "签到成功";
$content = "你已成功签到!连续生存:".$streak."天";
if (function_exists('zib_send_email')) {
zib_send_email($user_email, $title, $content);
}
}
}
}
// 漏签死亡
$yesterday = date('Y-m-d', strtotime('-1 day'));
if ($last_sign < $yesterday && $is_dead != 'yes') {
update_user_meta($uid, 'is_dead', 'yes');
update_user_meta($uid, 'sign_streak', 0);
if ($email_open == 'on') {
$title = "⚠️你已死亡!漏签惩罚";
$content = "你漏签了,连续天数清零";
if (function_exists('zib_send_email')) zib_send_email($user_email, $title, $content);
}
}
// 补签
if (isset($_POST['reSign'])) {
if ($card_num > 0 && $last_sign != $today) {
update_user_meta($uid, 'card_num', $card_num - 1);
update_user_meta($uid, 'last_sign_date', $today);
update_user_meta($uid, 'is_dead', 'no');
$msg = '<div class="alert alert-success">补签复活成功</div>';
} else {
$msg = '<div class="alert alert-danger">补签卡不足</div>';
}
}
// 排行榜
$users = get_users([
'meta_key' => 'sign_total',
'orderby' => 'meta_value_num',
'order' => 'desc',
'number' => 30
]);
get_header();
?>
<div class="container">
<div class="zib-widget text-center mb-20">
<h2>🧟 生死存亡签到系统</h2>
<p>签到生存|漏签死亡</p>
</div>
<?php echo $msg; ?>
<!-- 邮箱设置(可折叠) -->
<div class="zib-widget mb-20">
<div onclick="this.nextElementSibling.classList.toggle('hidden')" style="cursor:pointer;padding:10px;background:#f7f7f7">
📩 邮件通知设置(点击展开/收起)
</div>
<div class="hidden" style="padding:15px">
<form method="post">
<div class="form-item">
<label>接收邮箱</label>
<input type="email" name="user_email" class="form-control" value="<?php echo $user_email; ?>">
</div>
<div class="form-item">
<label>
<input type="radio" name="email_open" value="on" <?php checked($email_open,'on')?>> 开启通知
</label>
<label style="margin-left:10px">
<input type="radio" name="email_open" value="off" <?php checked($email_open,'off')?>> 关闭通知
</label>
</div>
<button class="btn btn-primary btn-sm" name="save_email">保存</button>
</form>
</div>
</div>
<!-- 状态 -->
<div class="zib-widget mb-20">
<h4>❤️ 生存状态</h4>
<p>连续:<?php echo $sign_streak; ?> 天</p>
<p>总签到:<?php echo $sign_total; ?> 天</p>
<p>补签卡:<?php echo $card_num; ?></p>
<p>
<?php if($is_dead=='yes'): ?>
<span style="color:red">⚠️ 你已死亡</span>
<?php elseif($last_sign==$today): ?>
<span style="color:green">✅ 今日已生存</span>
<?php else: ?>
<span style="color:orange">未签到</span>
<?php endif; ?>
</p>
</div>
<!-- 心情 + 签到 -->
<div class="zib-widget mb-20">
<h4>😊 今日心情</h4>
<form method="post">
<label><input type="radio" name="mood" value="开心" checked> 开心</label>
<label style="margin-left:10px"><input type="radio" name="mood" value="一般"> 一般</label>
<label style="margin-left:10px"><input type="radio" name="mood" value="失落"> 失落</label>
<br><br>
<?php if($last_sign != $today): ?>
<button class="btn btn-primary" name="sign" style="width:100%">✅ 立即签到</button>
<?php else: ?>
<button class="btn btn-success" disabled>✅ 今日已签到</button>
<?php endif; ?>
</form>
<br>
<form method="post">
<button class="btn btn-warning" name="reSign" style="width:100%">🃏 使用补签卡复活</button>
</form>
</div>
<!-- 打卡记录 -->
<div class="zib-widget mb-20">
<h4>📜 打卡记录</h4>
<?php if($sign_log): foreach(array_reverse($sign_log) as $l): ?>
<p><?php echo $l[0] ?> • <?php echo $l[1] ?></p>
<?php endforeach; else: ?>
<p>暂无记录</p>
<?php endif; ?>
</div>
<!-- 排行榜 -->
<div class="zib-widget">
<h4>🏆 生存排行榜</h4>
<?php foreach($users as $i=>$u): $total = get_user_meta($u->ID,'sign_total',1) ?: 0; $dead = get_user_meta($u->ID,'is_dead',1); ?>
<p>#<?php echo $i+1 ?> <?php echo $u->display_name ?> | <?php echo $total ?>天
<?php if($dead=='yes'): ?> <span style="color:red">死亡</span> <?php endif; ?>
</p>
<?php endforeach; ?>
</div>
</div>
<?php get_footer(); ?>
免责声明:本站资源均来自网络,仅用于学习研究,版权归原作者所有,请支持正版!
如有侵权请邮件 xmkucc@foxmail.com 联系删除,感谢理解!






















暂无评论内容