feat : basic

This commit is contained in:
2024-11-12 11:02:38 +08:00
parent 235acbea9c
commit a9f81888b7
26 changed files with 342 additions and 209 deletions

View File

@@ -10,7 +10,7 @@ declare(strict_types=1);
namespace App\Service\ServiceTrait\Api;
use App\Exception\ApiException;
use App\Exception\ErrException;
use App\Lib\Log;
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Di\Annotation\Inject;
@@ -68,12 +68,12 @@ trait WxMiniTrait
$res = json_decode($contents,true);
if (empty($res['errcode']) || $res['errcode'] != 0) throw new ApiException($res['errmsg'] ?? '系统繁忙');
if (empty($res['errcode']) || $res['errcode'] != 0) throw new ErrException($res['errmsg'] ?? '系统繁忙');
return $res;
}catch (GuzzleException $e) {
$this->log->debug(__CLASS__.':debug:'.$e->getMessage());
throw new ApiException($e->getMessage());
throw new ErrException($e->getMessage());
}
}
}

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