php+mysql+jquery implements calendar check-in

高洛峰
Release: 2023-03-06 09:26:02
Original
2766 people have browsed it


#During the website development process, we often use the check-in function to reward users with points or do some other activities. During the development of this project, I did a calendar check-in. Because I had no experience, I took many detours and recorded the process and steps again.

Recommended related mysql video tutorials: "mysql tutorial"

1. Calendar sign-in style:

php+mysql+jquery implements calendar check-in

2. This check-in only records the number of check-ins this month. If you want to query, you can write other pages to query all check-in records. (The function is available, but it is very troublesome. It has not been implemented in Gu.)

3. Front-end code

  

签到记录

已签到

立即签到

Copy after login

4. Back-end code: Check whether you have checked in today :

$points = M('points_log'); $userid=session('user.id'); $begintime=date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y'))); $endtime=date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1); $where=array( 'points'=>'5', 'user_id'=>$userid, 'createtime' => array(array('gt',$begintime),array('lt',$endtime)), ); $res=$points->where($where)->order("createtime desc")->select(); //var_dump($res['0']['points']); $this->assign('res',$res);
Copy after login

5. Query points:

/*查询积分*/ $jfen=M(cuser); $list=$jfen->where(array('id'=>$userid))->field('points')->find(); $preg = '/[0]*/'; $poin = preg_replace($preg, '', $list, 1); $this->assign('poin',$poin);
Copy after login

6. Sign in and write to the database:

/*签到*/ if(IS_AJAX){ $userid=session('user.id'); $type='签到'; $typename='checkin'; $id_status='up'; $date=Date('Y-m-d H:i:s'); $dataList=array( 'user_id'=>$userid, 'type'=>$type, 'typename'=>$typename, 'id_status'=>$id_status, 'points'=>'5', 'createtime'=>$date, 'remark'=>'奖励5积分' ); $points = M('points_log'); if($points->add($dataList)){ $log=session('user.id'); $user=M('cuser'); $user->where(array('id'=>$log))->setInc('points',5); } $this->ajaxReturn($status); }
Copy after login

7. /*Query the number of check-in days this month and return it in json format*/

public function MonthSign(){ $userid=session('user.id'); $points = M('points_log'); $res=$points->where(array('user_id'=>$userid))->select(); $sign='['; foreach($res as $key=>$value){ $first=explode(' ', $value['createtime']); $second=explode('-', $first['0'])['2']; if($key==0){ $sign .= '{"signDay":"'.$second.'"}'; }else{ $sign .= ',{"signDay":"'.$second.'"}'; } } $sign .=']'; $this->ajaxReturn($sign,'json'); }
Copy after login


php+mysql+jquery implements calendar check-in

##More php +mysql+jquery to implement calendar sign-in related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!