update
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@@ -12,9 +13,11 @@ use App\Models\Lelong;
|
||||
use App\Models\Payment;
|
||||
use App\Models\LelongBid;
|
||||
use App\Models\LelongBidder;
|
||||
use App\Models\Resit;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
public function senarailelongan(){
|
||||
|
||||
$user = Auth::user();
|
||||
@@ -72,10 +75,87 @@ class AccountController extends Controller
|
||||
public function sahsagonline($lelong_id, $user_id){
|
||||
|
||||
$senaraisag = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
||||
->join('payment', 'lelongbid.id', '=', 'payment.lelongbid_id')
|
||||
->where('lelongbid.lelong_id', $lelong_id)
|
||||
->where('lelongbidder.user_id', $user_id)
|
||||
->where('lelongbidder.status_bidder', 1)
|
||||
->where('payment.status_payment_opt', 2)
|
||||
->get()->toArray();
|
||||
|
||||
// dd($senaraisag);
|
||||
|
||||
$total_payment = 0;
|
||||
foreach($senaraisag as $index1=>$sagbid){
|
||||
|
||||
if($sagbid['total_payment']){
|
||||
$total_payment = $total_payment +$sagbid['total_payment'];
|
||||
}
|
||||
|
||||
// $senaraisag[$index1]['totalPay'] = $total_payment;
|
||||
}
|
||||
// dd($senaraisag);
|
||||
return view('account.sahsagonline', compact('senaraisag', 'user_id', 'lelong_id','total_payment'));
|
||||
}
|
||||
|
||||
public function sahbayaronline($lelong_id, $user_id){
|
||||
|
||||
$currentdate = Carbon::now();
|
||||
$currentdate = $currentdate->toDateTimeString();
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
$senaraisag = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
||||
->join('payment', 'lelongbid.id', '=', 'payment.lelongbid_id')
|
||||
->where('lelongbid.lelong_id', $lelong_id)
|
||||
->where('lelongbidder.user_id', $user_id)
|
||||
->where('lelongbidder.status_bidder', 1)
|
||||
->where('payment.status_payment_opt', 2)
|
||||
->get();
|
||||
|
||||
return view('account.sahsagonline', compact('senaraisag', 'user_id', 'lelong_id'));
|
||||
$total_payment = 0;
|
||||
foreach($senaraisag as $sag)
|
||||
{
|
||||
$payment = Payment::where('lelong_id', $lelong_id)
|
||||
->where('user_id', $user_id)
|
||||
->where('lelongbid_id',$sag->lelongbid_id)
|
||||
->first();
|
||||
$payment->disahkan_oleh = $user->id;
|
||||
$payment->disahkan_pada = $currentdate;
|
||||
$payment->save();
|
||||
|
||||
$total_payment = $total_payment + $payment->total_payment;
|
||||
|
||||
$updatelelbidbidder = LelongBidder::where('lelongbid_id', $sag->lelongbid_id)
|
||||
->first();
|
||||
$updatelelbidbidder->status_payment = 1;
|
||||
$updatelelbidbidder->save();
|
||||
|
||||
$eachbid = LelongBid::where('id',$sag->lelongbid_id)->first();
|
||||
$eachbid->status_jual = 1;
|
||||
$eachbid->t_jual = $currentdate;
|
||||
$eachbid->save();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$senaraisagallpayment = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
||||
->where('lelongbid.lelong_id', $lelong_id)
|
||||
->where('lelongbidder.user_id', $user_id)
|
||||
->where('lelongbidder.status_bidder', 1)
|
||||
->get();
|
||||
// dd($senaraisagallpayment);
|
||||
$resit = Resit::where('id',$payment->resit_id)->first();
|
||||
$resit->total_payment = $resit->total_payment + $total_payment;
|
||||
|
||||
if($resit->total_payment >= $senaraisagallpayment->sum('hargabida'))
|
||||
{
|
||||
$resit->status = 'PAID';
|
||||
$resit->paid_at = $currentdate;
|
||||
}
|
||||
$resit->save();
|
||||
|
||||
return redirect()->route('account.senarailelongan')->with('success','Pembayaran Berjaya');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,11 +448,13 @@ class LelongController extends Controller
|
||||
$lelongbid = LelongBid::where('lelong_id','=',$id)->get();
|
||||
foreach($lelongbid as $bid)
|
||||
{
|
||||
$highestprice = LelongBidder::where('lelongbid_id','=',$bid->id)->orderByRaw('lelongbidder.hargabida DESC' )->get();
|
||||
$highestprice = LelongBidder::where('lelongbid_id','=',139)->orderBy('lelongbidder.hargabida','DESC' )->first();
|
||||
// dd($highestprice->hargabida);
|
||||
if($highestprice)
|
||||
{
|
||||
foreach($highestprice as $price){
|
||||
$bidders = LelongBidder::where('hargabida','=',$price->hargabida)->MIN('lelongbidder.masa_bidaan' )->get();
|
||||
// foreach($highestprice as $price){
|
||||
$bidders = LelongBidder::where('lelongbid_id','=',139)->where('hargabida','=',$highestprice->hargabida)->orderBy('masa_bidaan','ASC' )->get();
|
||||
// dd($bidders);
|
||||
$count = 0;
|
||||
foreach($bidders as $bidder)
|
||||
{
|
||||
@@ -460,11 +462,12 @@ class LelongController extends Controller
|
||||
if($count == 1)
|
||||
{
|
||||
$pemenang = LelongBidder::where('id','=',$bidder->id)
|
||||
->first();
|
||||
->first();
|
||||
$pemenang->status_bidder = 1;
|
||||
$pemenang->save();
|
||||
|
||||
|
||||
$updatebid = LelongBid::where('id','=',$bid->id)->first();
|
||||
// dd($updatebid);
|
||||
$updatebid->hargajual = $bidder->hargabida;
|
||||
$updatebid->nopembeli = $bidder->user_id;
|
||||
$updatebid->status_jual = 1;
|
||||
@@ -501,7 +504,7 @@ class LelongController extends Controller
|
||||
$kalah->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
@@ -87,25 +87,22 @@ class PaymentController extends Controller
|
||||
'users.alamat'
|
||||
)
|
||||
->first();
|
||||
|
||||
// foreach($SAGBidItem as $eachbid){
|
||||
|
||||
$eachbid = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
||||
->join('users', 'lelongbidder.user_id', '=', 'users.id')
|
||||
->where('lelongbidder.status_bidder', 1)
|
||||
->where('users.id', $user_id)
|
||||
->where('lelongbid.lelong_id', $lelong_id)
|
||||
->select('lelongbidder.hargabida',
|
||||
'lelongbid.hargaasas',
|
||||
'lelongbid.norujukan',
|
||||
'lelongbidder.lelongbid_id',
|
||||
'lelongbidder.status_payment'
|
||||
)
|
||||
->get();
|
||||
$eachbid = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
||||
->join('users', 'lelongbidder.user_id', '=', 'users.id')
|
||||
->where('lelongbidder.status_bidder', 1)
|
||||
->where('users.id', $user_id)
|
||||
->where('lelongbid.lelong_id', $lelong_id)
|
||||
->select('lelongbidder.hargabida',
|
||||
'lelongbid.hargaasas',
|
||||
'lelongbid.norujukan',
|
||||
'lelongbidder.lelongbid_id',
|
||||
'lelongbidder.status_payment'
|
||||
)
|
||||
->get();
|
||||
|
||||
// }
|
||||
|
||||
return view('pembayaran.SAGBidItem',compact('SAGBidItem', 'eachbid', 'lelong_id'));
|
||||
return view('pembayaran.SAGBidItem',compact('SAGBidItem', 'eachbid', 'lelong_id','user_id'));
|
||||
}
|
||||
|
||||
public function paymentdenokaunter(Request $request){
|
||||
@@ -119,6 +116,7 @@ class PaymentController extends Controller
|
||||
$bid_id = explode(",", $request->eachbid);
|
||||
|
||||
$resit = Resit::where('lelong_id', $request->lelong_id)
|
||||
->where('user_id',$request->user_id)
|
||||
->first();
|
||||
|
||||
$total_hargabida = 0;
|
||||
@@ -135,8 +133,9 @@ class PaymentController extends Controller
|
||||
'lelongbid.lelong_id as lelong_id'
|
||||
)
|
||||
->first();
|
||||
|
||||
|
||||
$total_hargabida = $total_hargabida + $eachbid->hargabida;
|
||||
// dd($total_hargabida);
|
||||
$payment = Payment::create([
|
||||
'user_id' => $request->user_id,
|
||||
'lelongbidder_id' => $eachbid->lelongbidder_id,
|
||||
@@ -166,18 +165,29 @@ class PaymentController extends Controller
|
||||
$updatelelbidbidder = LelongBidder::where('lelongbid_id', $eachbid->lelongbid_id)
|
||||
->first();
|
||||
$updatelelbidbidder->status_payment = 1;
|
||||
$updatelelbidbidder->update();
|
||||
$updatelelbidbidder->save();
|
||||
|
||||
$eachbid->status_jual = 1;
|
||||
$eachbid->t_jual = $currentdate;
|
||||
$eachbid->update();
|
||||
$eachbidupdate = LelongBid::where('id',$bid)->first();
|
||||
$eachbidupdate->status_jual = 1;
|
||||
$eachbidupdate->t_jual = $currentdate;
|
||||
$eachbidupdate->save();
|
||||
|
||||
}
|
||||
if($request->amaunkiraan == $total_hargabida){
|
||||
$resit->total_payment = $total_hargabida;
|
||||
$resit->status = 'PAID';
|
||||
$resit->paid_at = $currentdate;
|
||||
$resit->update();
|
||||
$senaraisagallpayment = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
||||
->where('lelongbid.lelong_id', $request->lelong_id)
|
||||
->where('lelongbidder.user_id', $request->user_id)
|
||||
->where('lelongbidder.status_bidder', 1)
|
||||
->get();
|
||||
// dd(floatval($request->amaunkiraan));
|
||||
if(floatval($request->amaunkiraan) == $total_hargabida){
|
||||
// dd('hye');
|
||||
$resit->total_payment = $resit->total_payment + $total_hargabida;
|
||||
if($resit->total_payment >= $senaraisagallpayment->sum('hargabida'))
|
||||
{
|
||||
$resit->status = 'PAID'; // $resit->status = 'PAID'; when hargabida >= total_payment di resit
|
||||
$resit->paid_at = $currentdate;
|
||||
}
|
||||
$resit->save();
|
||||
}
|
||||
return redirect()->route('pembayaran.SenaraiLelongBayar')->with('success','Pembayaran Berjaya');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user