319 lines
10 KiB
PHP
319 lines
10 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;
|
|
use App\Models\Resit;
|
|
|
|
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'] = [];
|
|
}
|
|
|
|
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::join('resit', 'payment.resit_id','=','resit.id')
|
|
->where('payment.user_id',$request->user_id)
|
|
->where('payment.lelong_id', '=', $request->lelong_id)
|
|
->where('resit.resit_type',1)
|
|
->where('resit.status','PAID')->first();
|
|
// dd($feepayment);
|
|
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($carts);
|
|
// 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);
|
|
}
|
|
|
|
public function bidresult($user_id)
|
|
{
|
|
$sag = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->join('lelong', 'lelongbid.lelong_id', '=', 'lelong.id')
|
|
->where('lelongbidder.user_id',$user_id)
|
|
// ->where('lelongbid.lelong_id',$lelong_id)
|
|
->where('lelongbidder.status_bidder',1)
|
|
->whereNull('lelongbidder.status_payment')
|
|
->select(
|
|
'lelongbid.lelong_id',
|
|
'lelongbidder.user_id',
|
|
'lelongbidder.lelongbid_id',
|
|
'lelongbidder.hargabida',
|
|
'lelongbidder.status_payment',
|
|
'lelongbid.norujukan'
|
|
|
|
)
|
|
->get();
|
|
|
|
// dd($sag);
|
|
$data = [];
|
|
$total_hargabida = $sag->sum('hargabida');
|
|
array_push($data,[
|
|
'sag'=> $sag,
|
|
'total_hargabida'=> $total_hargabida
|
|
]);
|
|
// dd($winner);
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function updatebiditem(Request $request)
|
|
{
|
|
// dd($request->norujukan->toArray());
|
|
// foreach($request->norujukan as $norujukan)
|
|
// {
|
|
// dd($norujukan);
|
|
// }
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
$lelongbid = LelongBid::whereIn('norujukan',$request->norujukan)
|
|
->where('lelong_id',$request->lelong_id)
|
|
->get();
|
|
|
|
foreach($lelongbid as $bid)
|
|
{
|
|
$lelongbidder = LelongBidder::where('lelongbid_id',$bid->id)
|
|
->where('user_id',$request->user_id)->first();
|
|
$lelongbidder->status_payment =1;
|
|
$lelongbidder->payment_id = $request->paymentid;
|
|
$lelongbidder->save();
|
|
|
|
$lelongbid = LelongBid::where('id',$bid->id)->first();
|
|
$lelongbid->status_jual = 1;
|
|
$lelongbid->t_jual = $currentdate;
|
|
$lelongbid->hargajual = $lelongbidder->hargabida;
|
|
$lelongbid->save();
|
|
|
|
}
|
|
|
|
// $alllelongbidder = LelongBidder::join('lelongbid','lelongbidder.lelongbid_id','lelongbid.id')
|
|
// ->where('lelongbidder.user_id',$request->user_id)
|
|
// ->where('lelongbid.lelong_id',$request->lelong_id)
|
|
// ->where('lelongbidder.status_bidder',1)
|
|
// ->select('lelongbidder.hargabida')
|
|
// ->get();
|
|
|
|
// $resit = Resit::where('lelong_id',$request->lelong_id)
|
|
// ->where('user_id',$request->user_id)
|
|
// ->where('resit_type',2)
|
|
// ->first();
|
|
|
|
// if($resit->total_payment > $alllelongbidder->SUM('hargabida'))
|
|
// {
|
|
// $resit->status = 'PAID';
|
|
// $resit->paid_at = $currentdate;
|
|
// $resit->save();
|
|
// }
|
|
|
|
$response = [
|
|
'success' => "success",
|
|
'message' => "Bidaan berjaya dibayar"
|
|
];
|
|
|
|
return response()->json($response, 201);
|
|
|
|
}
|
|
|
|
public function history($user_id)
|
|
{
|
|
$lelongs_id = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('lelongbidder.user_id',$user_id)->select('lelongbid.lelong_id')->groupBy('lelongbid.lelong_id')->get();
|
|
|
|
$arrayID = [];
|
|
foreach($lelongs_id as $lelong_id)
|
|
{
|
|
array_push($arrayID,$lelong_id);
|
|
}
|
|
$lelongs = Lelong::whereIn('id',$arrayID)->get()->toArray();
|
|
// dd($lelongs);
|
|
|
|
foreach($lelongs as $index1 => $lelong)
|
|
{
|
|
// dd($lelong['id']);
|
|
$datalelongbidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('lelongbid.lelong_id',$lelong['id'])
|
|
->where('user_id',$user_id)
|
|
->where('status_bidder',1)->get();
|
|
|
|
$payment = Payment::join('resit', 'payment.resit_id', '=', 'resit.id')
|
|
->where('payment.lelong_id',$lelong['id'])
|
|
->where('payment.user_id',$user_id)
|
|
->where('resit.resit_type',2)
|
|
->first();
|
|
|
|
if($payment->status == 'PAID')
|
|
{
|
|
$status = 'Selesai';
|
|
}
|
|
else
|
|
{
|
|
$status = 'Belum Selesai';
|
|
}
|
|
$lelongs[$index1]['total'] = $datalelongbidder->sum('hargabida');
|
|
$lelongs[$index1]['status'] = $status;
|
|
$lelongs[$index1]['detail_sag'] = $datalelongbidder;
|
|
}
|
|
return response()->json($lelongs, 201);
|
|
}
|
|
}
|