feat : oss
This commit is contained in:
19
app/Constants/Common/OssObjectCode.php
Normal file
19
app/Constants/Common/OssObjectCode.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants\Common;
|
||||
|
||||
class OssObjectCode
|
||||
{
|
||||
/**
|
||||
* 状态 1=有效 2=无效
|
||||
*/
|
||||
const int ENABLE = 1;
|
||||
const int DISABLE = 2;
|
||||
|
||||
/**
|
||||
* 类型 1=图片 2=音频 3=视频
|
||||
*/
|
||||
const int TYPE_IMAGE = 1;
|
||||
const int TYPE_AUDIO = 2;
|
||||
const int TYPE_VIDEO = 3;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class OssDelByOssIdTask
|
||||
$delNum = 0;
|
||||
$ossIds = [];
|
||||
for ($i = 1; $i < 50; $i++) {
|
||||
$one = $this->redis->rPop($key);
|
||||
$one = $this->redis->rPop($key,'system');
|
||||
if (empty($one)){
|
||||
continue;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class OssDelByOssIdTask
|
||||
//删除oss资源
|
||||
//把图片地址丢到删除redis队列
|
||||
foreach ($urlList as $item) {
|
||||
$this->redis->lPush(CommonRedisKey::getDeleteOssImgListByUrl(), $item);
|
||||
$this->redis->lPush(CommonRedisKey::getDeleteOssImgListByUrl(), $item,'system');
|
||||
}
|
||||
|
||||
$this->log->notice(__CLASS__.':success:删除oss文件个数:' . $delNum);
|
||||
|
||||
@@ -62,7 +62,7 @@ class OssDelByUrlTask
|
||||
|
||||
$delNum = 0;
|
||||
for ($i = 1; $i < 50; $i++) {
|
||||
$url = $this->redis->rPop($key);
|
||||
$url = $this->redis->rPop($key,'system');
|
||||
|
||||
if (!empty($url)) {
|
||||
$delNum++;
|
||||
|
||||
@@ -34,8 +34,7 @@ class ErrExceptionHandler extends ExceptionHandler
|
||||
public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
if ($throwable instanceof ErrException) {
|
||||
$url = $this->request->path();
|
||||
$urlArr = explode('/',$url);
|
||||
$urlArr = explode('/',$this->request->path());
|
||||
|
||||
$result = match ($urlArr[0]) {
|
||||
'api' => $this->apiReturn->error($throwable->getMessage(),$throwable->getCode()),
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Common\OssObjectCode;
|
||||
use Hyperf\Collection\Collection;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use function Hyperf\Config\config;
|
||||
@@ -69,7 +70,7 @@ class OssObject extends Model
|
||||
*/
|
||||
public function updateEnabledByIds(array $ids): int
|
||||
{
|
||||
return $this->whereIn('id', $ids)->update(['is_enabled' => 1]);
|
||||
return $this->whereIn('id', $ids)->update(['is_enabled' => OssObjectCode::ENABLE]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +80,7 @@ class OssObject extends Model
|
||||
*/
|
||||
public function updateDisableByIds(array $ids): int
|
||||
{
|
||||
return $this->whereIn('id', $ids)->update(['is_enabled' => 0]);
|
||||
return $this->whereIn('id', $ids)->update(['is_enabled' => OssObjectCode::DISABLE]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +101,7 @@ class OssObject extends Model
|
||||
public function getOssIdListByIsEnabled($time): Collection|false
|
||||
{
|
||||
return $this->where([
|
||||
['is_enabled', '=', 0],
|
||||
['is_enabled', '=', OssObjectCode::DISABLE],
|
||||
['create_time', '<',$time]
|
||||
])->pluck('id') ?? false;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace App\Service\Common;
|
||||
|
||||
use App\Cache\Redis\Common\CommonRedisKey;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\Common\OssObjectCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Lib\AdminReturn;
|
||||
use App\Lib\Log;
|
||||
@@ -265,14 +266,14 @@ class OssCallbackService
|
||||
case 'jpeg':
|
||||
case 'png':
|
||||
case 'bmp':
|
||||
$type = 1;
|
||||
$type = OssObjectCode::TYPE_IMAGE;
|
||||
break;
|
||||
case 'mp3':
|
||||
$type = 2;
|
||||
$type = OssObjectCode::TYPE_AUDIO;
|
||||
break;
|
||||
case 'mp4':
|
||||
case 'swf':
|
||||
$type = 3;
|
||||
$type = OssObjectCode::TYPE_VIDEO;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -285,7 +286,7 @@ class OssCallbackService
|
||||
$ossObjectModel->audio_second = $this->data['audio_second'] ?? 0;
|
||||
$ossObjectModel->video_duration = $this->data['video_duration'] ?? 0;
|
||||
$ossObjectModel->size = $this->data['size'] ?? 0;
|
||||
|
||||
$ossObjectModel->is_enabled = OssObjectCode::DISABLE;
|
||||
$ossObjectModel->type = $type;
|
||||
|
||||
if (!$ossObjectModel->save()){
|
||||
|
||||
@@ -43,4 +43,46 @@ trait OssTrait
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改资源属性 -> Enable
|
||||
* @param array $ossIds
|
||||
* @return void
|
||||
*/
|
||||
public function updateOssObjects(array $ossIds): void
|
||||
{
|
||||
$this->checkOssObjects($ossIds);
|
||||
|
||||
$this->ossObjectModel->updateEnabledByIds($ossIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改资源属性 -> Disable
|
||||
* @param array $ossIds
|
||||
* @return void
|
||||
*/
|
||||
public function updateOssObjectsDisable(array $ossIds): void
|
||||
{
|
||||
$this->ossObjectModel->updateDisableByIds($ossIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有数据
|
||||
* @param array $ossIds
|
||||
* @return array
|
||||
*/
|
||||
public function getOssObjects(array $ossIds): array
|
||||
{
|
||||
$data = $this->ossObjectModel->getInfoByOssIds($ossIds);
|
||||
if (empty($data)){
|
||||
return [];
|
||||
}
|
||||
|
||||
$res = [];
|
||||
foreach ($data->toArray() as $one)
|
||||
{
|
||||
$res[$one['id']] = $one;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user