hasMany(CustomFieldValue::class, 'model_id') ->where('table_name', $this->getTable()) ->where('del_time', 0) ->select('id','field_label','field_value','field_type','model_id', 'field_name', 'crt_id', 'is_delivery', 'crt_time'); } /** * 获取格式化后的自定义字段列表 * 用于详情页接口返回给前端 custom_fields 数组 */ public function getFormattedCustomFields() { return $this->customFields->map(function (&$item) { $field_value_show = ""; if($item->field_type == SysOssTasks::type_two) $field_value_show = $this->getCustomFileUrl($item->field_value); $item['field_value_show'] = $field_value_show; return $item; })->values()->toArray(); } /** * 内部方法:处理附件显示地址 */ protected function getCustomFileUrl($path) { if (empty($path)) return ""; $fileUploadService = new FileUploadService(); return $fileUploadService->getFileShow($path); } }