feat : basic
This commit is contained in:
46
app/Service/ServiceTrait/Common/OssTrait.php
Normal file
46
app/Service/ServiceTrait/Common/OssTrait.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\ServiceTrait\Common;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\OssObject;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
trait OssTrait
|
||||
{
|
||||
/**
|
||||
* oss资源表
|
||||
* @var OssObject
|
||||
*/
|
||||
#[Inject]
|
||||
protected OssObject $ossObjectModel;
|
||||
|
||||
|
||||
/**
|
||||
* 确认资源
|
||||
* @param array $ossIds
|
||||
* @return void
|
||||
*/
|
||||
public function checkOssObjects(array $ossIds): void
|
||||
{
|
||||
$data = $this->ossObjectModel->getIdListByIds($ossIds);
|
||||
if (empty($data)){
|
||||
throw new ErrException('资源不存在');
|
||||
}
|
||||
|
||||
$data = $data->toArray();
|
||||
|
||||
if (count($data) != count($ossIds)) {
|
||||
throw new ErrException('资源不存在【' . implode('|', array_diff($ossIds, $data)) . '】');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user