184 lines
5.7 KiB
PHP
184 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Mobile;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Lelong;
|
|
use App\Models\LelongBid;
|
|
use App\Models\LelongBidder;
|
|
use App\Models\LelongBidMarhun;
|
|
use App\Models\lelkarat;
|
|
use App\Models\User;
|
|
use App\Models\Payment;
|
|
use App\Models\Cart;
|
|
use Carbon\Carbon;
|
|
use App\Models\Cawangan;
|
|
|
|
class LelongMobileController extends Controller
|
|
{
|
|
|
|
public function getlelongdetails(Request $request){
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
// $arrayLelong = [];
|
|
$lelong = Lelong::where('tarikh_lelong','=',$currentdate)
|
|
->where('sts_lelong','=',1)
|
|
->get()->toArray();
|
|
|
|
if($lelong)
|
|
{
|
|
foreach($lelong as $index1=>$lel)
|
|
{
|
|
$lelongbid = LelongBid::whereIn('lelong_id',$lelong)
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'] = $lelongbid;
|
|
|
|
foreach($lelongbid as $index2=>$lelbidmarhun){
|
|
$cawangan = Cawangan::where('id','=',$lelbidmarhun['caw_id'])->first()->toArray();
|
|
// $id = lelongbid::first();
|
|
|
|
$lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelbidmarhun['id'])
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'][$index2]['lelongbidmarhun'] = $lelongbidmarhun;
|
|
$lelong[$index1]['lelongbid'][$index2]['cawangan'] = $cawangan;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
$lelong[0]['lelongbid'] = 0;
|
|
}
|
|
|
|
return response()->json($lelong);
|
|
|
|
}
|
|
|
|
public function getListKarat(Request $request){
|
|
|
|
$getKarat = lelkarat::all();
|
|
|
|
// $lelongBidder = lelongBidder::all();
|
|
|
|
return response()->json($getKarat);
|
|
|
|
}
|
|
|
|
public function bidderSelectBidItem(Request $request){
|
|
|
|
$feepayment = Payment::where('lelong_id', '=', $request->lelong_id)->first();
|
|
|
|
if($feepayment != null){
|
|
|
|
$user = User::where('id', '=', $request->user_id)
|
|
->first();
|
|
|
|
$carts = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id')
|
|
->join('lelong', 'lelongbid.lelong_id', '=', 'lelong.id')
|
|
->where('lelong.sts_lelong','=',1)
|
|
->where('carts.user_id', $user->id)
|
|
->select('lelongbid.id as lelongbid_id',
|
|
'lelongbid.t_lelong',
|
|
'lelongbid.nilaimarhun',
|
|
'lelongbid.cajlelong',
|
|
'carts.hargabida',
|
|
'carts.id as cart_id')
|
|
->get();
|
|
|
|
// dd($selectBid[0]->hargabida);
|
|
|
|
$currentdate = Carbon::now()->toDateTimeString();
|
|
|
|
foreach($carts as $cart)
|
|
{
|
|
$lelongBidder = new LelongBidder();
|
|
$lelongBidder->nama_bidder = $request->name;
|
|
$lelongBidder->user_id = $user->id;
|
|
$lelongBidder->notelbimbit = $user->notelbimbit;
|
|
$lelongBidder->hargabida = $cart->hargabida;
|
|
$lelongBidder->lelongbid_id = $cart->lelongbid_id;
|
|
$lelongBidder->nilaimarhun = $cart->nilaimarhun;
|
|
$lelongBidder->cajlelong = $cart->cajlelong;
|
|
$lelongBidder->masa_bidaan = $currentdate;
|
|
if($lelongBidder->save())
|
|
{
|
|
$delincart = Cart::where('id',$cart->cart_id)->first();
|
|
$delincart->delete();
|
|
}
|
|
|
|
}
|
|
|
|
$response = [
|
|
'success' => "success",
|
|
'message' => "Bidder berjaya disimpan"
|
|
];
|
|
|
|
return response()->json($response, 201);
|
|
}
|
|
else if($feepayment == null){
|
|
|
|
$errors = [
|
|
'success' => "error",
|
|
'message' => "Something wrong with the server"
|
|
];
|
|
return response()->json($response, 201);
|
|
}
|
|
}
|
|
|
|
public function listBidItem(Request $request){
|
|
|
|
$lelongbidder = LelongBidder::where('user_id','=', $request->user_id)
|
|
->get()->toArray();
|
|
|
|
foreach($lelongbidder as $index1=>$lelbid)
|
|
{
|
|
$lelongbid = LelongBid::whereIn('id',$lelongbidder)
|
|
->get()->toArray();
|
|
|
|
$lelongbidder[$index1]['lelongbid'] = $lelongbid;
|
|
}
|
|
|
|
return response()->json($lelongbidder);
|
|
}
|
|
|
|
public function searchLelByCaw(Request $request){
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
// $arrayLelong = [];
|
|
$lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
|
|
->where('tarikh_lelong','=',$currentdate)
|
|
->where('caw_id', '=', $request->caw_id)
|
|
->get()->toArray();
|
|
|
|
foreach($lelong as $index1=>$lel)
|
|
{
|
|
$lelongbid = LelongBid::where('lelong_id',$lel['lelong_id'])
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'] = $lelongbid;
|
|
|
|
foreach($lelongbid as $index2=>$lelbidmarhun){
|
|
$cawangan = Cawangan::where('id','=',$lelbidmarhun['caw_id'])->first()->toArray();
|
|
// $id = lelongbid::first();
|
|
|
|
$lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelbidmarhun['id'])
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'][$index2]['lelongbidmarhun'] = $lelongbidmarhun;
|
|
$lelong[$index1]['lelongbid'][$index2]['cawangan'] = $cawangan;
|
|
}
|
|
|
|
}
|
|
|
|
return response()->json($lelong);
|
|
}
|
|
}
|