* @return array|bool|mixed|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getFilePath($id = '', $type = 0) { if (is_array($id)) { $data_list = $this->where('id', 'in', $id)->select(); $paths = []; foreach ($data_list as $key => $value) { if ($value['driver'] == 'local') { $paths[$value['id']] = ($type == 0 ? PUBLIC_PATH : '').$value['path']; } else { $paths[$value['id']] = $value['path']; } } return $paths; } else { $data = $this->where('id', $id)->find(); if ($data) { if ($data['driver'] == 'local') { return ($type == 0 ? PUBLIC_PATH : '').$data['path']; } else { return $data['path']; } } else { return false; } } } /** * 根据图片id获取缩略图路径,如果缩略图不存在,则返回原图路径 * @param string $id 图片id * @author 蔡伟明 <314013107@qq.com> * @return array|mixed|string|Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getThumbPath($id = '') { $result = $this->where('id', $id)->field('path,driver,thumb')->find(); if ($result) { if ($result['driver'] == 'local') { return $result['thumb'] != '' ? PUBLIC_PATH.$result['thumb'] : PUBLIC_PATH.$result['path']; } else { return $result['thumb'] != '' ? $result['thumb'] : $result['path']; } } else { return $result; } } /** * 根据附件id获取名称 * @param string $id 附件id * @return string 名称 */ public function getFileName($id = '') { return $this->where('id', $id)->value('name'); } }