master
elf 4 months ago
parent e85948b2a5
commit 10753da02c

@ -15,6 +15,7 @@ use Admin\Event\QiNiuEvent;
use Think\Model; use Think\Model;
use Think\Upload; use Think\Upload;
use Base\Service\OssService; use Base\Service\OssService;
use Base\Tool\Storage;
/** /**
* 图片模型 * 图片模型
@ -70,15 +71,14 @@ class PictureModel extends Model{
$this->where(['id'=>$value['id']])->save($data); $this->where(['id'=>$value['id']])->save($data);
} }
} }
if (C('OSS_STATUS')) { if (C('STORAGE_TYPE')) {
$path = explode('/', $value['path']); $path = explode('/', $value['path']);
$saveFileName = 'icon/' . $path[4]; $saveFileName = 'icon/' . $path[4];
$localFilePath = '.' . $value['path']; $localFilePath = '.' . $value['path'];
$ossService = new OssService(); $result = Storage::upload($localFilePath, $saveFileName);
$result = $ossService->upload($localFilePath, $saveFileName);
if ($result['status']) { if ($result['status']) {
$dataUrl['oss_url'] = $ossService->getUrl($saveFileName); $dataUrl['oss_url'] = $result['data']['url'];
$coo = $this->where(['id' => $value['id']])->save($dataUrl); $this->where(['id' => $value['id']])->save($dataUrl);
} else { } else {
$this->error = $result['message']; $this->error = $result['message'];
return false; return false;

@ -11,6 +11,7 @@ namespace Home\Model;
use Think\Model; use Think\Model;
use Think\Upload; use Think\Upload;
use Base\Service\OssService; use Base\Service\OssService;
use Base\Tool\Storage;
/** /**
* 图片模型 * 图片模型
@ -56,15 +57,14 @@ class PictureModel extends Model{
unset($info[$key]); unset($info[$key]);
} }
} }
if (C('OSS_STATUS')) { if (C('STORAGE_TYPE')) {
$path = explode('/', $value['path']); $path = explode('/', $value['path']);
$saveFileName = 'icon/' . $path[4]; $saveFileName = 'icon/' . $path[4];
$localFilePath = '.' . $value['path']; $localFilePath = '.' . $value['path'];
$ossService = new OssService(); $result = Storage::upload($localFilePath, $saveFileName);
$ossService->upload($localFilePath, $saveFileName);
if ($result['status']) { if ($result['status']) {
$dataUrl['oss_url'] = $ossService->getUrl($saveFileName); $dataUrl['oss_url'] = $result['data']['url'];
$coo = $this->where(['id' => $value['id']])->save($dataUrl); $this->where(['id' => $value['id']])->save($dataUrl);
} else { } else {
$this->error = $result['message']; $this->error = $result['message'];
return false; return false;

Loading…
Cancel
Save