From 7c38c7619d2500eb7708d7ed0714811a4c36cfdb Mon Sep 17 00:00:00 2001 From: Amir Date: Wed, 5 Oct 2022 12:35:34 +0800 Subject: [PATCH] fix api --- .../Controllers/AuthMobile/AuthController.php | 4 +- .../Mobile/LelongMobileController.php | 53 +++++++++++-------- app/Models/LelongBid.php | 4 ++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/AuthMobile/AuthController.php b/app/Http/Controllers/AuthMobile/AuthController.php index 367da1e4..46e26b73 100644 --- a/app/Http/Controllers/AuthMobile/AuthController.php +++ b/app/Http/Controllers/AuthMobile/AuthController.php @@ -30,7 +30,7 @@ class AuthController extends Controller if ($validator->fails()) { $errors = [ - 'success' => "error", + 'success' => false, 'message' => $validator->errors() ]; return response($errors, 201); @@ -73,7 +73,7 @@ class AuthController extends Controller $token = $user->createToken('myapptoken')->plainTextToken; $response = [ - 'success' => "success", + 'success' => true, 'user' => $user, 'token' => $token ]; diff --git a/app/Http/Controllers/Mobile/LelongMobileController.php b/app/Http/Controllers/Mobile/LelongMobileController.php index 78802c0c..75c435bc 100644 --- a/app/Http/Controllers/Mobile/LelongMobileController.php +++ b/app/Http/Controllers/Mobile/LelongMobileController.php @@ -66,13 +66,24 @@ class LelongMobileController extends Controller } - public function getListKarat(Request $request){ + public function getListKarat() + { - $getKarat = LelKarat::all(); - - // $lelongBidder = lelongBidder::all(); - - return response()->json($getKarat); + $activeLelong = Lelong::where('sts_lelong', '=', 1)->first(); + if (isset($activeLelong)) { + $getKarat = LelKarat::where('lelong_id', '=' ,$activeLelong['id'])->get(); + + $updatedDateTime = $getKarat[0]['updated_at']->toDateTimeString(); + return response()->json([ + 'success' => true, + 'karat' => $getKarat, + 'update_time' => $updatedDateTime + ], 201); + } else { + return response()->json([ + 'success' => false, + ], 201); + } } @@ -315,7 +326,6 @@ class LelongMobileController extends Controller public function listSuratLelong(Request $request) { - $currentdate = Carbon::now(); $currentdate = $currentdate->toDateString(); @@ -323,10 +333,10 @@ class LelongMobileController extends Controller ->where('tarikh_lelong', '=', $currentdate) ->where('caw_id', '=', $request->caw_id) ->where('status_online', '=', 1) - ->get()->toArray(); + ->first(); - foreach ($lelong as $index1 => $lel) { - $lelongbid = LelongBid::where('lelong_id', $lel['lelong_id']) + if ($lelong) { + $lelongbid = LelongBid::where('lelong_id', $lelong['lelong_id']) ->where('caw_id', '=', $request->caw_id) ->select('id', 'kodcaw') ->get(); @@ -350,21 +360,23 @@ class LelongMobileController extends Controller $listLelong = []; foreach ($arrayDiff2 as $index => $data) { - $lelongbid = LelongBid::where('id', $data)->first()->toArray(); + $lelongbid = LelongBid:: + // join('filemarhun', 'lelongbid.id', '=', 'filemarhun.lelongbid_id') + where('id', $data) + // ->where('photo_type', 1) + ->first()->toArray(); $lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelongbid['id'])->get()->toArray(); foreach ($lelongbidmarhun as $index1 => $marhun) { $marhunDesc = JenisEmas::where('marhun', $marhun['marhun'])->first()->toArray(); $lelongbidmarhun[$index1]['marhun_desc'] = $marhunDesc['descpt']; } - + $lelongbid['lelongbidmarhun'] = $lelongbidmarhun; array_push($listLelong, $lelongbid); - $lelong[$index1]['lelongbid'] = $listLelong; } - } + $lelong['lelongbid'] = $listLelong; - if ($lelong) { return response()->json( ['success' => true, 'message' => $lelong], 201 @@ -700,8 +712,8 @@ class LelongMobileController extends Controller $currentdate = $currentdate->toDateString(); $lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id') - ->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id') - ->where('tarikh_lelong', '=', $currentdate) + ->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id') + ->where('tarikh_lelong', '=', $currentdate) ->select( 'lelong.id as lelong_id', 'lelong.tarikh_lelong', @@ -710,12 +722,11 @@ class LelongMobileController extends Controller 'cawangan_lelong.masamula_lelong', 'cawangan_lelong.masatamat_lelong', ) - ->get()->toArray(); - - if ($lelong) { + ->get(); + if ($lelong->isNotEmpty()) { return response()->json([ 'success' => true, - 'lelong' => $lelong + 'lelong' => $lelong, ]); } else { return response()->json([ diff --git a/app/Models/LelongBid.php b/app/Models/LelongBid.php index de2bae4c..1f42d1ee 100644 --- a/app/Models/LelongBid.php +++ b/app/Models/LelongBid.php @@ -47,4 +47,8 @@ class LelongBid extends Model public function cawanganLelong(){ return $this->hasOne(CawanganLelong::class, 'caw_id','caw_id'); } + + public function fileMarhunMain() { + return $this->hasOne(FileMarhun::class, 'lelongbidmarhun_id'); + } }