PhotoService.php 846 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\miniapi\service;
  4. use app\miniapi\exception\ApiException;
  5. use app\miniapi\model\MiniPhoto;
  6. final class PhotoService
  7. {
  8. public function __construct(private readonly Access $access)
  9. {
  10. }
  11. public function read(int $id, string $scope, int $resource): MiniPhoto
  12. {
  13. $photo = MiniPhoto::query()->find($id);
  14. if (!$photo) {
  15. throw new ApiException(40401, '照片不存在', 404);
  16. }
  17. if ($scope === 'enterprise') {
  18. $this->access->enterpriseTask($resource, (int) $photo->delivery_id);
  19. } elseif ($scope === 'driver') {
  20. $this->access->driverTask($resource, (int) $photo->delivery_id);
  21. } else {
  22. throw new ApiException(42201, '照片访问身份无效', 422);
  23. }
  24. return $photo;
  25. }
  26. }