基於tp5 模型的乙個簽到功能;由於儲存所有的簽到日期資料庫會非常龐大,所以簽到日期只儲存近三個月的。
具體功能:
1、記錄最近一次的簽到時間
2、每次簽到都會新增15積分
3、有連續簽到的記錄
create table `sp_sign` (
`id` int(11) not null auto_increment comment '主鍵',
`times` datetime default null comment '最近一次簽到時間',
`userid` int(11) default null comment '使用者id',
`days` tinyint(6) not null default '0' comment '連續簽到的天數',
`number` decimal(10,0) not null default '0' comment '當月簽到給的積分',
`one` varchar(255) default null comment '當月簽到的日期,用「,」隔開',
`two` varchar(255) default null comment '上個月簽到的日期,用「,」隔開',
`three` varchar(255) default null comment '上上個月簽到的日期,用「,」隔開',
primary key (`id`)
) engine=innodb auto_increment=4 default charset=utf8;
/**
* 使用者簽到
* @param array $userid 使用者id
*/public function add($userid)
else
else //今日未簽到
else //上次簽到時間小於24小時,連續簽到次數加1
//更新上次簽到時間和簽到積分
$query1 = db::name('sign')->where('userid',$userid)->update(['times'=>date('y-m-d h:i:s')]);
$query2 = db::name('sign')->where('userid',$userid)->setinc('number', 15);
$sqldate = date('m',$time); //上次簽到日期的月份
$nowdate = date('m',time()); //當前月份
//記錄本次簽到日期
if($sqldate != $nowdate) //上次簽到日期與本次簽到日期月份不一樣
elseif($oldtime < $twotime && $oldtime >= $threetime) //月份間隔 大於2個月,小於3個月
elseif($oldtime < $threetime) //月份間隔 大於3個月
$query3 = db::name('sign')->where('userid',$userid)->update(['one'=>$one,'two'=>$two,'three'=>$three]);
}else //上次簽到日期與本次簽到日期月份一樣
return 1;}}
}
TP5 驗證碼功能實現
參考資料 第一步 安裝驗證碼外掛程式 composer require topthink think captcha 檢查是否存在think captcha包 vendor topthink think captcha第二步 前端設定 簡單的就直接新增 即可 class pass label 驗證碼...
TP5 軟刪除功能
參考 tp5 完全開發手冊 軟刪除 在實際專案中,對資料頻繁使用刪除操作會導致效能問題,軟刪除的作用就是把資料加上刪除標記,而不是真正的刪除,同時也便於需要的時候進行資料的恢復。使用軟刪除功能,需要在物件模型中引入use traits model softdelete 並定義軟刪除標記字段prote...
tp5實現資料介面
注 以下內容均已預設配置好資料庫連線且所有表都在同一資料庫中 資料介面 model層 資料介面檔案 namespace use think db class inface 根據表名分頁查詢100條資料 public function getonehundreddata page table 根據表名...