-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e285b8c
commit b8376f7
Showing
6 changed files
with
246 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: penghcheng | ||
* Date: 2019/11/7 0007 | ||
* Time: 10:06 | ||
*/ | ||
|
||
namespace App\Controller\Admin; | ||
|
||
|
||
use App\Controller\AbstractController; | ||
use App\Service\Instance\JwtInstance; | ||
use App\Service\SysUserService; | ||
use Hyperf\Di\Annotation\Inject; | ||
|
||
class SysLogController extends AbstractController | ||
{ | ||
/** | ||
* @Inject() | ||
* @var SysUserService | ||
*/ | ||
protected $sysUserService; | ||
|
||
|
||
/** | ||
* 操作日志管理list | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function sysLogList() | ||
{ | ||
$currentLoginUserId = JwtInstance::instance()->build()->getId(); | ||
|
||
$key = (string)$this->request->input('key'); | ||
$page = (int)$this->request->input('page'); | ||
$limit = (int)$this->request->input('limit'); | ||
|
||
$result = $this->sysUserService->getSysLogList($key, $limit, $page); | ||
|
||
return $this->response->success([ | ||
'page' => $result | ||
]); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://doc.hyperf.io | ||
* @contact group@hyperf.io | ||
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE | ||
*/ | ||
|
||
namespace App\Model\Dao; | ||
|
||
use App\Constants\ErrorCode; | ||
use App\Exception\BusinessException; | ||
use App\Model\SysLog; | ||
use Hyperf\DbConnection\Db; | ||
|
||
class SysLogDao | ||
{ | ||
public function first($id, $throw = true) | ||
{ | ||
$model = SysLog::query()->where('id', $id)->first(); | ||
if (empty($model) && $throw) { | ||
throw new BusinessException(ErrorCode::USER_NOT_EXIST); | ||
} | ||
return $model; | ||
} | ||
|
||
/** | ||
* 根据条件获取totalCount | ||
* @param string $key | ||
* @return int | ||
*/ | ||
public function getTotalCount(string $key): int | ||
{ | ||
$where = ['like', "'%" . $key . "%'"]; | ||
|
||
$count = SysLog::query()->where('username', $where)->orWhere("operation", $where)->count(); | ||
|
||
return $count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
namespace App\Model; | ||
|
||
use Hyperf\DbConnection\Model\Model; | ||
/** | ||
* @property int $id | ||
* @property string $username | ||
* @property string $operation | ||
* @property string $method | ||
* @property string $params | ||
* @property int $time | ||
* @property string $ip | ||
* @property string $create_date | ||
*/ | ||
class SysLog extends Model | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'sys_log'; | ||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = []; | ||
/** | ||
* The attributes that should be cast to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = ['id' => 'int', 'time' => 'integer']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Administrator | ||
* Date: 2019/11/7 0007 | ||
* Time: 10:32 | ||
*/ | ||
|
||
namespace App\Service\Formatter; | ||
|
||
|
||
use App\Model\SysLog; | ||
|
||
class SysLogFormatter extends Formatter | ||
{ | ||
public function base(SysLog $model) | ||
{ | ||
return [ | ||
'id' => $model->id, | ||
'ip' => $model->ip, | ||
'method' => $model->method, | ||
'username' => $model->username ?? null, | ||
'operation' => $model->operation, | ||
'time' => $model->time, | ||
'createDate' => $model->create_date | ||
]; | ||
} | ||
|
||
public function forArray($model) | ||
{ | ||
return [ | ||
'id' => $model['id'], | ||
'ip' => $model['ip'], | ||
'method' => $model['method'], | ||
'username' => $model['username'] ?? null, | ||
'operation' => $model['operation'], | ||
'time' => $model['time'], | ||
'createDate' => $model['create_date'] | ||
]; | ||
} | ||
|
||
public function arrayFormat($models) | ||
{ | ||
$result = []; | ||
foreach ($models as $model) { | ||
$item = self::forArray($model); | ||
$result[] = $item; | ||
} | ||
return $result; | ||
} | ||
|
||
public function collectionFormat($models) | ||
{ | ||
$result = []; | ||
foreach ($models as $model) { | ||
$item = self::base($model); | ||
$result[] = $item; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters