From 92d2460a957f44d91ce785c1ddf5e2e4e67fd25e Mon Sep 17 00:00:00 2001 From: Amir Date: Thu, 1 Dec 2022 09:49:50 +0800 Subject: [PATCH] Read photoMarhun in CartController --- app/Http/Controllers/CartController.php | 5 ++++ app/Http/Controllers/LelongController.php | 2 ++ .../Mobile/LelongMobileController.php | 24 +++++++++++++++++++ app/Services/MarhunPhotoService.php | 19 +++++++++++++++ routes/api.php | 2 ++ 5 files changed, 52 insertions(+) diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index 2ade905f..4fc07354 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -19,6 +19,8 @@ use App\Models\LelongBidMarhun; use App\Models\LelKarat; use App\Models\Cart; use Carbon\Carbon; +use App\Models\FileMarhun; + class CartController extends Controller { @@ -78,6 +80,9 @@ class CartController extends Controller $total_surat = 0; foreach ($cart as $index1 => $data) { + $fileMarhun = FileMarhun::where('lelongbid_id', $data['id'])->get(); + $cart[$index1]['filemarhun'] = $fileMarhun; + $total_hargabida += $data['hargabida']; $total_berat += $data['berat']; $total_surat += 1; diff --git a/app/Http/Controllers/LelongController.php b/app/Http/Controllers/LelongController.php index 6ce627fa..5cf8bd90 100644 --- a/app/Http/Controllers/LelongController.php +++ b/app/Http/Controllers/LelongController.php @@ -164,6 +164,8 @@ class LelongController extends Controller ->where('kodcaw', '=', $cawanganLelong->cawangan->caw_code) ->sum('total_payment'); + // dd($cawanganLelong->cawangan->caw_code, $request->tarikh_lelong, $lelongDetails->masamula_lelong, $lelongDetails->masatamat_lelong, $lelongBidMaster->toArray(), $lelongbidmarhun->toArray(), floatval($paymentOnline), floatval($paymentTunai)); + $exportData = Http::withOptions(['verify' => config('app.api_verify')])->post( config('app.api_url') . 'exportLelong', [ diff --git a/app/Http/Controllers/Mobile/LelongMobileController.php b/app/Http/Controllers/Mobile/LelongMobileController.php index b301840b..4bf2184c 100644 --- a/app/Http/Controllers/Mobile/LelongMobileController.php +++ b/app/Http/Controllers/Mobile/LelongMobileController.php @@ -19,6 +19,7 @@ use App\Models\Resit; use App\Models\FileResit; use App\Models\Invoice; use App\Models\JenisEmas; +use App\Services\MarhunPhotoService; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; @@ -345,6 +346,7 @@ class LelongMobileController extends Controller if ($lelong) { $lelongbid = LelongBid::where('lelong_id', $lelong['lelong_id']) ->where('caw_id', '=', $request->caw_id) + ->where('status_jual', '=', 0) ->select('id', 'kodcaw') ->get(); $pluckedLelongBid = $lelongbid->pluck('id')->toArray(); @@ -377,6 +379,20 @@ class LelongMobileController extends Controller $lelongbid['lelongbidmarhun'] = $lelongbidmarhun; $fileMarhun = FileMarhun::where('lelongbid_id', $lelongbid['id'])->get(); + // dd($fileMarhun); + + // foreach ($fileMarhun as $index) { + // dd($index); + // // $eachmarhun = FileMarhun::where('lelongbidmarhun_id', '=', $index['id'])->first(); + // // if (isset($eachmarhun)) { + // // $index->eachmarhun_filename = route('marhun.showphotomarhun', ['norujukan_sag' => $lelongbid['norujukan'], 'filemarhun_id' => $index->id]); + // // $test = route('marhun.showphotomarhun', ['norujukan_sag' => $lelongbid['norujukan'], 'filemarhun_id' => $index->id]); + // $marhunPhotoService = new MarhunPhotoService(); + // $marhun_photo = $marhunPhotoService->get($lelongbid['norujukan'], $index); + // dd($marhun_photo); + // return $marhun_photo; + // } + // // dd($fileMarhun); if ($fileMarhun->isNotEmpty()) { $lelongbid['filemarhun'] = $fileMarhun; @@ -398,6 +414,14 @@ class LelongMobileController extends Controller } } + public function photoMarhun(Request $request) + { + $fileMarhun = FileMarhun::find($request->filemarhun_id); + $marhunPhotoService = new MarhunPhotoService(); + $marhun_photo = $marhunPhotoService->get($request->norujukan, $fileMarhun); + return base64_encode($marhun_photo); + } + public function lelongOnline() { $lelong = Lelong::where('sts_lelong', '=', 1)->first(); diff --git a/app/Services/MarhunPhotoService.php b/app/Services/MarhunPhotoService.php index 1cdac2a8..d86ea30e 100644 --- a/app/Services/MarhunPhotoService.php +++ b/app/Services/MarhunPhotoService.php @@ -92,4 +92,23 @@ class MarhunPhotoService header('Content-Disposition: inline; filename="'.basename($filePath).'"'); readfile($filePath); } + + public function get($norujukan_sag, $marhun) + { + $lelongbidmarhun_id = $marhun->lelongbidmarhun_id; + + $photo_type_name = $marhun->photo_type === 1 ? 'overall_photo' : 'by_marhun_photo'; + + $directory = "/{$norujukan_sag}/{$photo_type_name}/"; + $imageExtension = $marhun->file_type; + + $marhunImageFileName = "overall.{$imageExtension}"; + + if (!empty($lelongbidmarhun_id)) { + $marhunImageFileName = "$lelongbidmarhun_id.$imageExtension"; + } + + return Storage::disk('marhun')->get("{$directory}${marhunImageFileName}"); + + } } diff --git a/routes/api.php b/routes/api.php index 48cc6779..168ae91e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -59,6 +59,8 @@ Route::group(['middleware' => ['auth:sanctum']], function () { Route::get('/lelongDetails/listSuratLelong', [LelongMobileController::class, 'listSuratLelong']); //list lelong online Route::get('/lelongOnline', [LelongMobileController::class, 'lelongOnline']); + //photo marhun + Route::get('/photoMarhun',[LelongMobileController::class, 'photoMarhun']);