AuditRecord.php
3.4 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
115
116
117
118
119
120
121
122
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 模型层:系统 审核记录 模型类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Models\System
* @package App\Models\System
* @author Richer <yangzi1028@163.com>
* @date 2020年12月29日16:42:11
* @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\Traits\MorphMapTrait;
use App\Models\User\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Arr;
/**
* Class AuditRecord
*
* @category App\Models\System
* @package App\Models\System
* @author Richer <yangzi1028@163.com>
* @date 2020年12月29日16:42:11
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class AuditRecord extends Model
{
use MorphMapTrait;
// 指定数据库表
const TABLE = 'system_audit_records';
protected $table = self::TABLE ;
// 指定对象显示名称:方便系统统一查询和做其他处理
const OBJ_NAME = 'audit-record';
const OBJ_NAME_ZH = '审核记录';
const SUBMITTED = 1;// 已提交
const AUDIT_PASSED = 2;// 审核通过
const AUDIT_NOT_PASSED = 99;// 审核不通过
const AUDIT_STATUS_OPTIONS = [
self::SUBMITTED => 'submitted',
self::AUDIT_PASSED => 'audit_passed',
self::AUDIT_NOT_PASSED => 'audit_not_passed',
];
const AUDIT_COLOR_STATUS_OPTIONS = [
self::SUBMITTED => 'warning',
self::AUDIT_PASSED => 'success',
self::AUDIT_NOT_PASSED => 'danger',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id', 'user_type', 'auditable_id', 'auditable_type', 'audited_by', 'audited_status','audited_opinion',
'audited_at', 'remark', 'created_at'
];
/**
* 访问器被附加到模型数组的形式。
*
* @var array
*/
protected $appends = ['audited_status_show', 'audited_status_show_color'];
// /**
// * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
// */
// public function user()
// {
// return $this->belongsTo(User::class);
// }
/**
* @return MorphTo
*/
public function user(): MorphTo
{
return $this->morphTo();
}
/**
* @return MorphTo
*/
public function auditable(): MorphTo
{
return $this->morphTo();
}
/**
* 获取状态的中文显示
*
* @return mixed
*/
public function getAuditedStatusShowAttribute()
{
return __(Arr::get(self::AUDIT_STATUS_OPTIONS, $this->audited_status ? : config('constants.AUDIT_PASSED')));
}
/**
* 获取状态的中文显示
*
* @return mixed
*/
public function getAuditedStatusShowColorAttribute()
{
$color = Arr::get(self::AUDIT_COLOR_STATUS_OPTIONS, $this->audited_status);
return '<span class="text text-'.$color.'" style="white-space:nowrap;">'.$this->audited_status_show.'</span>';
}
}