OperationLog.php
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 模型层:系统-操作日志 模型类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Models\System
* @package App\Models\System
* @author Richer <yangzi1028@163.com>
* @date 2022年8月3日11:23:05
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Models\System;
use App\Models\BaseModel;
use App\Models\Traits\MorphMapTrait;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Arr;
/**
* Class OperationLog
*
* @property mixed user_id
* @property mixed type
* @property mixed type_show
* @property mixed unshelved_opinion
* @property mixed input
* @category App\Models\System
* @package App\Models\System
* @author Richer <yangzi1028@163.com>
* @date 2022年8月3日11:23:05
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class OperationLog extends BaseModel
{
use MorphMapTrait;
// 指定数据库表
const TABLE = 'system_operation_logs';
protected $table = self::TABLE ;
// 指定对象显示名称:方便系统统一查询和做其他处理
const OBJ_NAME = 'system-operation-log';
const OBJ_NAME_ZH = '系统操作日志';
const CREATE = 1; // 创建
const UPDATE = 2; // 更新
const DELETE = 3; // 删除
const SHELVE = 4; // 上架
const UNSHELVE = 5; // 下架
const TYPE_OPTIONS = [
self::CREATE => '创建',
self::UPDATE => '更新',
self::DELETE => '删除',
self::SHELVE => '上架',
self::UNSHELVE => '下架',
];
/**
* 访问器被附加到模型数组的形式。
*
* @var array
*/
protected $appends = ['type_show','unshelved_opinion'];
/**
* 多态关联
*
* @return MorphTo
*/
public function loggable(): MorphTo
{
return $this->morphTo()->withTrashed();
}
/**
* @param $value
*/
public function setInputAttribute($value)
{
$this->attributes['input'] = my_json_encode($value);
}
/**
* @param $value
* @return mixed|null
*/
public function getInputAttribute($value)
{
return json_decode($value, true) ?: null;
}
/**
* @return string
*/
public function getTypeShowAttribute()
{
return Arr::get(self::TYPE_OPTIONS, $this->type ? : self::CREATE);
}
/**
* @return string
*/
public function getUnshelvedOpinionAttribute()
{
return Arr::get($this->input, 'unshelved_opinion');
}
}