分享一个会员签到
在项目中会员签到的模块必不可少的在,这里把自己整理过的一份代码个大家分享下。
先上效果图
会员签到是必须做的,我个人对这个没啥好的头绪,这里参考的 素材火 的会员签到。
首先看下控制器的代码://会员签到<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/imghw/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/imghw/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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

PHP variables store values during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above
