feat: implement system-wide activity logging with database persistence, repository patterns, and admin controller access.
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Log;
|
||||
use App\Models\Transaction;
|
||||
use App\Services\ActivityLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -20,10 +21,12 @@ use Illuminate\Support\Str;
|
||||
class TransactionController extends Controller
|
||||
{
|
||||
protected VNPayService $vnpayService;
|
||||
protected ActivityLogger $activityLogger;
|
||||
|
||||
public function __construct(VNPayService $vnpayService)
|
||||
public function __construct(VNPayService $vnpayService, ActivityLogger $activityLogger)
|
||||
{
|
||||
$this->vnpayService = $vnpayService;
|
||||
$this->activityLogger = $activityLogger;
|
||||
}
|
||||
|
||||
public function handle(DepositRequest $request)
|
||||
@@ -48,6 +51,14 @@ class TransactionController extends Controller
|
||||
'transaction_uuid' => $uuid,
|
||||
]);
|
||||
|
||||
$this->activityLogger->log(
|
||||
event: 'deposit_vnpay',
|
||||
logName: 'Transaction',
|
||||
description: "Customer {$user->email} tạo yêu cầu nạp tiền VNPay: " . number_format($request->amount) . ' VNĐ - Mã: ' . $publicCode,
|
||||
subject: $transaction,
|
||||
newValues: ['public_code' => $publicCode, 'amount' => $request->amount, 'type' => 'vnpay'],
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Tạo yêu cầu nạp tiền thành công',
|
||||
@@ -151,6 +162,14 @@ class TransactionController extends Controller
|
||||
'customer_id' => $transaction->customer_id,
|
||||
]);
|
||||
|
||||
$this->activityLogger->log(
|
||||
event: 'deposit_success',
|
||||
logName: 'Transaction',
|
||||
description: "Customer {$customer->email} nạp tiền VNPay thành công: " . number_format($transaction->amount) . ' VNĐ - Mã: ' . $transaction->public_code,
|
||||
subject: $transaction,
|
||||
newValues: ['amount' => $transaction->amount, 'new_total' => $customer->total, 'public_code' => $transaction->public_code],
|
||||
);
|
||||
|
||||
DepositSuccessJob::dispatch([
|
||||
'customer_email' => $customer->email,
|
||||
'customer_name' => $customer->fullname,
|
||||
|
||||
Reference in New Issue
Block a user