57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* MineAdmin is committed to providing solutions for quickly building web applications
|
|
* Please view the LICENSE file that was distributed with this source code,
|
|
* For the full copyright and license information.
|
|
* Thank you very much for using MineAdmin.
|
|
*
|
|
* @Author X.Mo<root@imoi.cn>
|
|
* @Link https://gitee.com/xmo/MineAdmin
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
namespace Builder\Aspect;
|
|
use Hyperf\Di\Annotation\Aspect;
|
|
use Hyperf\Di\Aop\AbstractAspect;
|
|
use Hyperf\Di\Aop\ProceedingJoinPoint;
|
|
use Hyperf\Di\Exception\Exception;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
use Builder\BaseModel;
|
|
use Builder\BaseRequest;
|
|
|
|
/**
|
|
* Class UpdateAspect
|
|
* @package Builder\Aspect
|
|
*/
|
|
#[Aspect]
|
|
class UpdateAspect extends AbstractAspect
|
|
{
|
|
public array $classes = [
|
|
'Builder\BaseModel::update'
|
|
];
|
|
|
|
/**
|
|
* @param ProceedingJoinPoint $proceedingJoinPoint
|
|
* @return mixed
|
|
* @throws Exception
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function process(ProceedingJoinPoint $proceedingJoinPoint)
|
|
{
|
|
$instance = $proceedingJoinPoint->getInstance();
|
|
// 更新更改人
|
|
if ($instance instanceof BaseModel &&
|
|
in_array('updated_by', $instance->getFillable()) &&
|
|
config('mineadmin.data_scope_enabled') &&
|
|
container()->get(BaseRequest::class)->getHeaderLine('authorization')
|
|
) {
|
|
try {
|
|
$instance->updated_by = user()->getId();
|
|
} catch (\Throwable $e) {}
|
|
}
|
|
return $proceedingJoinPoint->process();
|
|
}
|
|
} |