mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 14:40:44 +00:00
107 lines
2.2 KiB
PHP
107 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\traits\Filter;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class Log extends Model
|
|
{
|
|
use Filter;
|
|
|
|
//查询字段
|
|
public $fieldSearchable = [
|
|
'module',
|
|
'action',
|
|
'target_type',
|
|
'target_id',
|
|
'target_field',
|
|
'user_id',
|
|
'created_at',
|
|
];
|
|
|
|
public $fillable = [
|
|
'module',
|
|
'action',
|
|
'target_type',
|
|
'target_id',
|
|
'target_field',
|
|
'before_update',
|
|
'after_update',
|
|
];
|
|
|
|
public function getModuleAttribute($value)
|
|
{
|
|
$map = [
|
|
'goods' => '商品',
|
|
'menu' => '菜单',
|
|
'permission' => '权限',
|
|
'role' => '角色',
|
|
'user' => '用户',
|
|
];
|
|
|
|
return $map[$value];
|
|
}
|
|
|
|
public function getActionAttribute($value)
|
|
{
|
|
$map = [
|
|
'GET' => '查看',
|
|
'POST' => '新增',
|
|
'PATCH' => '更新',
|
|
'DELETE' => '删除',
|
|
];
|
|
|
|
return $map[$value];
|
|
}
|
|
|
|
public function getTargetTypeAttribute($value)
|
|
{
|
|
$map = [
|
|
'goods_sku' => '商品&规格',
|
|
'goods_type' => '商品种类',
|
|
'goods_brand' => '商品品牌',
|
|
'permission' => '权限',
|
|
'role' => '角色',
|
|
'menu' => '菜单',
|
|
'user' => '用户',
|
|
];
|
|
|
|
return $map[$value];
|
|
}
|
|
|
|
public function getTargetFieldAttribute($value)
|
|
{
|
|
$map = [
|
|
'add' => '创建',
|
|
'status' => '状态',
|
|
'name' => '名称',
|
|
'title' => '名称',
|
|
'import' => '导入',
|
|
'export' => '导出',
|
|
'set' => '设置',
|
|
];
|
|
|
|
return $map[$value];
|
|
}
|
|
|
|
public function setUserIdAttribute($value)
|
|
{
|
|
$this->attributes['user_id'] = Auth::id() ?: $value;
|
|
}
|
|
|
|
public function add($targetId = 0, $targetField = '')
|
|
{
|
|
$this->attributes['user_id'] = Auth::id();
|
|
$this->attributes['target_id'] = $targetId;
|
|
$this->attributes['target_field'] = $targetField;
|
|
|
|
return $this->save();
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->hasOne(User::class, 'id', 'user_id');
|
|
}
|
|
}
|