UserLogin.php 747 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace App\Models;
  3. class UserLogin extends BaseModel
  4. {
  5. protected $table = 'user_login';
  6. protected $fillable = ['user_id', 'login_ip'];
  7. protected $hidden = [];
  8. // 获取用户未登录天数(最后第二次未登录的天数)
  9. public static function getNotLoginDays($memberId)
  10. {
  11. $list = self::where('user_id', $memberId)->orderByDesc('id')->limit(2)->get()->toArray();
  12. if (count($list) < 2) {
  13. return 0;
  14. }
  15. if (date('Y-m-d', strtotime($list[0]['created_at'])) != date('Y-m-d')) {
  16. return 0;
  17. }
  18. $diff = strtotime($list[0]['created_at']) - strtotime($list[1]['created_at']);
  19. $days = ceil($diff / 86400);
  20. return abs($days);
  21. }
  22. }