Files
hyperf_service/app/Service/ServiceTrait/Common/OssTrait.php
2024-11-12 11:02:38 +08:00

46 lines
916 B
PHP

<?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)) . '】');
}
}
}