第一步:進(jìn)入數(shù)據(jù)庫,給會(huì)員添加字段:
last_score_time
第二步:在文件:
/apps/home/model/MemberModel.php
找到:
// 會(huì)員登錄
public function login($where)
{
$field = array(
'a.id',
'a.ucode',
'a.username',
'a.useremail',
'a.usermobile',
'a.gid',
'a.status',
'b.gcode',
'b.gname',
'a.last_score_time',// 加上這一行,這樣才能正確取出用戶上次加分的時(shí)間。
);找到原來的登陸添加積分的代碼
// 登錄積分
// $score = Config::get('login_score') ?: 0;
// if (is_numeric($score) && $score > 0) {
// $data['score'] = '+=' . $score;
// }修改成:
// 登錄積分(每天最多加一次)
$score = Config::get('login_score') ?: 0;
if (is_numeric($score) && $score > 0) {
$lastScoreTime = $user->last_score_time;
$today = date('Y-m-d');
if (substr($lastScoreTime, 0, 10) != $today) {
$data['score'] = '+=' . $score;
$data['last_score_time'] = get_datetime(); // 更新積分記錄時(shí)間
}
}這樣每天登陸就會(huì)只增加一次積分了。
增加字段 last_score_time
判斷這個(gè)字段的日期是否為“今天”
如果不是今天再加積分