mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
backend update
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Http\Resources\InvoiceCollection;
|
||||
use App\Http\Resources\UsersCollection;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Http\Resources\UserStorageResource;
|
||||
use App\Http\Resources\UserSubscription;
|
||||
use App\Http\Tools\Demo;
|
||||
use App\Share;
|
||||
use App\User;
|
||||
@@ -67,6 +68,19 @@ class UserController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user subscription details
|
||||
*
|
||||
* @param $id
|
||||
* @return UserSubscription
|
||||
*/
|
||||
public function subscription($id)
|
||||
{
|
||||
return new UserSubscription(
|
||||
User::findOrFail($id)->subscription('main')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users
|
||||
*
|
||||
|
||||
@@ -23,37 +23,9 @@ class AccountController extends Controller
|
||||
/**
|
||||
* Get all user data to frontend
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
// Get User
|
||||
$user = Auth::user();
|
||||
|
||||
// Get folder tree
|
||||
$tree = FileManagerFolder::with(['folders.shared', 'shared:token,id,item_id,permission,protected'])
|
||||
->where('parent_id', 0)
|
||||
->where('user_id', $user->id)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'user' => $user->only(['name', 'email', 'avatar', 'role']),
|
||||
'favourites' => $user->favourite_folders->makeHidden(['pivot']),
|
||||
'tree' => $tree,
|
||||
'storage' => [
|
||||
'used' => Metric::bytes($user->used_capacity)->format(),
|
||||
'capacity' => format_gigabytes($user->settings->storage_capacity),
|
||||
'percentage' => get_storage_fill_percentage($user->used_capacity, $user->settings->storage_capacity),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get me
|
||||
*
|
||||
* @return UserResource
|
||||
*/
|
||||
public function me()
|
||||
public function user()
|
||||
{
|
||||
return new UserResource(
|
||||
Auth::user()
|
||||
|
||||
@@ -26,10 +26,22 @@ class SubscriptionController extends Controller
|
||||
$plan = app('rinvex.subscriptions.plan')
|
||||
->find($request->input('plan.data.id'));
|
||||
|
||||
// Create subscription
|
||||
$user->newSubscription('main', $plan);
|
||||
// Check if user have subscription
|
||||
if ($user->activeSubscriptions()->count() !== 0) {
|
||||
|
||||
// Update user storage limig
|
||||
// Get old subscription
|
||||
$subscription = $user->subscription('main');
|
||||
|
||||
// Change subscription plan
|
||||
$subscription->changePlan($plan);
|
||||
|
||||
} else {
|
||||
|
||||
// Create subscription
|
||||
$user->newSubscription('main', $plan);
|
||||
}
|
||||
|
||||
// Update user storage limit
|
||||
$user->settings()->update([
|
||||
'storage_capacity' => $plan->features->first()->value
|
||||
]);
|
||||
@@ -41,4 +53,20 @@ class SubscriptionController extends Controller
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel Subscription
|
||||
*
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function cancel() {
|
||||
|
||||
// Get user
|
||||
$user = Auth::user();
|
||||
|
||||
// Cancel subscription
|
||||
$user->subscription('main')->cancel();
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ class PricingResource extends JsonResource
|
||||
'description' => $this->description,
|
||||
'price' => $this->price,
|
||||
'capacity_formatted' => format_gigabytes($this->features->first()->value),
|
||||
'capacity' => $this->features->first()->value,
|
||||
'capacity' => (int) $this->features->first()->value,
|
||||
'currency' => 'USD',
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
@@ -33,6 +33,9 @@ class UserResource extends JsonResource
|
||||
]
|
||||
],
|
||||
'relationships' => [
|
||||
'subscription' => $this->activeSubscriptions()->count() !== 0
|
||||
? new UserSubscription($this->subscription('main'))
|
||||
: null,
|
||||
'settings' => [
|
||||
'data' => [
|
||||
'id' => (string)$this->settings->id,
|
||||
@@ -55,7 +58,24 @@ class UserResource extends JsonResource
|
||||
'attributes' => $this->storage
|
||||
]
|
||||
],
|
||||
'subscription' => $this->activeSubscriptions()->count() !== 0 ? new UserSubscription($this->subscription('main')) : null,
|
||||
'favourites' => [
|
||||
'data' => [
|
||||
'id' => '1',
|
||||
'type' => 'folders_favourite',
|
||||
'attributes' => [
|
||||
'folders' => $this->favourite_folders->makeHidden(['pivot'])
|
||||
],
|
||||
],
|
||||
],
|
||||
'tree' => [
|
||||
'data' => [
|
||||
'id' => '1',
|
||||
'type' => 'folders_tree',
|
||||
'attributes' => [
|
||||
'folders' => $this->folder_tree
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -19,10 +19,16 @@ class UserSubscription extends JsonResource
|
||||
'id' => $this->id,
|
||||
'type' => 'subscription',
|
||||
'attributes' => [
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'starts_at' => format_date($this->starts_at, '%d. %B. %Y'),
|
||||
'ends_at' => format_date($this->ends_at, '%d. %B. %Y'),
|
||||
'active' => $this->active(),
|
||||
'canceled' => $this->canceled(),
|
||||
'name' => $this->plan->name,
|
||||
'capacity' => (int) $this->plan->features->first()->value,
|
||||
'capacity_formatted' => format_gigabytes($this->plan->features->first()->value),
|
||||
'slug' => $this->slug,
|
||||
'canceled_at' => format_date($this->created_at, '%d. %B. %Y'),
|
||||
'created_at' => format_date($this->created_at, '%d. %B. %Y'),
|
||||
'starts_at' => format_date($this->starts_at, '%d. %B. %Y'),
|
||||
'ends_at' => format_date($this->ends_at, '%d. %B. %Y'),
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
@@ -21,7 +21,7 @@ function get_invoice_number()
|
||||
$invoices = \App\Invoice::all();
|
||||
|
||||
if ($invoices->isEmpty()) {
|
||||
return Carbon::now()->year . '00001';
|
||||
return Carbon::now()->year . '001';
|
||||
} else {
|
||||
return (int)$invoices->last()->order + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user