Commit 584382ea by 杨树贤

修复签到的问题

parent 75e8e44f
......@@ -31,9 +31,7 @@ class CheckInController extends Controller
'add_time' => time(),
];
$canCheckIn = $integral->checkIntegralLimit($data['user_id'], Integral::INTEGRAL_TYPE_CHECK_IN);
if (!$canCheckIn) {
return $this->Export(ErrorCode(1, 1), '今天已签到,无法再进行签到');
} else {
if ($canCheckIn) {
$res = $checkIn->addCheckIn($data);
if ($res) {
return $this->Export(0, 'ok');
......@@ -41,5 +39,7 @@ class CheckInController extends Controller
return $this->Export(ErrorCode(18, 5), '新增签到记录失败');
}
}
return $this->Export(0, 'ok');
}
}
\ No newline at end of file
......@@ -53,44 +53,10 @@ class CheckIn extends Model
if (!$result) {
return false;
}
//添加流水成功后,要把签到记录放到redis
$date = Carbon::now()->toDateString();
$hashKey = 'ic_welfare_integral_limit_' . Integral::INTEGRAL_TYPE_CHECK_IN;
$userId = $data['user_id'];
$redis = new RedisModel();
$redis->hincrby($hashKey, $userId, 1);
return true;
});
return $result;
}
//判断是否可以签到
public function canCheckInFromRedis($userId)
{
$redis = new RedisModel();
//先判断 ic_welfare_check_in_日期 在不在,不在的话就添加一个并且给过期时间
$date = Carbon::now()->toDateString();
$hashKey = 'ic_welfare_check_in_' . $date;
$exist = $redis->exists($hashKey);
if (!$exist) {
//设置晚上12点过期
$todayEndTime = Carbon::now()->endOfDay()->timestamp;
$redis->expireAt($hashKey, $todayEndTime);
//因为连最基础的键都没有,就代表肯定没有签到过
return true;
}
//如果没有,就代表用户今天没有签到
$checkInTime = $redis->hget($hashKey, $userId);
if (!$checkInTime) {
//因为他今天没有签到过,所以本次签到是可以执行的
return true;
}
return false;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment