问题说明:平台、门店、供应商网络图片上传不显示
修改文件:app/services/system/attachment/SystemAttachmentServices.php
修改方法:onlineUpload()
/**
* 网络图片上传
* @param $data
* @return bool
* @throws \Exception
*/
public function onlineUpload(array $data, int $type = 0, int $relation_id = 0)
{
//生成附件目录
if (make_path('attach', 3, true) === '') {
throw new AdminException('无法创建文件夹,请检查您的上传目录权限');
}
//上传图片
/** @var SystemAttachmentServices $systemAttachmentService */
$systemAttachmentService = app()->make(SystemAttachmentServices::class);
$siteUrl = sys_config('site_url');
foreach ($data['images'] as $image) {
try {
$uploadValue = app()->make(DownloadImageService::class)->thumb(true)->downloadOnlineImage($image);
} catch (\Throwable $e) {
throw new AdminException('文件下载失败,请更换链接');
}
if (is_array($uploadValue)) {
//TODO 拼接图片地址
if ($uploadValue['image_type'] == 1) {
$imagePath = $siteUrl . $uploadValue['path'];
} else {
$imagePath = $uploadValue['path'];
}
//写入数据库
if (!$uploadValue['is_exists']) {
$systemAttachmentService->save([
'type' => $type,
'relation_id' => $relation_id,
'name' => $uploadValue['name'],
'real_name' => $uploadValue['name'],
'att_dir' => $imagePath,
'satt_dir' => $imagePath,
'att_size' => $uploadValue['size'],
'att_type' => $uploadValue['mime'],
'image_type' => $uploadValue['image_type'],
'module_type' => 1,
'time' => time(),
'pid' => $data['pid']
]);
}
}
}
return true;
}