| 1234567891011121314151617181920212223242526272829303132 |
- <?php
- declare(strict_types=1);
- namespace app\miniapi\service;
- use app\miniapi\exception\ApiException;
- use app\miniapi\model\MiniPhoto;
- final class PhotoService
- {
- public function __construct(private readonly Access $access)
- {
- }
- public function read(int $id, string $scope, int $resource): MiniPhoto
- {
- $photo = MiniPhoto::query()->find($id);
- if (!$photo) {
- throw new ApiException(40401, '照片不存在', 404);
- }
- if ($scope === 'enterprise') {
- $this->access->enterpriseTask($resource, (int) $photo->delivery_id);
- } elseif ($scope === 'driver') {
- $this->access->driverTask($resource, (int) $photo->delivery_id);
- } else {
- throw new ApiException(42201, '照片访问身份无效', 422);
- }
- return $photo;
- }
- }
|