RequestLog.php 692 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace app\abutment\model;
  3. use think\Model;
  4. //请求记录日志表
  5. class RequestLog extends Model
  6. {
  7. protected $table = 'wsm_abutment_request_log';
  8. protected $pk = 'id';
  9. protected $autoWriteTimestamp = 'datetime';
  10. // 定义时间戳字段名
  11. protected $createTime = 'addtime';
  12. protected $updateTime = 'updatetime';
  13. public static function add(string $request_id = '', array $param = [])
  14. {
  15. return self::create([
  16. 'request_id' => $request_id,
  17. 'ipaddr' => request()->ip(),
  18. 'action' => request()->pathinfo(),
  19. 'param' => json_encode($param, JSON_UNESCAPED_UNICODE),
  20. ])->save();
  21. }
  22. }