mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-24 05:34:43 +00:00
- charge members
This commit is contained in:
@@ -12,15 +12,15 @@ class FormatUsageEstimatesAction
|
||||
return $usage->mapWithKeys(function ($estimate) use ($currency) {
|
||||
// Format usage
|
||||
$usage = match ($estimate['feature']) {
|
||||
'bandwidth' => Metric::megabytes($estimate['usage'])->format(),
|
||||
'storage' => Metric::megabytes($estimate['usage'])->format(),
|
||||
'bandwidth', 'storage' => Metric::megabytes($estimate['usage'])->format(),
|
||||
'flatFee' => intval($estimate['usage']) . ' ' . __('Pcs.'),
|
||||
'member' => intval($estimate['usage']) . ' ' . __('Mem.'),
|
||||
};
|
||||
|
||||
// Normalize units
|
||||
$amount = match ($estimate['feature']) {
|
||||
'bandwidth', 'storage' => $estimate['amount'] / 1000,
|
||||
'flatFee' => $estimate['amount'],
|
||||
'flatFee', 'member' => $estimate['amount'],
|
||||
};
|
||||
|
||||
return [
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Support\Scheduler\Actions;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use DB;
|
||||
use VueFileManager\Subscription\Domain\Subscriptions\Models\Subscription;
|
||||
|
||||
@@ -23,6 +24,10 @@ class ReportUsageAction
|
||||
if ($subscription->plan->meteredFeatures()->where('key', 'flatFee')->exists()) {
|
||||
$this->recordFlatFee($subscription);
|
||||
}
|
||||
|
||||
if ($subscription->plan->meteredFeatures()->where('key', 'member')->exists()) {
|
||||
$this->recordMemberUsage($subscription);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,4 +65,35 @@ class ReportUsageAction
|
||||
// Record flat fee
|
||||
$subscription->recordUsage('flatFee', 1);
|
||||
}
|
||||
|
||||
// TODO: Refactor this function to get total used team members, same function here UserLimitation.php@getMaxTeamMembers
|
||||
private function recordMemberUsage(Subscription $subscription): void
|
||||
{
|
||||
$userTeamFolderIds = DB::table('team_folder_members')
|
||||
->where('user_id', $subscription->user_id)
|
||||
->pluck('parent_id');
|
||||
|
||||
$memberIds = DB::table('team_folder_members')
|
||||
->where('user_id', '!=', $subscription->user_id)
|
||||
->whereIn('parent_id', $userTeamFolderIds)
|
||||
->pluck('user_id')
|
||||
->unique();
|
||||
|
||||
// Get member emails
|
||||
$memberEmails = User::whereIn('id', $memberIds)
|
||||
->pluck('email');
|
||||
|
||||
// Get active invitation emails
|
||||
$InvitationEmails = DB::table('team_folder_invitations')
|
||||
->where('status', 'pending')
|
||||
->where('inviter_id', $subscription->user_id)
|
||||
->pluck('email')
|
||||
->unique();
|
||||
|
||||
// Get allowed emails in the limit
|
||||
$totalUsedEmails = $memberEmails->merge($InvitationEmails)
|
||||
->unique();
|
||||
|
||||
$subscription->recordUsage('member', $totalUsedEmails->count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user