| 12345678910111213141516171819202122232425 |
- <?php
- namespace App\Models;
- class UserLogin extends BaseModel
- {
- protected $table = 'user_login';
- protected $fillable = ['user_id', 'login_ip'];
- protected $hidden = [];
- // 获取用户未登录天数(最后第二次未登录的天数)
- public static function getNotLoginDays($memberId)
- {
- $list = self::where('user_id', $memberId)->orderByDesc('id')->limit(2)->get()->toArray();
- if (count($list) < 2) {
- return 0;
- }
- if (date('Y-m-d', strtotime($list[0]['created_at'])) != date('Y-m-d')) {
- return 0;
- }
- $diff = strtotime($list[0]['created_at']) - strtotime($list[1]['created_at']);
- $days = ceil($diff / 86400);
- return abs($days);
- }
- }
|