stage #33
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Controllers\Transactions;
|
||||
|
||||
use App\Enums\PaymentStatusEnum;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Transaction;
|
||||
use App\Traits\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
class MerchantTransactionController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$merchantId = Auth::id();
|
||||
|
||||
$query = Transaction::query()
|
||||
->select([
|
||||
'transactions.id',
|
||||
'transactions.amount',
|
||||
'transactions.currency',
|
||||
'transactions.status_id',
|
||||
'transactions.created_at',
|
||||
|
||||
'payments.id',
|
||||
'payments.payment_method',
|
||||
'payments.paid_amount',
|
||||
'payments.paid_currency',
|
||||
'payments.paid_at',
|
||||
'payments.status_name as payment_status',
|
||||
'payments.status_id as payment_status_id',
|
||||
'payments.verified_at',
|
||||
'payments.refunded_at',
|
||||
'payments.refund_reason',
|
||||
'payments.track_id',
|
||||
|
||||
'user_gateways.name',
|
||||
])
|
||||
->join(
|
||||
'payments',
|
||||
'payments.id',
|
||||
'=',
|
||||
'transactions.payment_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'user_gateways',
|
||||
'user_gateways.id',
|
||||
'=',
|
||||
'transactions.user_gateway_id'
|
||||
)
|
||||
->where('transactions.user_id', $merchantId);
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedSelects: ['payments.id as payment_id', 'payments.track_id', 'payments.status_id as payment_status_id',
|
||||
'payments.status_name as payment_status',
|
||||
'payment_method', 'paid_amount', 'paid_currency', 'paid_at', 'payment_track_id',
|
||||
'transactions.amount',
|
||||
'transactions.currency',
|
||||
'user_gateways.name as gateway_name',
|
||||
'payments.verified_at',
|
||||
'payments.refunded_at',
|
||||
'payments.refund_reason',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function stats(): JsonResponse
|
||||
{
|
||||
$merchantId = Auth::id();
|
||||
|
||||
$data = [
|
||||
'total_transactions' => Payment::query()->where(
|
||||
'user_id',
|
||||
$merchantId
|
||||
)->count(),
|
||||
|
||||
'successful_transactions' => Payment::query()->where(
|
||||
'user_id',
|
||||
$merchantId
|
||||
)
|
||||
->where('status_id', PaymentStatusEnum::PAID->value)
|
||||
->count(),
|
||||
|
||||
'failed_transactions' => Payment::query()->where(
|
||||
'user_id',
|
||||
$merchantId
|
||||
)
|
||||
->whereIn('status_id', [
|
||||
PaymentStatusEnum::Cancelled->value,
|
||||
PaymentStatusEnum::Expired->value
|
||||
])
|
||||
->count(),
|
||||
|
||||
'total_paid_amount' => Payment::query()
|
||||
->where('user_id', $merchantId)
|
||||
->where(
|
||||
'status_id',
|
||||
PaymentStatusEnum::PendingVerification->value
|
||||
)
|
||||
->selectRaw('SUM(CAST(paid_amount AS DECIMAL(20,2))) as total')
|
||||
->value('total'),
|
||||
];
|
||||
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Admin\Controllers\PermissionManagementController;
|
||||
use App\Admin\Controllers\ProfileController;
|
||||
use App\Admin\Controllers\RoleManagementController;
|
||||
use App\Admin\Controllers\UserManagementController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('auth')
|
||||
->name('auth.')
|
||||
@@ -14,7 +15,7 @@ Route::prefix('auth')
|
||||
->group(function () {
|
||||
Route::post('login', 'login')->name('login');
|
||||
Route::post('logout', 'logout')->name('logout');
|
||||
});
|
||||
});
|
||||
|
||||
Route::prefix('documents')
|
||||
->name('documents.')
|
||||
@@ -33,10 +34,10 @@ Route::prefix('user_management')
|
||||
->controller(UserManagementController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::get('/{user}', 'show')->name('show');
|
||||
Route::post('/{user}', 'update')->name('update');
|
||||
Route::delete('/{user}', 'destroy')->name('destroy');
|
||||
Route::post('/store', 'store')->name('store');
|
||||
Route::get('{user}', 'show')->name('show');
|
||||
Route::post('/update/{user}', 'update')->name('update');
|
||||
Route::delete('/delete/{user}', 'destroy')->name('destroy');
|
||||
});
|
||||
|
||||
Route::prefix('roles')
|
||||
@@ -45,10 +46,10 @@ Route::prefix('roles')
|
||||
->controller(RoleManagementController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::get('/{role}', 'show')->name('show');
|
||||
Route::post('/{role}', 'update')->name('update');
|
||||
Route::delete('/{role}', 'destroy')->name('destroy');
|
||||
Route::post('/store', 'store')->name('store');
|
||||
Route::get('{role}', 'show')->name('show');
|
||||
Route::post('/update/{role}', 'update')->name('update');
|
||||
Route::delete('/delete/{role}', 'destroy')->name('destroy');
|
||||
});
|
||||
|
||||
Route::prefix('permissions')
|
||||
@@ -57,22 +58,22 @@ Route::prefix('permissions')
|
||||
->controller(PermissionManagementController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::get('/{permission}', 'show')->name('show');
|
||||
Route::post('/{permission}', 'update')->name('update');
|
||||
Route::delete('/{permission}', 'destroy')->name('destroy');
|
||||
Route::post('/store', 'store')->name('store');
|
||||
Route::get('{permission}', 'show')->name('show');
|
||||
Route::post('/update/{permission}', 'update')->name('update');
|
||||
Route::delete('/delete/{permission}', 'destroy')->name('destroy');
|
||||
});
|
||||
|
||||
Route::prefix('expert')
|
||||
Route::prefix('expert_manage')
|
||||
->name('expert.')
|
||||
->middleware(['auth:expert', 'permission:expert-management'])
|
||||
->controller(ExpertManagementController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::get('/{expert}', 'show')->name('show');
|
||||
Route::post('/{expert}', 'update')->name('update');
|
||||
Route::delete('/{expert}', 'destroy')->name('destroy');
|
||||
Route::post('/stores', 'store')->name('store');
|
||||
Route::get('{expert}', 'show')->name('show');
|
||||
Route::post('/update/{expert}', 'update')->name('update');
|
||||
Route::delete('/delete/{expert}', 'destroy')->name('destroy');
|
||||
});
|
||||
|
||||
Route::prefix('profile')
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
<?php
|
||||
|
||||
use App\Admin\Controllers\ExpertManagementController;
|
||||
use App\Admin\Controllers\PermissionManagementController;
|
||||
use App\Admin\Controllers\RoleManagementController;
|
||||
use App\Admin\Controllers\UserManagementController;
|
||||
|
||||
use App\User\Controllers\AuthController;
|
||||
use App\User\Controllers\GatewayManagementController;
|
||||
use App\User\Controllers\CityController;
|
||||
use App\User\Controllers\ProfileController;
|
||||
use App\User\Controllers\ProvinceController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\User\Controllers\Transactions\MerchantTransactionController;
|
||||
|
||||
Route::prefix('auth')
|
||||
->name('Auth.')
|
||||
@@ -55,3 +53,13 @@ Route::prefix('city')
|
||||
->group(function () {
|
||||
Route::get('list', 'list')->name('list');
|
||||
});
|
||||
|
||||
|
||||
Route::prefix('merchant')->group(function () {
|
||||
Route::prefix('transactions')
|
||||
->middleware(['auth'])
|
||||
->group(function () {
|
||||
Route::get('/list', [MerchantTransactionController::class, 'index'])->name('index');
|
||||
Route::get('/stats', [MerchantTransactionController::class, 'stats'])->name('stats');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user