mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
Balance & Estimates backend implementation
This commit is contained in:
@@ -206,6 +206,14 @@ return [
|
||||
'max_storage_amount' => '{value} GB Storage Size',
|
||||
'interval.month' => 'Monthly',
|
||||
'interval.year' => 'Yearly',
|
||||
|
||||
// v2
|
||||
'bandwidth' => 'Bandwidth',
|
||||
'storage' => 'Storage',
|
||||
'feature_usage_desc_bandwidth' => 'Data amount you transferred to/from your account.',
|
||||
'feature_usage_desc_storage' => 'Total storage amount you are using.',
|
||||
'feature_usage_desc_members' => 'Total members you invited to your team folders.',
|
||||
'feature_usage_desc_platform' => 'Total storage amount you are using.',
|
||||
],
|
||||
'regular' => [
|
||||
'actions.close' => 'Close',
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~97130d1f.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~97130d1f.js?id=e2d818009a4e2c1fffdf",
|
||||
"/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~1bec6fe4.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~1bec6fe4.js?id=510e6c1b1017a73a40a6",
|
||||
"/chunks/admin~chunks/platform.js": "/chunks/admin~chunks/platform.js?id=917aab9de16d3eb7039a",
|
||||
"/chunks/admin~chunks/platform~chunks/settings.js": "/chunks/admin~chunks/platform~chunks/settings.js?id=aa33127e176333acfb68",
|
||||
"/chunks/admin~chunks/platform~chunks/settings.js": "/chunks/admin~chunks/platform~chunks/settings.js?id=5655107fc94a22804c92",
|
||||
"/chunks/admin~chunks/platform~chunks/settings~chunks/shared.js": "/chunks/admin~chunks/platform~chunks/settings~chunks/shared.js?id=8e89d2271b17b2d78177",
|
||||
"/chunks/admin~chunks/platform~chunks/shared.js": "/chunks/admin~chunks/platform~chunks/shared.js?id=0d6c4be667e46ea1303e",
|
||||
"/chunks/app-appearance.js": "/chunks/app-appearance.js?id=6035ca411b2c4239d964",
|
||||
@@ -74,7 +74,7 @@
|
||||
"/chunks/settings-payment-methods.js": "/chunks/settings-payment-methods.js?id=093cc2fd918ee6a340d3",
|
||||
"/chunks/settings-storage.js": "/chunks/settings-storage.js?id=75172fe522988795ec59",
|
||||
"/chunks/settings-storage~chunks/settings-subscription~chunks/user-storage~chunks/user-subscription.js": "/chunks/settings-storage~chunks/settings-subscription~chunks/user-storage~chunks/user-subscription.js?id=147afaac8c8bacfe6433",
|
||||
"/chunks/settings-subscription.js": "/chunks/settings-subscription.js?id=1c39345122bbf945f055",
|
||||
"/chunks/settings-subscription.js": "/chunks/settings-subscription.js?id=241cee35aba1f607aa40",
|
||||
"/chunks/settings~chunks/settings-password.js": "/chunks/settings~chunks/settings-password.js?id=c33cd2341b9b04a732e5",
|
||||
"/chunks/setup-wizard.js": "/chunks/setup-wizard.js?id=651d5accf401908724c5",
|
||||
"/chunks/shared.js": "/chunks/shared.js?id=6230d050545cd1bd9b87",
|
||||
@@ -1252,5 +1252,24 @@
|
||||
"/chunks/settings-storage.025677c7d6044c82014b.hot-update.js": "/chunks/settings-storage.025677c7d6044c82014b.hot-update.js",
|
||||
"/chunks/user-storage.025677c7d6044c82014b.hot-update.js": "/chunks/user-storage.025677c7d6044c82014b.hot-update.js",
|
||||
"/chunks/settings-storage.0c4a306e871a6a932496.hot-update.js": "/chunks/settings-storage.0c4a306e871a6a932496.hot-update.js",
|
||||
"/chunks/user-storage.0c4a306e871a6a932496.hot-update.js": "/chunks/user-storage.0c4a306e871a6a932496.hot-update.js"
|
||||
"/chunks/user-storage.0c4a306e871a6a932496.hot-update.js": "/chunks/user-storage.0c4a306e871a6a932496.hot-update.js",
|
||||
"/chunks/settings-subscription.d40760eb7049bef93d7e.hot-update.js": "/chunks/settings-subscription.d40760eb7049bef93d7e.hot-update.js",
|
||||
"/chunks/settings-subscription.c57f7330793a42f04e26.hot-update.js": "/chunks/settings-subscription.c57f7330793a42f04e26.hot-update.js",
|
||||
"/chunks/settings-subscription.1dfcb7180c795fc18b9e.hot-update.js": "/chunks/settings-subscription.1dfcb7180c795fc18b9e.hot-update.js",
|
||||
"/chunks/settings-subscription.8eceac76d14a52446e90.hot-update.js": "/chunks/settings-subscription.8eceac76d14a52446e90.hot-update.js",
|
||||
"/chunks/settings-subscription.92639fee50d12724e676.hot-update.js": "/chunks/settings-subscription.92639fee50d12724e676.hot-update.js",
|
||||
"/chunks/settings-subscription.5324fdd1d5433235a1ef.hot-update.js": "/chunks/settings-subscription.5324fdd1d5433235a1ef.hot-update.js",
|
||||
"/chunks/settings-subscription.473b0f898629fdef27fe.hot-update.js": "/chunks/settings-subscription.473b0f898629fdef27fe.hot-update.js",
|
||||
"/chunks/settings-subscription.59aa7636dafb82d26628.hot-update.js": "/chunks/settings-subscription.59aa7636dafb82d26628.hot-update.js",
|
||||
"/chunks/settings-subscription.a89225a0f90622376f5c.hot-update.js": "/chunks/settings-subscription.a89225a0f90622376f5c.hot-update.js",
|
||||
"/chunks/settings-subscription.7b392c700f13f047a226.hot-update.js": "/chunks/settings-subscription.7b392c700f13f047a226.hot-update.js",
|
||||
"/chunks/settings-subscription.5781ca4d50bdbcfa065f.hot-update.js": "/chunks/settings-subscription.5781ca4d50bdbcfa065f.hot-update.js",
|
||||
"/chunks/settings-subscription.ca758fee04a3cf78cf30.hot-update.js": "/chunks/settings-subscription.ca758fee04a3cf78cf30.hot-update.js",
|
||||
"/chunks/admin~chunks/platform~chunks/settings.fdd665cf61d49aebc69d.hot-update.js": "/chunks/admin~chunks/platform~chunks/settings.fdd665cf61d49aebc69d.hot-update.js",
|
||||
"/chunks/admin~chunks/platform~chunks/settings.6a3205fb4f2b8dd393da.hot-update.js": "/chunks/admin~chunks/platform~chunks/settings.6a3205fb4f2b8dd393da.hot-update.js",
|
||||
"/chunks/settings-subscription.6a3205fb4f2b8dd393da.hot-update.js": "/chunks/settings-subscription.6a3205fb4f2b8dd393da.hot-update.js",
|
||||
"/chunks/settings-subscription.12fa902b3a9391e8d538.hot-update.js": "/chunks/settings-subscription.12fa902b3a9391e8d538.hot-update.js",
|
||||
"/chunks/settings-subscription.453191d7a9558d27b6be.hot-update.js": "/chunks/settings-subscription.453191d7a9558d27b6be.hot-update.js",
|
||||
"/chunks/settings-subscription.e6a599a3de8030a1289e.hot-update.js": "/chunks/settings-subscription.e6a599a3de8030a1289e.hot-update.js",
|
||||
"/chunks/settings-subscription.68f33a64d80e06da6b44.hot-update.js": "/chunks/settings-subscription.68f33a64d80e06da6b44.hot-update.js"
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<!--Usage-->
|
||||
<div v-if="config.subscriptionType === 'metered'" class="text-center leading-3 mt-1">
|
||||
<b class="text-xs font-bold leading-3 block text-theme">
|
||||
$22,93
|
||||
{{ user.data.meta.usages.costEstimate }}
|
||||
</b>
|
||||
<span class="text-xs text-gray-500">
|
||||
{{ $t('usage') }}
|
||||
|
||||
@@ -39,21 +39,21 @@
|
||||
</FormLabel>
|
||||
|
||||
<b class="text-3xl font-extrabold -mt-3 block mb-0.5">
|
||||
$22.93
|
||||
{{ user.data.meta.usages.costEstimate }}
|
||||
</b>
|
||||
|
||||
<b class="mb-3 block text-sm text-gray-400 mb-5">
|
||||
From 2. December till now
|
||||
{{ user.data.relationships.subscription.data.attributes.updated_at }} {{ $t('till now') }}
|
||||
</b>
|
||||
|
||||
<div>
|
||||
<div class="flex items-center justify-between py-2 border-b dark:border-opacity-5 border-light border-dashed" v-for="(usage, i) in usages" :ke="i">
|
||||
<div class="flex items-center justify-between py-2 border-b dark:border-opacity-5 border-light border-dashed" v-for="(usage, i) in user.data.meta.usages.featureEstimates" :key="i">
|
||||
<div class="w-2/4 leading-none">
|
||||
<b class="text-sm font-bold leading-none">
|
||||
{{ usage.title }}
|
||||
{{ $t(usage.feature) }}
|
||||
</b>
|
||||
<small class="text-xs text-gray-500 pt-2 leading-none block">
|
||||
{{ usage.description }}
|
||||
{{ $t(`feature_usage_desc_${usage.feature}`) }}
|
||||
</small>
|
||||
</div>
|
||||
<div class="text-left w-1/4">
|
||||
@@ -63,7 +63,7 @@
|
||||
</div>
|
||||
<div class="text-right w-1/4">
|
||||
<span class="text-sm font-bold text-theme">
|
||||
{{ usage.amount }}
|
||||
{{ usage.cost }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -186,31 +186,6 @@
|
||||
return {
|
||||
isLoading: false,
|
||||
paymentAmount: undefined,
|
||||
usages: [
|
||||
{
|
||||
title: 'Storage',
|
||||
description: this.$t('Total storage amount you are using.'),
|
||||
usage: '12.23GB',
|
||||
amount: '$4.98',
|
||||
},
|
||||
{
|
||||
title: 'Bandwidth',
|
||||
description: this.$t('Data amount you transferred to/from your account.'),
|
||||
usage: '3.61GB',
|
||||
amount: '$2.89',
|
||||
},
|
||||
{
|
||||
title: 'Members',
|
||||
description: this.$t('Total members you invited to your team folders.'),
|
||||
usage: '12',
|
||||
amount: '$1.20',
|
||||
},
|
||||
{
|
||||
title: 'Platform Fee',
|
||||
usage: '1',
|
||||
amount: '$2.00',
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
label: this.$t('Note'),
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Users\Resources;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
use Domain\Folders\Resources\FolderCollection;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use VueFileManager\Subscription\Domain\Credits\Resources\BalanceResource;
|
||||
use VueFileManager\Subscription\Domain\Subscriptions\Resources\SubscriptionResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
@@ -16,6 +18,11 @@ class UserResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$subscriptionType = get_settings('subscription_type');
|
||||
|
||||
$isMeteredSubscription = $subscriptionType === 'metered';
|
||||
$isFixedSubscription = $subscriptionType === 'fixed';
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
@@ -31,34 +38,68 @@ class UserResource extends JsonResource
|
||||
'updated_at' => format_date($this->updated_at, '%d. %B. %Y'),
|
||||
],
|
||||
'relationships' => [
|
||||
'balance' => [
|
||||
'data' => [
|
||||
'id' => $this->balance->id,
|
||||
'type' => 'balance',
|
||||
'attributes' => [
|
||||
'formatted' => format_currency($this->balance->amount, $this->balance->currency),
|
||||
'balance' => $this->balance->amount,
|
||||
'currency' => $this->balance->currency,
|
||||
],
|
||||
],
|
||||
],
|
||||
'settings' => new SettingsResource($this->settings),
|
||||
'favourites' => new FolderCollection($this->favouriteFolders),
|
||||
'limitations' => [
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
'type' => 'limitations',
|
||||
'attributes' => $this->limitations,
|
||||
],
|
||||
],
|
||||
'settings' => new SettingsResource($this->settings),
|
||||
'favourites' => new FolderCollection($this->favouriteFolders),
|
||||
$this->mergeWhen($this->hasSubscription(), fn() => [
|
||||
'subscription' => new SubscriptionResource($this->subscription),
|
||||
]),
|
||||
$this->mergeWhen($isMeteredSubscription, fn() => [
|
||||
'balance' => new BalanceResource($this->balance),
|
||||
]),
|
||||
],
|
||||
'meta' => [
|
||||
'limitations' => $this->limitations->summary(),
|
||||
$this->mergeWhen($isFixedSubscription, fn() => [
|
||||
'limitations' => $this->limitations->summary(),
|
||||
]),
|
||||
$this->mergeWhen($isMeteredSubscription, fn() => [
|
||||
'usages' => $this->getUsageEstimates(),
|
||||
]),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function getUsageEstimates()
|
||||
{
|
||||
$estimates = $this
|
||||
->subscription
|
||||
->plan
|
||||
->meteredFeatures
|
||||
->map(function ($feature) {
|
||||
|
||||
// Get first tier
|
||||
$tier = $feature->tiers()->first();
|
||||
|
||||
$usageQuery = $this->subscription
|
||||
->usages()
|
||||
->where('created_at', '>=', now()->subDays(30))
|
||||
->where('subscription_id', $this->subscription->id)
|
||||
->where('metered_feature_id', $feature->id);
|
||||
|
||||
$usage = match ($feature->aggregate_strategy) {
|
||||
'sum_of_usage' => $usageQuery->sum('quantity'),
|
||||
'maximum_usage' => $usageQuery->max('quantity'),
|
||||
};
|
||||
|
||||
$amount = ($tier->per_unit / 1000) * $usage;
|
||||
|
||||
$formattedUsage = match ($feature->key) {
|
||||
'bandwidth' => Metric::megabytes($usage)->format(),
|
||||
'storage' => Metric::megabytes($usage)->format(),
|
||||
};
|
||||
|
||||
// return sum of money
|
||||
return [
|
||||
'feature' => $feature->key,
|
||||
'amount' => $amount,
|
||||
'cost' => format_currency($amount, $this->subscription->plan->currency),
|
||||
'usage' => $formattedUsage,
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'costEstimate' => format_currency($estimates->sum('amount'), $this->subscription->plan->currency),
|
||||
'featureEstimates' => $estimates->toArray(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user