diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index 3c09500f..17f8a341 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -53,6 +53,45 @@ class CartController extends Controller return response()->json($carts); } + public function getCartByCawangan($userId) + { + $groupCawangan = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id') + ->join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id') + ->where('user_id', '=', $userId) + ->select('caw_id', 'caw_name') + ->groupBy('caw_id') + ->get()->toArray(); + + foreach ($groupCawangan as $index => $cawangan) { + + $cart = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id') + ->where('user_id', $userId) + ->where('caw_id', $cawangan) + ->get()->toArray(); + + foreach ($cart as $index1 => $data) { + + $marhun = LelongBidMarhun::where('lelongbid_id', '=', $data['id'])->get()->toArray(); + + $cart[$index1]['lelongbidmarhun'] = $marhun; + } + + $groupCawangan[$index]['lelongbid'] = $cart; + } + + if ($groupCawangan) { + return response()->json([ + 'success' => true, + 'cart' => $groupCawangan + ], 201); + } else { + return response()->json([ + 'success' => false, + 'message' => 'Empty Data' + ], 201); + } + } + public function addToCart(Request $request) { $item = new Cart; diff --git a/app/Http/Controllers/Mobile/LelongMobileController.php b/app/Http/Controllers/Mobile/LelongMobileController.php index 99e80ee6..ae71e801 100644 --- a/app/Http/Controllers/Mobile/LelongMobileController.php +++ b/app/Http/Controllers/Mobile/LelongMobileController.php @@ -170,6 +170,44 @@ class LelongMobileController extends Controller return response()->json($lelongbidder); } + public function bidRecordByCawangan($userId, Request $request) + { + $groupCawangan = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id') + ->join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id') + ->where('user_id', '=', $userId) + ->where('lelong_id', $request->lelongId) + ->select('caw_id', 'caw_name') + ->groupBy('caw_id') + ->get()->toArray(); + + foreach ($groupCawangan as $index => $cawangan) { + + $lelongBidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id') + ->where('user_id', $userId) + ->where('caw_id', $cawangan) + ->get()->toArray(); + + foreach ($lelongBidder as $index1 => $data) { + + $marhun = LelongBidMarhun::where('lelongbid_id', '=', $data['id'])->get()->toArray(); + $lelongBidder[$index1]['lelongbidmarhun'] = $marhun; + } + $groupCawangan[$index]['lelongbid'] = $lelongBidder; + } + + if ($groupCawangan) { + return response()->json([ + 'success' => true, + 'lelongbidder' => $groupCawangan + ], 201); + } else { + return response()->json([ + 'success' => false, + 'message' => 'Empty Data' + ], 201); + } + } + // please do not delete this changes // backup web pembida public function listBidItemWeb($user_id, Request $request){ @@ -274,6 +312,66 @@ class LelongMobileController extends Controller } } + public function listSuratLelong(Request $request) + { + + $currentdate = Carbon::now(); + $currentdate = $currentdate->toDateString(); + + $lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id') + ->where('tarikh_lelong', '=', $currentdate) + ->where('caw_id', '=', $request->caw_id) + ->where('status_online', '=', 1) + ->get()->toArray(); + + foreach ($lelong as $index1 => $lel) { + $lelongbid = LelongBid::where('lelong_id', $lel['lelong_id']) + ->where('caw_id', '=', $request->caw_id) + ->select('id', 'kodcaw') + ->get(); + $pluckedLelongBid = $lelongbid->pluck('id')->toArray(); + + $carts = Cart::where('user_id', $request->user_id) + ->select('lelongbid_id') + ->get(); + $pluckedCarts = $carts->pluck('lelongbid_id')->toArray(); + + $lelongbidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', "=", 'lelongbid.id') + ->where('lelong_id', $request->lelong_id) + ->where('user_id', $request->user_id) + ->select('lelongbid_id') + ->get(); + $pluckedLelongBidder = $lelongbidder->pluck('lelongbid_id')->toArray(); + + $arrayDiff1 = array_diff($pluckedLelongBid, $pluckedCarts); + $arrayDiff2 = array_diff($arrayDiff1, $pluckedLelongBidder); + + $listLelong = []; + foreach ($arrayDiff2 as $index => $data) { + + $lelongbid = LelongBid::where('id', $data)->first()->toArray(); + $lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelongbid['id'])->get()->toArray(); + + $lelongbid['lelongbidmarhun'] = $lelongbidmarhun; + + array_push($listLelong, $lelongbid); + $lelong[$index1]['lelongbid'] = $listLelong; + } + } + + if ($lelong) { + return response()->json( + ['success' => true, 'message' => $lelong], + 201 + ); + } else { + return response()->json( + ['success' => false, 'message' => 'Empty Data'], + 201 + ); + } + } + public function searchLelongByCawangan(Request $request){ $currentdate = Carbon::now(); @@ -922,4 +1020,38 @@ class LelongMobileController extends Controller ]); } } + + public function resultStatus($userId, $lelongId) + { + // dd('hey'); + $lelong = Lelong::join('lelongbid', 'lelong.id', '=', 'lelongbid.lelong_id') + ->join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id') + ->where('lelongbidder.user_id', $userId) + ->where('lelong.id', $lelongId) + ->where('status_bidder', 1) + ->get(); + + foreach ($lelong as $index) { + + $status = true; + + if ($index->status_payment == null || $index->status_payment == 0) { + $status = false; + } + } + + if ($lelong) { + return response()->json([ + 'success' => true, + 'statusMenang' => true, + 'statusBayaran' => $status, + ]); + } else { + return response()->json([ + 'success' => false, + 'statusMenang' => false, + + ]); + } + } } diff --git a/routes/api.php b/routes/api.php index cf85b328..b8e71c31 100644 --- a/routes/api.php +++ b/routes/api.php @@ -25,7 +25,6 @@ use App\Http\Controllers\ApiController; Route::post('/register', [AuthController::class, 'register']); Route::post('/user/login', [AuthController::class, 'loginUser']); -Route::get('/cart/{userid}', [CartController::class, 'getCart']); Route::post('/password/email', [ForgotPasswordController::class, 'sendResetLinkEmail']); // Route::post('/feepayment', [ApiController::class, 'feepayment']); @@ -46,12 +45,58 @@ Route::group(['middleware' => ['auth:sanctum']], function () { Route::get('/user/profile', [UserController::class, 'getProfileUser']); Route::put('/userUpdate/profile', [UserController::class, 'updateProfileUser']); - // Cart + //============HOME=========================== + //today's auction + Route::get('/listcawlelongtoday', [LelongMobileController::class, 'listCawLelongToday']); + //next auction + Route::get('/listcawlelongnext', [LelongMobileController::class, 'listCawLelongNext']); + + + //============LIST LELONG=========================== + //list cawangan started lelong + Route::get('/listcawlelongtodaystarted', [LelongMobileController::class, 'listCawLelongTodayStarted']); + //list surat exclude in cart and bid-record + Route::get('/lelongDetails/listSuratLelong', [LelongMobileController::class, 'listSuratLelong']); + + + + //============CART=========================== + //get cart group by cawangan + Route::get('/cartByCawangan/{userId}', [CartController::class, 'getCartByCawangan']); + //add item to cart Route::post('/addToCart', [CartController::class, 'addToCart']); - Route::post('/removeFromCart', [CartController::class, 'removeFromCart']); + //update item in cart Route::post('/updateItem', [CartController::class, 'updateItem']); + //delete item in cart Route::get('/deleteItem/{id}', [CartController::class, 'deleteCart']); + //===========STALE CART===================== + Route::post('/removeFromCart', [CartController::class, 'removeFromCart']); + Route::get('/cart/{userid}', [CartController::class, 'getCart']); + + + + //===========BID RECORD====================== + //get bid record group by cawangan + Route::get('/bidRecordByCawangan/{userId}', [LelongMobileController::class, 'bidRecordByCawangan']); + + //===========STALE BID RECORD================= + Route::get('/bidder/bidrecord', [LelongMobileController::class, 'bidRecord']); + + + + //===========RESULT====================== + //get all result + Route::get('/resultLelong', [LelongMobileController::class, 'resultLelong']); + //get status result + Route::get('/resultStatus/{userId}/{lelongId}', [LelongMobileController::class, 'resultStatus']); + + //===========PAY====================== + //get invoice detail + Route::get('/invoice', [LelongMobileController::class, 'getInvoiceId']); + + + // Lelong Route::get('/lelongDetails/today', [LelongMobileController::class, 'getlelongdetails']); Route::get('/lelongDetails/cawangan', [LelongMobileController::class, 'searchLelByCaw']); @@ -61,22 +106,17 @@ Route::group(['middleware' => ['auth:sanctum']], function () { Route::get('/bayar/{user_id}/{lelong_id}', [LelongMobileController::class, 'bidresults']); Route::get('/bayarBaki/{user_id}/{lelong_id}', [LelongMobileController::class, 'bidPayRemaining']); Route::get('/history/{user_id}', [LelongMobileController::class, 'history']); - Route::get('/listcawlelongtoday', [LelongMobileController::class, 'listCawLelongToday']); - Route::get('/listcawlelongtodaystarted', [LelongMobileController::class, 'listCawLelongTodayStarted']); - Route::get('/listcawlelongnext', [LelongMobileController::class, 'listCawLelongNext']); Route::post('/bayarcdm', [LelongMobileController::class, 'bayarCdm']); Route::post('/updateresit', [LelongMobileController::class, 'updateResit']); - Route::get('/invoice', [LelongMobileController::class, 'getInvoiceId']); - Route::get('/result-lelong', [LelongMobileController::class, 'resultLelong']); // Lelong => Bidder Route::post('/bidder/biditem', [LelongMobileController::class, 'bidderSelectBidItem']); Route::get('/bidder/listbiditem', [LelongMobileController::class, 'listBidItem']); Route::get('/bidder/listBidItemWeb/{user_id}', [LelongMobileController::class, 'listBidItemWeb']); - Route::get('/bidder/bidrecord', [LelongMobileController::class, 'bidRecord']); Route::get('/bidder/historyFeePay', [LelongMobileController::class, 'historyFeePay']); Route::post('/bidder/updatebiditem', [LelongMobileController::class, 'updatebiditem']); + });