tambah function semakan billplz
This commit is contained in:
@@ -39,6 +39,7 @@ use Billplz\Client;
|
||||
use Http\Client\Common\HttpMethodsClient;
|
||||
use Http\Adapter\Guzzle7\Client as GuzzleHttpClient;
|
||||
use Http\Message\MessageFactory\GuzzleMessageFactory;
|
||||
use App\Models\LogUser;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
@@ -644,5 +645,66 @@ class ApiController extends Controller
|
||||
return view('pembida.feePaymentResult', compact('data', 'result', 'success'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// BillplzService.php atau ApiController.php
|
||||
public function processPaidResit(array $data)
|
||||
{
|
||||
$currentdate = Carbon::now();
|
||||
$currentdate = $currentdate->toDateTimeString();
|
||||
$loguser = new LogUser;
|
||||
$loguser->user_id = User::where('name','System')->first()->id;
|
||||
$loguser->date = $currentdate;
|
||||
$loguser->username = 'System';
|
||||
$loguser->nama_user = 'System';
|
||||
$loguser->norujukan = $data['billplz']['id'];
|
||||
$loguser->nota = 'Callback Resit Billplz Telah Bayar : Billplz_id -'.$data['billplz']['id'];
|
||||
$loguser->save();
|
||||
|
||||
$resit = Resit::where('billplz_id', '=', $data['billplz']['id'])->first();
|
||||
|
||||
if (!$resit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$resit->status = 'PAID';
|
||||
$resit->paid_at = $data['billplz']['paid_at'];
|
||||
$resit->save();
|
||||
|
||||
$resitoriginal = Resit::where('user_id', $resit->user_id)
|
||||
->where('lelong_id', $resit->lelong_id)
|
||||
->where('resit_type', 2)
|
||||
->first();
|
||||
|
||||
$payment = Payment::where('lelong_id', $resit->lelong_id)
|
||||
->where('user_id', $resit->user_id)
|
||||
->where('resit_id', $resit->id)
|
||||
->get();
|
||||
|
||||
foreach ($payment as $index) {
|
||||
$index->status = 2;
|
||||
$index->remark = "BERJAYA BAYARAN ONLINE";
|
||||
$index->update();
|
||||
|
||||
$updateTagBid = LelongBid::where('norujukan', $index->norujukan)->first();
|
||||
if ($updateTagBid) {
|
||||
$updateTagBid->status_payment = 2;
|
||||
$updateTagBid->save();
|
||||
|
||||
$updateTagBidder = LelongBidder::where('lelongbid_id', $updateTagBid->id)
|
||||
->where('user_id', $resit->user_id)->first();
|
||||
if ($updateTagBidder) {
|
||||
$updateTagBidder->status_payment = 2;
|
||||
$updateTagBidder->payment_id = $index->id;
|
||||
$updateTagBidder->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event(new PaymentNotify('PAID', $resit->user_id, $payment));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,19 +24,26 @@ use App\Models\Invoice;
|
||||
use App\Models\ScanJual;
|
||||
use App\Services\ResitPhotoService;
|
||||
use Symfony\Component\Console\Descriptor\Descriptor;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\BillplzService;
|
||||
use App\Http\Controllers\ApiController;
|
||||
|
||||
|
||||
class PembidaController extends Controller
|
||||
{
|
||||
private $resitPhotoService;
|
||||
protected $billplzService;
|
||||
protected $ResitSemakanService;
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ResitPhotoService $resitPhotoService)
|
||||
public function __construct(ResitPhotoService $resitPhotoService,BillplzService $billplzService)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->resitPhotoService = $resitPhotoService;
|
||||
$this->billplzService = $billplzService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1371,5 +1378,166 @@ class PembidaController extends Controller
|
||||
//return view('pembida.statusserahanbypembida',compact('listwinner','lelong','arrayinfo','cawanganbidder'));
|
||||
return view('pembida.statusserahanbypembida',compact('arraysms','arraysls','listwinner','lelong','cawanganbidder'));
|
||||
}
|
||||
|
||||
public function semakanBillplz(Request $request, BillplzService $billplzService)
|
||||
{
|
||||
$date = $request->input('date') ?? now()->toDateString();
|
||||
|
||||
try {
|
||||
$dateObj = Carbon::createFromFormat('Y-m-d', $date);
|
||||
} catch (\Exception $e) {
|
||||
return back()->with('error', 'Tarikh tidak sah. Guna format YYYY-MM-DD.');
|
||||
}
|
||||
|
||||
$date = $dateObj->toDateString();
|
||||
|
||||
$allPendingResits = DB::table('resit as r')
|
||||
->join('payment as p', 'p.resit_id', '=', 'r.id')
|
||||
->join(DB::raw('(
|
||||
SELECT user_id, total_payment, MIN(id) AS min_id
|
||||
FROM payment
|
||||
GROUP BY user_id, total_payment
|
||||
) as unique_payment'), 'p.id', '=', 'unique_payment.min_id')
|
||||
->join('users as u', 'p.user_id', '=', 'u.id')
|
||||
->join('cawangan as c', 'p.kodcaw', '=', 'c.caw_code') // JOIN ikut kodcaw
|
||||
// Elakkan resit yang ada CDM payment pada hari yang sama
|
||||
->whereNotExists(function ($query) use ($date) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('resit as r2')
|
||||
->join('payment as p2', 'p2.resit_id', '=', 'r2.id')
|
||||
->whereRaw('p2.user_id = p.user_id')
|
||||
->whereRaw('p2.total_payment = p.total_payment')
|
||||
->whereDate('r2.created_at', $date)
|
||||
->where('r2.billplz_id', 'LIKE', '%CDM%');
|
||||
})
|
||||
->whereNull('r.status')
|
||||
->where('p.status', 0)
|
||||
->whereNotNull('r.billplz_id')
|
||||
->where('r.billplz_id', 'NOT LIKE', '%CDM%')
|
||||
->whereDate('r.created_at', $date)
|
||||
->select(
|
||||
'r.*',
|
||||
'p.id as payment_id',
|
||||
'p.total_payment',
|
||||
'p.user_id',
|
||||
'u.name as payer_name',
|
||||
'c.caw_name as cawangan_nama' // Tambah nama cawangan
|
||||
)
|
||||
->distinct()
|
||||
->get();
|
||||
|
||||
// Kumpul mengikut billplz_id dan user_id
|
||||
$groupedResitsUnpaid = $allPendingResits
|
||||
->groupBy('billplz_id') // Group mengikut billplz_id
|
||||
->map(function ($items) {
|
||||
return (object) [
|
||||
'billplz_id' => $items->first()->billplz_id,
|
||||
'jumlah_bayaran' => $items->sum('total_payment'),
|
||||
'payer_name' => $items->first()->payer_name,
|
||||
'cawangan_nama' => $items->first()->cawangan_nama,
|
||||
'resit_id' => $items->first()->id,
|
||||
'created_at' => $items->first()->created_at,
|
||||
'user_id' => $items->first()->user_id,
|
||||
];
|
||||
})
|
||||
->values(); // Reset index
|
||||
|
||||
|
||||
$billplzWithCdmResits = DB::table('resit as r')
|
||||
->join('payment as p', 'p.resit_id', '=', 'r.id')
|
||||
->join(DB::raw('(
|
||||
SELECT user_id, total_payment, MIN(id) AS min_id
|
||||
FROM payment
|
||||
GROUP BY user_id, total_payment
|
||||
) as unique_payment'), 'p.id', '=', 'unique_payment.min_id')
|
||||
->join('users as u', 'p.user_id', '=', 'u.id')
|
||||
->join('cawangan as c', 'p.kodcaw', '=', 'c.caw_code')
|
||||
->whereNull('r.status')
|
||||
->where('p.status', 0)
|
||||
->whereNotNull('r.billplz_id')
|
||||
->where('r.billplz_id', 'NOT LIKE', '%CDM%')
|
||||
->whereDate('r.created_at', $date)
|
||||
->whereExists(function ($query) use ($date) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('resit as r2')
|
||||
->join('payment as p2', 'p2.resit_id', '=', 'r2.id')
|
||||
->join('users as u2', 'p2.user_id', '=', 'u2.id')
|
||||
->whereRaw('u2.name = u.name') // banding nama
|
||||
->whereRaw('p2.total_payment = p.total_payment') // dan jumlah
|
||||
->whereDate('r2.created_at', $date)
|
||||
->where('r2.billplz_id', 'LIKE', '%CDM%');
|
||||
})
|
||||
->select('r.*', 'p.id as payment_id', 'p.total_payment', 'u.name as payer_name', 'c.caw_name as cawangan_nama')
|
||||
->distinct()
|
||||
->get();
|
||||
|
||||
$groupedResits = $billplzWithCdmResits
|
||||
->groupBy('billplz_id')
|
||||
->map(function ($items) {
|
||||
return (object) [
|
||||
'billplz_id' => $items->first()->billplz_id,
|
||||
'jumlah_bayaran' => $items->sum('total_payment'),
|
||||
'payer_name' => $items->first()->payer_name,
|
||||
'cawangan_nama' => $items->first()->cawangan_nama,
|
||||
'resit_id' => $items->first()->id,
|
||||
'created_at' => $items->first()->created_at,
|
||||
'user_id' => $items->first()->user_id,
|
||||
];
|
||||
})->values();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Semak status Billplz untuk setiap resit
|
||||
$paidResits = collect();
|
||||
$unpaidResits = collect();
|
||||
$processingResits = collect();
|
||||
|
||||
foreach ($allPendingResits as $resit) {
|
||||
$billData = $billplzService->testGetBill($resit->billplz_id);
|
||||
|
||||
$isPaid = isset($billData['paid']) && $billData['paid'] === true;
|
||||
$isProcessing = isset($billData['state']) && in_array($billData['state'], ['pending', 'processing']) && isset($billData['paid_at']);
|
||||
|
||||
if ($isPaid) {
|
||||
$resit->paid_at = $billData['paid_at'] ?? now();
|
||||
$paidResits->push($resit);
|
||||
} elseif ($isProcessing) {
|
||||
$resit->paid_at = $billData['paid_at'];
|
||||
$resit->state = $billData['state'];
|
||||
$processingResits->push($resit);
|
||||
} else {
|
||||
$unpaidResits->push($resit);
|
||||
}
|
||||
}
|
||||
|
||||
return view('pembida.semakanbillplz', compact(
|
||||
'paidResits',
|
||||
'unpaidResits',
|
||||
'billplzWithCdmResits',
|
||||
'processingResits',
|
||||
'groupedResits',
|
||||
'groupedResitsUnpaid',
|
||||
'date'
|
||||
));
|
||||
}
|
||||
|
||||
public function prosesBillplz(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'billplz' => [
|
||||
'id' => $request->billplz_id,
|
||||
'paid' => 'true',
|
||||
'paid_at' => $request->paid_at ?? now()->toDateTimeString(),
|
||||
]
|
||||
];
|
||||
|
||||
$apiController = app(ApiController::class);
|
||||
$apiController->processPaidResit($data);
|
||||
|
||||
return redirect()->back()->with('success', 'Resit telah diproses.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user