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');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user