No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdminUser.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 后台用户管理
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\model;
  15. use think\Model;
  16. class AdminUser extends Model
  17. {
  18. // 自动写入时间戳
  19. protected $autoWriteTimestamp = true;
  20. // 设置当前模型对应的完整数据表名称
  21. protected $name = 'admin';
  22. protected $insert = ['status' => 1];
  23. public function getLastLoginTimeAttr($value)
  24. {
  25. return date('Y-m-d H:i:s', $value);
  26. }
  27. public static function init()
  28. {
  29. self::beforeWrite(function ($row) {
  30. $changed = $row->getChangedData();
  31. //如果修改了用户或或密码则需要重新登录
  32. if (isset($changed['username']) || isset($changed['password']) || isset($changed['salt'])) {
  33. $row->token = '';
  34. }
  35. });
  36. }
  37. }