AdminLog.php 872 B

1234567891011121314151617181920212223242526272829303132
  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. $content = !is_scalar($content) ? json_encode($content) : $content . '';
  16. $username = $username ? $username : ($admin ? $admin->username : __(''));
  17. self::create([
  18. 'title' => $title,
  19. 'content' => $content,
  20. 'url' => request()->url(),
  21. 'admin_id' => $admin_id,
  22. 'username' => $username
  23. ]);
  24. }
  25. }