Optimize queries for lelongbid listing at pembida side

This commit is contained in:
Amir
2023-03-11 15:17:37 +08:00
parent 4270f7e701
commit 9247063ffb
3 changed files with 74 additions and 3 deletions
@@ -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);