Optimize queries for lelongbid listing at pembida side
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user