Admin.php 744 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Session;
  5. class Admin extends Model
  6. {
  7. // 开启自动写入时间戳字段
  8. protected $autoWriteTimestamp = 'int';
  9. // 定义时间戳字段名
  10. protected $createTime = 'createtime';
  11. protected $updateTime = 'updatetime';
  12. protected $hidden = [
  13. 'password',
  14. 'salt'
  15. ];
  16. public static function init()
  17. {
  18. self::beforeWrite(function ($row) {
  19. $changed = $row->getChangedData();
  20. //如果修改了用户或或密码则需要重新登录
  21. if (isset($changed['username']) || isset($changed['password']) || isset($changed['salt'])) {
  22. $row->token = '';
  23. }
  24. });
  25. }
  26. }