41 lines
1002 B
PHP
41 lines
1002 B
PHP
<?php
|
|
|
|
namespace app\model;
|
|
|
|
use think\model\relation\HasOne;
|
|
|
|
class Log extends Base
|
|
{
|
|
//记录操作日志
|
|
public static function write($controller, $action, $content, $requestType = '')
|
|
{
|
|
$auth = session('auth');
|
|
return self::create([
|
|
'member_id' => $auth['user_id'] ?? 0,
|
|
'name' => $auth['username'] ?? 0,
|
|
'ip' => request()->ip(),
|
|
'create_time' => time(),
|
|
'controller' => $controller,
|
|
'request_type' => $requestType,
|
|
'action' => $action,
|
|
'content' => $content
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return HasOne
|
|
*/
|
|
public function memberName(): HasOne
|
|
{
|
|
return $this->hasOne(Member::class, 'id', 'member_id')->bind(['operator' => 'nickname']);
|
|
}
|
|
|
|
public function getCreateTimeAttr($value)
|
|
{
|
|
if (empty($value)) {
|
|
return $value;
|
|
}
|
|
|
|
return date('Y-m-d H:i:s', $value);
|
|
}
|
|
} |