PHP實現簽到功能

2021-08-21 04:09:10 字數 1802 閱讀 1477

php實現簽到功能

1、表設計

1)、主表

create table `sign` (

`id` int(11) not null auto_increment comment '主鍵自增',

`uid` varchar(50) not null default '0' comment '使用者id 唯一',

`username` varchar(50) not null default '' comment '使用者名稱',

`sign_count` int(11) not null default '0' comment '連續簽到次數',

`last_time` int(11) not null default '0' comment '最近一次簽到時間',

`create_time` int(11) not null default '0' comment '建立時間',

primary key (`id`)

) engine=innodb default charset=utf8 comment='簽到主表';

2)、詳情表

create table `sign_detail` (

`id` int(11) not null auto_increment comment '主鍵自增',

`sign_id` int(11) not null default '0' comment '簽到表 wechat_sign表id',

`sign_time` int(11) not null default '0' comment '簽到時間',

primary key (`id`)

) engine=innodb default charset=utf8 comment='簽到詳情表';

2、model.php檔案

1)、主表model [ sign.php ]

<?php

/*** @todo 簽到主表

* @author admin

*/class signmodel extends model

2)、詳情表model [ signdetail.php ]

<?php

/** * @todo 簽到詳情表

* @author admin

*/class signdetailmodel extends model

3、控制器方法  [ test.php ]

<?php

class testcontroller extends rest

$time = time();

$msign = new signmodel();

$msigndetail = new signdetailmodel();

$signinfo = $msign->getone(['uid'=>$uid]);

if($signinfo)else if( $last_time == $yesterday )else

$where = [ 'uid'=>$uid ];

$editdata = ['sign_count'=>$sign_count, 'last_time'=>$time];

$result = $msign->edit($editdata, $where); //編輯詳情表

}else

if($result)else

}else

}}

php實現簽到功能

首先我在資料庫裡建了兩張表,乙個是使用者的積分表,乙個是簽到狀態表,分來用來記錄使用者的積分數和先到狀態 在使用者簽到狀態表中我們有乙個字段,last sign time,即上一次簽到時間,每次可以簽到的時候把這個時間與當前時間進行比較 如果相差為0天,則說明今天已簽到 這個簽到是24小時內只能簽到...

PHP 實現簽到功能

如圖所示 實現上圖功能,建立兩張表 簽到獎品表 簽到記錄表 這個表可以再拆分出乙個表 2 功能 計算兩個時間戳之間相差的日時分秒 3 begin time 開始時間戳 4 end time 結束時間戳5 6public function timediff begin time,end time el...

PHP實現簽到功能

1 表設計 1 主表 create table sign id int 11 not null auto increment comment 主鍵自增 uid varchar 50 not null default 0 comment 使用者id 唯一 sign count int 11 not n...