优化上传组件

This commit is contained in:
2020-04-18 09:58:51 +08:00
parent 09c0c3cc59
commit 37a972592d
4 changed files with 36 additions and 18 deletions

View File

@@ -229,25 +229,25 @@ function format_bytes($size, $delimiter = '') {
* @param string $field
* @return 完整的数据 或者 指定的$field字段值
*/
function get_attach($id, $field = null) {
function get_attach($id, $field = false, $is_list = false) {
$basePath = request()->domain();
if (empty($id)) {
return $basePath . '/static/common/images/default.png';
}
if (false !== strpos($id, ",")) {
if (false !== strpos($id, ",") || $is_list) {
$map[] = ['id', 'IN', explode(",", $id)];
$picture = \think\facade\Db::name('Attach')->where($map)->column("*", "id");
$picture = \app\model\Attach::where($map)->column("*", "id");
return $picture;
}else{
$map[] = ['id', '=', $id];
$picture = \think\facade\Db::name('Attach')->where($map)->find();
$picture = \app\model\Attach::where($map)->find();
if ($field == 'path') {
if (!empty($picture['url'])) {
$picture['path'] = $picture['url'] ? $basePath . $picture['url'] : $basePath . '/static/images/default.png';
$picture['path'] = $picture['url'] ? $basePath . $picture['url'] : $basePath . '/static/common/images/default.png';
} else {
$picture['path'] = $picture['path'] ? $basePath . $picture['path'] : $basePath . '/static/images/default.png';
$picture['path'] = $picture['path'] ? $basePath . $picture['path'] : $basePath . '/static/common/images/default.png';
}
}
return empty($field) ? $picture : $picture[$field];
return (false !== $field) ? $picture[$field] : $picture;
}
}