网络图片后台上传

This commit is contained in:
evoxwht 2023-06-13 18:22:04 +08:00
parent a04e5c2f9c
commit c48dc8ec7e
4 changed files with 71 additions and 1 deletions

View File

@ -163,4 +163,21 @@ class SystemAttachment extends AuthController
{
return app('json')->success($this->service->scanUploadImage($scan_token));
}
/**
* 网络图片上传
* @return \think\Response
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/06/13
*/
public function onlineUpload()
{
$data = $this->request->postMore([
['pid', 0],
['images', []]
]);
$this->service->onlineUpload($data);
return app('json')->success(100032);
}
}

View File

@ -47,6 +47,8 @@ Route::group('file', function () {
Route::get('scan_upload/qrcode', 'v1.file.SystemAttachment/scanUploadQrcode')->option(['real_name' => '扫码上传页面链接']);
//获取扫码上传的图片数据
Route::get('scan_upload/image/:scan_token', 'v1.file.SystemAttachment/scanUploadImage')->option(['real_name' => '获取扫码上传的图片数据']);
//网络图片上传
Route::post('online_upload', 'v1.file.SystemAttachment/onlineUpload')->option(['real_name' => '网络图片上传']);
})->middleware([
\app\http\middleware\AllowOriginMiddleware::class,
\app\adminapi\middleware\AdminAuthTokenMiddleware::class,

View File

@ -106,6 +106,6 @@ class SystemAttachmentDao extends BaseDao
*/
public function scanUploadImage($scan_token)
{
return $this->getModel()->where('scan_token', $scan_token)->select()->toArray();
return $this->getModel()->where('scan_token', $scan_token)->field('att_dir,att_id')->select()->toArray();
}
}

View File

@ -14,6 +14,7 @@ namespace app\services\system\attachment;
use app\services\BaseServices;
use app\dao\system\attachment\SystemAttachmentDao;
use app\services\product\product\CopyTaobaoServices;
use crmeb\exceptions\AdminException;
use crmeb\exceptions\ApiException;
use crmeb\exceptions\UploadException;
@ -284,4 +285,54 @@ class SystemAttachmentServices extends BaseServices
}
return $res;
}
/**
* 网络图片上传
* @param $data
* @return bool
* @throws \Exception
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/06/13
*/
public function onlineUpload($data)
{
//生成附件目录
if (make_path('attach', 3, true) === '') {
throw new AdminException(400555);
}
//上传图片
/** @var SystemAttachmentServices $systemAttachmentService */
$systemAttachmentService = app()->make(SystemAttachmentServices::class);
$siteUrl = sys_config('site_url');
foreach ($data['images'] as $image) {
$uploadValue = app()->make(CopyTaobaoServices::class)->downloadImage($image);
if (is_array($uploadValue)) {
//TODO 拼接图片地址
if ($uploadValue['image_type'] == 1) {
$imagePath = $siteUrl . $uploadValue['path'];
} else {
$imagePath = $uploadValue['path'];
}
//写入数据库
if (!$uploadValue['is_exists']) {
$systemAttachmentService->save([
'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;
}
}