123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?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 [
- 'original' => $value,
- 'html' => "<div class='rich_text'>{$value}</div>"
- ];
- } elseif ($data['message_type'] == 1) {
- $value = cdnurl($value, true);
- return [
- 'original' => $value,
- 'html' => "<img src='{$value}' class='img_message' alt='' />"
- ];
- } elseif ($data['message_type'] == 2) {
- // 文件地址可能是完整的url,可能是cdn的url
- // 此处只能计算本地文件的大小
- $domain = cdnurl('', true);
- if (strpos($value, $domain) !== false) {
- $value = str_replace($domain, '', $value);
- }
- $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);
- }
- $fileSize = $fileSize ? General::formatFileSize($fileSize) : __('Unknown size');
- $value = cdnurl($value, true);
- $imgIconUrl = url('index/workorder/icon', ['suffix' => $fileExt], true, true);
- $fileName = __('%s file', [$fileExt]);
- $textHtml = <<<HTML
- <a target='_blank' href='{$value}'>
- <div class='file_message'>
- <img src='{$imgIconUrl}' alt=''>
- <div>
- <p class='file_name'>{$fileName}</p>
- <p class='file_size'>{$fileSize}</p>
- </div>
- <div class='down_file'>
- <i class='fa fa-download'></i>
- </div>
- </div>
- </a>
- HTML;
- return [
- 'original' => [
- 'url' => $value,
- 'ext' => $fileExt,
- 'size' => $fileSize
- ],
- 'html' => $textHtml
- ];
- } elseif ($data['message_type'] == 4) {
- return [
- 'original' => $data['id'],
- 'html' => "<div id='confidential_{$data['id']}'><span class='confidential text-gray'>" . __('Confidential information is hidden') . "</span><button data-confidential_id='{$data['id']}' class='btn btn-danger btn-xs confidential_btn'>" . __('check') . "</button></div>"
- ];
- }
- }
- }
|