diff --git a/app/Http/Controllers/Mobile/LelongMobileController.php b/app/Http/Controllers/Mobile/LelongMobileController.php index 85555976..c22f57e8 100644 --- a/app/Http/Controllers/Mobile/LelongMobileController.php +++ b/app/Http/Controllers/Mobile/LelongMobileController.php @@ -435,6 +435,71 @@ class LelongMobileController extends Controller } } + public function listSuratLelong2(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) + ->select('lelong.id', 'lelong.tarikh_lelong', 'lelong.sts_lelong', 'cawangan_lelong.caw_id') + ->first(); + + $listLelong = []; + if ($lelong) { + $jenis_emas = JenisEmas::select('marhun', 'descpt')->get()->keyBy('marhun'); + + $cart_all = Cart::join('lelongbid', 'carts.lelongbid_id', "=", 'lelongbid.id') + ->where('user_id', $request->user_id) + ->where('caw_id', '=', $request->caw_id) + ->pluck('lelongbid_id'); + + $lelongbidder_all = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', "=", 'lelongbid.id') + ->where('lelong_id', $request->lelong_id) + ->where('user_id', $request->user_id) + ->where('caw_id', '=', $request->caw_id) + ->pluck('lelongbid_id'); + + $combine_carts_lelongbidder = $cart_all->concat($lelongbidder_all); + + $lelongbid_all = LelongBid::with('lelongBidMarhun', 'fileMarhunMainMany') + ->where('lelong_id', $lelong->id) + ->where('caw_id', $request->caw_id) + ->where('status_jual', 0) + ->whereNotIn('id', $combine_carts_lelongbidder) + ->get(); + + foreach ($lelongbid_all as $lelongbid) { + foreach ($lelongbid->lelongBidMarhun as $lel_bid_marhun) { + if ($jenis_emas[$lel_bid_marhun->marhun]) { + $lel_bid_marhun['marhun_desc'] = $jenis_emas[$lel_bid_marhun->marhun]->descpt; + } + } + $lelongbid->lelongbidmarhun = $lelongbid->lelongBidMarhun; + unset($lelongbid->lelongBidMarhun); + + if ($lelongbid->fileMarhunMainMany->isNotEmpty()) { + $lelongbid->filemarhun = $lelongbid->fileMarhunMainMany; + } + unset($lelongbid->fileMarhunMainMany); + + array_push($listLelong, $lelongbid); + } + + $lelong['lelongbid'] = $listLelong; + + return response()->json( + ['success' => true, 'message' => $lelong],201 + ); + } else { + return response()->json( + ['success' => false, 'message' => 'Empty Data'],201 + ); + } + } + public function photoMarhun(Request $request) { $fileMarhun = FileMarhun::find($request->filemarhun_id); diff --git a/app/Models/LelongBid.php b/app/Models/LelongBid.php index 0873031c..45e5a981 100644 --- a/app/Models/LelongBid.php +++ b/app/Models/LelongBid.php @@ -53,8 +53,14 @@ class LelongBid extends Model return $this->hasOne(CawanganLelong::class, 'caw_id','caw_id'); } - public function fileMarhunMain() { - return $this->hasOne(FileMarhun::class, 'lelongbid_id'); + public function fileMarhunMain() + { + return $this->hasOne(FileMarhun::class, 'lelongbid_id')->where('photo_type', 1); + } + + public function fileMarhunMainMany() + { + return $this->hasMany(FileMarhun::class, 'lelongbid_id')->where('photo_type', 1); } public function lelong() diff --git a/routes/api.php b/routes/api.php index 82929f81..a01b2aee 100644 --- a/routes/api.php +++ b/routes/api.php @@ -59,7 +59,7 @@ Route::group(['middleware' => ['auth:sanctum']], function () { //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']); + Route::get('/lelongDetails/listSuratLelong', [LelongMobileController::class, 'listSuratLelong2']); //list lelong online Route::get('/lelongOnline', [LelongMobileController::class, 'lelongOnline']); //photo marhun