From b37ece7d83a28359b4450910bdc9940ff6482106 Mon Sep 17 00:00:00 2001 From: Immanuel Onyeka Date: Wed, 2 Jun 2021 10:16:31 -0400 Subject: [PATCH] Add transaction page transitioning --- .../Controllers/TransactionController.php | 9 ++ .../2014_10_12_000000_create_users_table.php | 2 +- resources/js/panel/credits.vue | 3 + resources/js/panel/orders.vue | 2 +- resources/js/panel/panel.vue | 7 +- resources/js/panel/services.vue | 100 +++++++++++++----- resources/js/panel/sidebar.vue | 2 +- resources/scss/main.scss | 11 +- 8 files changed, 100 insertions(+), 36 deletions(-) create mode 100644 resources/js/panel/credits.vue diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 582e790..c66f950 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -12,13 +12,22 @@ class TransactionController extends Controller { //THis should also reduce user's available credits public function newOrder(Request $request) { + $user = Auth::user(); $order = new Order; + $order->service_id = $request->service; $order->user_id = Auth::user()->id; $order->quantity = $request->quantity; $order->url = $request->url; $order->note = $request->note ?: ''; $order->status = 'processing'; + + $cost = ceil($order->quantity*$order->service->price/1000); + $user->credits = $user->credits - $cost; + if ($cost > $user->credits) { + abort(520, 'Insufficient Credits'); + } + $user->save(); $order->save(); } } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 045d00e..a234e76 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -21,7 +21,7 @@ class CreateUsersTable extends Migration $table->string('password'); $table->string('role'); $table->boolean('active')->default(true); - $table->bigInteger('credits')->default(0); + $table->unsignedBigInteger('credits')->default(0); $table->rememberToken(); $table->timestamps(); }); diff --git a/resources/js/panel/credits.vue b/resources/js/panel/credits.vue new file mode 100644 index 0000000..9ffb918 --- /dev/null +++ b/resources/js/panel/credits.vue @@ -0,0 +1,3 @@ + diff --git a/resources/js/panel/orders.vue b/resources/js/panel/orders.vue index f5ca992..a0f19b4 100644 --- a/resources/js/panel/orders.vue +++ b/resources/js/panel/orders.vue @@ -1,7 +1,7 @@