在项目中会员签到的模块必不可少的在,这里把自己整理过的一份代码个大家分享下。
先上效果图
会员签到是必须做的,我个人对这个没啥好的头绪,这里参考的 素材火 的会员签到。
首先看下控制器的代码://会员签到<br>
public function sign(){<br>
$first = strtotime(date("Y-m-01 00:00:00"));<br>
$first = date("w", $first);<br>
$maxDay = date('t', strtotime("" . date("Y") . "-" . date("m") . ""));<br>
for ($j = 0; $j
$blankArr[] = $j;<br>
}<br>
for ($i = 0; $i
$z = $first + $i;<br>
$days[] = array("key" => $i, "key2" => $z % 7);<br>
}<br>
$this->assign("days", $days);<br>
$this->assign("first", $first);<br>
$this->assign("blankArr", $blankArr);<br>
$total = $first + count($days);<br>
for ($x = 0; $x
$other[] = $x;<br>
}<br>
$this->assign("other", $other);<br>
$this->display();
首先是获取这个月的第一天的时间戳,然后记录有这是周几,这个是$first的作用,比如这里是10月份,然后处理之后打印出来的$first得值就是4;
然后我们根据这个周几知道有几天的时间是空白的,上面记录的是4,所以前面有4的空白,周日、周一、周二、周三;
然后我们遍历这个月一共多少天,这里用到的 data("t",xx) 这个函数,他的作用是返回这个月的最大天数。28/29/30/31 中的一个;
在循环的时候for是用0开始的,这里把原有得周的值加上然后模上7来取得周几的时间。
然后我们把数据分配到前端,这里需要考虑的是天数可能大于或者少于,那么我们这里就需要和开始一样补空了。ceil($maxDay/7)的值为5,所以这个月的星期为5周,然后*7之后为35,假设这个月是5周,那么最大是35天,和$total相减之后为0,则最后的空为0;
然后是视图代码:<br>
<br>
<title>会员签到</title>
<br>
<link>
<br>
<br>
<br>
<div>
<br>
<div>
<br>
<table>
<br>
<thead>
<br>
<tr>
<br>
<th>周日</th>
<br>
<th>周一</th>
<br>
<th>周二</th>
<br>
<th>周三</th>
<br>
<th>周四</th>
<br>
<th>周五</th>
<br>
<th>周六</th>
<br>
</tr>
<br>
</thead>
<br>
<tbody>
<br>
<notempty><br>
<tr>
<br>
<foreach><br>
<td>-</td>
<br>
<if></if></foreach>
</tr>
<br>
<br>
</notempty><br>
<foreach><br>
<if><tr>
<br>
{$row['key']|getSign=###}<br>
<if></if>
</tr></if><br>
</foreach><br>
<foreach><br>
<td>-</td>
<br>
</foreach><br>
</tbody>
<br>
</table>
<br>
</div>
<br>
</div>
<br>
<script></script><br>
<script><br />
function signDay(obj) {<br />
$.post("/User/Index/signDay", {}, function(data) {<br />
if(data == -1){<br />
alert("请登录!");return false;<br />
}<br />
var num = obj.find("span").text();<br />
var td = "<td style='background-color:navajowhite;navajowhite ;'>\n\<br />
<div align='right' valign='top'><span style='position:relative;right:20px;'>" + num + "\n\<br />
<div align='left'><img src="/static/imghwm/default1.png" data-src="/Public/Images/extension/common.gif" class="lazy" width='35px' height='35px' src='/Public/Images/cart_3.gif' alt='已签到' style='position:relative;left:10px;'>\n\<br />
已签到";<br />
obj.before(td);<br />
obj.remove();<br />
if (data > 0) {<br />
alert("签到成功获取 " + data + " 积分");<br />
} else {<br />
alert("今天您已签到!");<br />
}<br />
})<br />
}<br />
</script><br>
<br>
这里需要依赖的是两个文件,一个是CSS,一个是JQ。这里的话CSS我就不拿出来了,需要的可以去素材火注册然后另存为他的签到的CSS样式,JQ的是1.11.0.min.js,这个自行下载
其中的技巧就是满足7的时候才给这个用的比较经典,就我个人来说,我是写不出来,至少现在的能力是写不出来的。
然后其中调用一个函数,这个函数的代码是(Common/function.php):function getSign($row) {<br>
$t = $row + 1;<br>
if ($t > date('d')) {<br>
$td = "<td>
<br>
<div>
<span>" . $t . "</span><br>
</div>
<div> </div>
<div> </div>
</td>";<br>
} else {<br>
if (strlen($t) == 1) {<br>
$day = "0" . $t;<br>
} else {<br>
$day = $t;<br>
}<br>
$t2 = strtotime(date("Y-m-" . $day . ""));<br>
$info = M("sign")->field("id")->where("addtime = " . $t2 . " AND status = 0 AND uid = " . session('uid') . "")->find();<br>
if ($info) {<br>
$td = "<td>
<br>
<div>
<span>" . $t . "</span><br>
</div>
<div>
<br>
<img src="/static/imghwm/default1.png" data-src="/Public/Images/extension/common.gif" class="lazy" alt="分享一个会员签到" > 已签到<br>
</div>
</td>";<br>
} else {<br>
if ($t == date('d')) {<br>
$td = "<td>
<br>
<div><span>" . $t . "</span></div>
<br>
<div><a>签到</a></div>
</td>";<br>
} else {<br>
$td = "<td>
<br>
<div>
<span>" . $t . "</span><br>
</div>
<div>
<br>
</div>
</td>";<br>
}<br>
}<br>
}<br>
return $td;<br>
}
这里就是根据周几的值显示不同的样式;
还有数据库的代码:
CREATE TABLE IF NOT EXISTS `sign` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL,
`money` decimal(10,1) NOT NULL,
`addtime` int(10) NOT NULL,
`status` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
需要注意的是用户登陆之后,我的是UID来识别的,所以在function的时候需要自行调整。
好了,会员签到就写到这里了。
sign.rar
( 11.06 KB 下载:153 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
