Records.php
3.1 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
<?php
namespace addons\workorder\model;
use addons\workorder\library\General;
use think\Model;
/**
* 工单沟通记录模型
*/
class Records extends Model
{
protected $name = "workorder_records";
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = null;
// 追加属性
protected $append = [
'sender',
'createtime_text',
];
protected static function init()
{
}
public function getSenderAttr($value, $data)
{
if (isset($data['user_id']) && $data['user_id']) {
return 'user';
} elseif (isset($data['engineer_id']) && $data['engineer_id']) {
return 'engineer';
} else {
return 'none';
}
}
public function getCreatetimeTextAttr($value, $data)
{
return human_date($data['createtime']);
}
public function engineer()
{
return $this->hasOne('Engineer', 'id', 'engineer_id', [], 'LEFT')->setEagerlyType(0);
}
public static function getMessageAttr($value, $data)
{
if ($data['message_type'] == 0 || $data['message_type'] == 3) {
return "<div class='rich_text'>{$value}</div>";
} elseif ($data['message_type'] == 1) {
$value = cdnurl($value);
return "<img src='{$value}' class='img_message' alt='' />";
} elseif ($data['message_type'] == 2) {
$filePath = str_replace('/', DS, ROOT_PATH . 'public' . $value);
if (!file_exists($filePath)) {
$fileExt = General::getFileExtension($value);
$fileSize = false;
} else {
$fileObj = new \think\File($filePath);
$fileExt = $fileObj->getExtension();
$fileSize = $fileObj->getSize();
unset($fileObj);
}
$imgArr = ['jpg', 'png', 'bmp', 'jpeg', 'gif'];
$value = cdnurl($value);
if (in_array($fileExt, $imgArr)) {
return "<img src='{$value}' class='img_message' alt='' />";
} else {
if ($fileSize) {
$fileSize = round($fileSize / 1024, 2) . 'MB';
} else {
$fileSize = '未知大小';
}
$imgIconUrl = url('index/workorder/icon', ['suffix' => $fileExt], true);
$textHtml = <<<HTML
<a target='_blank' href='{$value}'>
<div class='file_message'>
<img src='{$imgIconUrl}' alt=''>
<div>
<p class='file_name'>{$fileExt}文件</p>
<p class='file_size'>{$fileSize}</p>
</div>
<div class='down_file'>
<i class='fa fa-download'></i>
</div>
</div>
</a>
HTML;
return $textHtml;
}
} elseif ($data['message_type'] == 4) {
return "<div id='confidential_{$data['id']}'><span class='confidential text-gray'>机密信息已隐藏</span><button data-confidential_id='{$data['id']}' class='btn btn-danger btn-xs confidential_btn'>查看</button></div>";
}
}
}