//会员签到
public function sign(){
$first = strtotime(date("Y-m-01 00:00:00"));
$first = date("w", $first);
$maxDay = date('t', strtotime("" . date("Y") . "-" . date("m") . ""));
for ($j = 0; $j < $first; $j++) {
$blankArr[] = $j;
}
for ($i = 0; $i < $maxDay; $i++) {
$z = $first + $i;
$days[] = array("key" => $i, "key2" => $z % 7);
}
$this->assign("days", $days);
$this->assign("first", $first);
$this->assign("blankArr", $blankArr);
$total = $first + count($days);
for ($x = 0; $x < ceil($maxDay / 7) * 7 - $total; $x++) {
$other[] = $x;
}
$this->assign("other", $other);
$this->display();
首先是获取这个月的第一天的时间戳,然后记录有这是周几,这个是$first的作用,比如这里是10月份,然后处理之后打印出来的$first得值就是4;<html>
<head>
<title>会员签到</title>
<link href="__PUBLIC__/Css/test.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container clearfix">
<div class="member_main">
<table class='table_sign'>
<thead>
<tr>
<th>周日</th>
<th>周一</th>
<th>周二</th>
<th>周三</th>
<th>周四</th>
<th>周五</th>
<th>周六</th>
</tr>
</thead>
<tbody id="signrili">
<notempty name='blankArr'>
<tr>
<foreach name="blankArr" item="row">
<td>-</td>
<if condition="$row%7 eq $first"></tr></if>
</foreach>
</notempty>
<foreach name="days" item="row">
<if condition="$row['key2'] eq 0"><tr></if>
{$row['key']|getSign=###}
<if condition="$row['key2'] eq 7"></tr></if>
</foreach>
<foreach name="other" item="row">
<td>-</td>
</foreach>
</tbody>
</table>
</div>
</div>
<script src="__PUBLIC__/Js/jquery-1.11.0.js" type="text/javascript"></script>
<script type="text/javascript">
function signDay(obj) {
$.post("/User/Index/signDay", {}, function(data) {
if(data == -1){
alert("请登录!");return false;
}
var num = obj.find("span").text();
var td = "<td style='background-color:navajowhite;navajowhite ;'>\n\
<div align='right' valign='top'><span style='position:relative;right:20px;'>" + num + "</span></div>\n\
<div align='left'><img width='35px' height='35px' src='/Public/Images/cart_3.gif' alt='已签到' style='position:relative;left:10px;'>\n\
已签到</div></td>";
obj.before(td);
obj.remove();
if (data > 0) {
alert("签到成功获取 " + data + " 积分");
} else {
alert("今天您已签到!");
}
})
}
</script>
</body>
</html>
这里需要依赖的是两个文件,一个是CSS,一个是JQ。这里的话CSS我就不拿出来了,需要的可以去素材火注册然后另存为他的签到的CSS样式,JQ的是1.11.0.min.js,这个自行下载function getSign($row) {
$t = $row + 1;
if ($t > date('d')) {
$td = "<td style='background-color:lemonchiffon' valign='top'>
<div align='right' valign='top'><span style='position:relative;right:20px;'>" . $t . "</span>
</div><div align='left'> </div><div align='left'> </div></td>";
} else {
if (strlen($t) == 1) {
$day = "0" . $t;
} else {
$day = $t;
}
$t2 = strtotime(date("Y-m-" . $day . ""));
$info = M("sign")->field("id")->where("addtime = " . $t2 . " AND status = 0 AND uid = " . session('uid') . "")->find();
if ($info) {
$td = "<td style='background-color:navajowhite;navajowhite ;'>
<div align='right' valign='top'><span style='position:relative;right:20px;'>" . $t . "</span>
</div><div align='left'>
<img width='35px' height='35px' src='/Public/Images/cart_3.gif' style='position:relative;left:10px;'> 已签到
</div></td>";
} else {
if ($t == date('d')) {
$td = "<td class='today' onclick='signDay($(this))'>
<div align='right' valign='top'><span style='position:relative;right:20px;'>" . $t . "</span></div>
<div align='center'><a style='cursor:pointer;color:#ffffff;' >签到</a></div></td>";
} else {
$td = "<td style='background-color:#DCDCDC;'>
<div align='right' valign='top'><span style='position:relative;right:20px;'>" . $t . "</span>
</div><div align='left'style='height:47px'>
</div></td>";
}
}
}
return $td;
}
这里就是根据周几的值显示不同的样式;sign.rar ( 11.06 KB 下载:82 次 )