file.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. use App\Http\Controllers\GoogleOCRController;
  3. use App\Services\CallApiService;
  4. use App\Services\MediaLibraryService;
  5. use App\Services\Msg\MailTemplateService;
  6. use Carbon\Carbon;
  7. use Illuminate\Support\Facades\Route;
  8. use Illuminate\Http\Request;
  9. use Intervention\Image\Facades\Image;
  10. Route::post('/put-msg-template', function () {
  11. $result = app(MailTemplateService::class)
  12. ->putTemplate(request('FilePath'), request('Message'), request('Theme'));
  13. return response([ 'error' => ! $result, 'data' => null ], 200);
  14. });
  15. Route::get('/google-ocr', [GoogleOCRController::class, 'index'])->name('index');
  16. Route::post('/google-ocr', [GoogleOCRController::class, 'submit'])->name('submit');
  17. Route::post('/pro-file-upload', function (Request $request) {
  18. if (!$request->hasFile('file')) {
  19. return response('error', 500);
  20. }
  21. $mediaLibraryService = app(MediaLibraryService::class);
  22. $mediaLibraryService->setGateToken(session('GateToken')['main']);
  23. $setup = $mediaLibraryService->getSetup('item');
  24. $path = $mediaLibraryService->getCurrSetupFilePath($setup);
  25. $file = $request->file('file');
  26. $image = Image::make($file);
  27. $fileExtension = $file->extension();
  28. $media = [
  29. 'name' => date('mdYHis') . uniqid() . $file->getClientOriginalName() . '.' . $fileExtension,
  30. 'path' => $path,
  31. 'setup' => $setup,
  32. 'type' => 'image'
  33. ];
  34. $hdPage = [
  35. 'Id' => 0,
  36. 'MediaNo' => $mediaLibraryService->lastSlipNoGet(),
  37. 'MediaDate' => Carbon::now()->format('Ymd'),
  38. 'MediaBrand' => $setup['BrandCode'],
  39. 'MediaName' => $media['name'],
  40. 'MineType' => $file->getMimeType(),
  41. 'FileUrl' => '/' . substr($media['path'], '1') . $media['name'],
  42. 'FileSize' => (int)round($image->filesize() / 1024),
  43. 'MediaWidth' => $image->width(),
  44. 'MediaHeight' => $image->height(),
  45. 'IsClosed' => '0'
  46. ];
  47. $file->storeAs($media['path'], $media['name'], ['disk' => getDisk()]);
  48. if ($fileExtension === 'gif' || $fileExtension === 'webp' || $fileExtension === 'svg') {
  49. $bdPage = $mediaLibraryService->makeGifBd($file, $media);
  50. } else {
  51. $bdPage = $mediaLibraryService->makeImageBd($file, $media);
  52. }
  53. $mediaBact = app(CallApiService::class)->callApi([
  54. 'url' => 'media-bact',
  55. 'data' => [
  56. 'HdPage' => [
  57. $hdPage
  58. ],
  59. 'BdPage' => $bdPage
  60. ]
  61. ]);
  62. if (app(CallApiService::class)->verifyApiError($mediaBact)) {
  63. return response('error', 500);
  64. }
  65. return response()->json($mediaBact);
  66. });