From 87a4fdc59fb2951f0154d9b8f714e44154038abc Mon Sep 17 00:00:00 2001 From: Amir Date: Sun, 9 Oct 2022 12:18:33 +0800 Subject: [PATCH 1/2] fix login api --- .../Controllers/AuthMobile/AuthController.php | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/AuthMobile/AuthController.php b/app/Http/Controllers/AuthMobile/AuthController.php index 46e26b73..0ceb7a3f 100644 --- a/app/Http/Controllers/AuthMobile/AuthController.php +++ b/app/Http/Controllers/AuthMobile/AuthController.php @@ -81,53 +81,55 @@ class AuthController extends Controller return response($response, 201); } - public function loginUser(Request $request) { + public function loginUser(Request $request) + { $fields = $request->validate([ 'username' => 'required|string', 'password' => 'required|string' ]); - //Check username - $user = User::where('username', $fields['username'])->first(); - - if($user->status != 'active') - { - if($user->status == 'banned') - { - return response([ - 'message' => 'User Banned' - ], 401); - } - else if($user->status == 'rejected') - { - return response([ - 'message' => 'rejected', - 'nota' => $user->note - ], 401); - } - else - { - return response([ - 'message' => 'Registration in progress,status wait for approval.' - ], 401); - } - } - //Check Password - if(!$user || !Hash::check($fields['password'], $user->password)){ + $user = User::where('username', $fields['username'])->first(); - return response([ - 'message' => 'Bad Creds' - ], 401); + if ($user) { - } + $passwordTrue = Hash::check($fields['password'], $user->password); - $token = $user->createToken('myapptoken')->plainTextToken; - $response = [ - 'user' => $user, - 'token' => $token - ]; - - return response($response, 201); + if ($passwordTrue) { + if ($user->status == 'active') { + $token = $user->createToken('myapptoken')->plainTextToken; + return response([ + 'statusAkaun' => 1, + 'user' => $user, + 'token' => $token + ]); + } else if ($user->status == 'banned') { + return response()->json([ + 'statusAkaun' => 2, + 'message' => "User banned." + ]); + } else if ($user->status == 'rejected') { + return response([ + 'statusAkaun' => 3, + 'message' => "Rejected." + ]); + } else { + return response([ + 'statusAkaun' => 4, + 'message' => 'Registration in progress,status wait for approval.' + ]); + } + } else { + return response()->json([ + 'statusAkaun' => 5, + 'message' => "Kata Laluan Salah." + ]); + } + } else { + return response()->json([ + 'statusAkaun' => 0, + 'message' => "Akaun tiada." + ]); + } } public function logoutUser(Request $request){ From 00c02f39ad03cfc78b2add531e99a955e3465279 Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 11 Oct 2022 06:20:28 +0800 Subject: [PATCH 2/2] fix api pembida --- app/Http/Controllers/CartController.php | 22 +++++++++++++++++-- .../Mobile/LelongMobileController.php | 9 ++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index 0ab8ed92..f7552f91 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -62,6 +62,9 @@ class CartController extends Controller ->groupBy('caw_id') ->get()->toArray(); + $master_total_surat = 0; + $master_total_bidaan = 0; + foreach ($groupCawangan as $index => $cawangan) { $cart = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id') @@ -69,20 +72,35 @@ class CartController extends Controller ->where('caw_id', $cawangan) ->get()->toArray(); - foreach ($cart as $index1 => $data) { + $total_hargabida = 0; + $total_berat = 0; + $total_surat = 0; + foreach ($cart as $index1 => $data) { + $total_hargabida += $data['hargabida']; + $total_berat += $data['berat']; + $total_surat += 1; $marhun = LelongBidMarhun::where('lelongbid_id', '=', $data['id'])->get()->toArray(); $cart[$index1]['lelongbidmarhun'] = $marhun; } + $groupCawangan[$index]['total_surat'] = $total_surat; + $groupCawangan[$index]['total_berat'] = $total_berat; + $groupCawangan[$index]['total_bidaan'] = number_format((float)$total_hargabida, 2, '.', ''); $groupCawangan[$index]['lelongbid'] = $cart; + + $master_total_surat += $total_surat; + $master_total_bidaan += $total_hargabida; } + if ($groupCawangan) { return response()->json([ 'success' => true, - 'cart' => $groupCawangan + 'cart' => $groupCawangan, + 'master_total_surat' => $master_total_surat, + 'master_total_bidaan' => number_format((float)$master_total_bidaan, 2, '.', ''), ], 201); } else { return response()->json([ diff --git a/app/Http/Controllers/Mobile/LelongMobileController.php b/app/Http/Controllers/Mobile/LelongMobileController.php index 75c435bc..30d6d8a5 100644 --- a/app/Http/Controllers/Mobile/LelongMobileController.php +++ b/app/Http/Controllers/Mobile/LelongMobileController.php @@ -199,11 +199,16 @@ class LelongMobileController extends Controller ->where('caw_id', $cawangan) ->get()->toArray(); + $total_hargabida = 0; + $total_berat = 0; foreach ($lelongBidder as $index1 => $data) { - + $total_hargabida += $data['hargabida']; + $total_berat += $data['berat']; $marhun = LelongBidMarhun::where('lelongbid_id', '=', $data['id'])->get()->toArray(); $lelongBidder[$index1]['lelongbidmarhun'] = $marhun; } + $groupCawangan[$index]['total_berat'] = $total_berat; + $groupCawangan[$index]['total_bidaan'] = number_format((float)$total_hargabida, 2, '.', ''); $groupCawangan[$index]['lelongbid'] = $lelongBidder; } @@ -1025,7 +1030,7 @@ class LelongMobileController extends Controller $lelong[$index]['status'] = $status; } - if (!empty($lelong)) { + if ($lelong->isNotEmpty()) { return response()->json([ 'success' => true, 'lelong' => $lelong,