AdminLog.php 790 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class AdminLog extends Model
  5. {
  6. // 开启自动写入时间戳字段
  7. protected $autoWriteTimestamp = 'int';
  8. // 定义时间戳字段名
  9. protected $createTime = 'createtime';
  10. protected $updateTime = '';
  11. public static function record($title, $content = '', $username = '')
  12. {
  13. $admin = \think\Session::get('admin');
  14. $admin_id = $admin ? $admin->id : 0;
  15. $username = $username ? $username : ($admin ? $admin->username : __(''));
  16. self::create([
  17. 'title' => $title,
  18. 'content' => $content,
  19. 'url' => request()->url(),
  20. 'admin_id' => $admin_id,
  21. 'username' => $username
  22. ]);
  23. }
  24. }