mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-18 11:15:02 +00:00
- Create/Update metered billing plan
This commit is contained in:
@@ -14,13 +14,13 @@ class FormatUsageEstimatesAction
|
||||
$usage = match ($estimate['feature']) {
|
||||
'bandwidth' => Metric::megabytes($estimate['usage'])->format(),
|
||||
'storage' => Metric::megabytes($estimate['usage'])->format(),
|
||||
'flat-fee' => intval($estimate['usage']) . ' ' . __('Pcs.'),
|
||||
'flatFee' => intval($estimate['usage']) . ' ' . __('Pcs.'),
|
||||
};
|
||||
|
||||
// Normalize units
|
||||
$amount = match ($estimate['feature']) {
|
||||
'bandwidth', 'storage' => $estimate['amount'] / 1000,
|
||||
'flat-fee' => $estimate['amount'],
|
||||
'flatFee' => $estimate['amount'],
|
||||
};
|
||||
|
||||
return [
|
||||
|
||||
@@ -12,12 +12,21 @@ class ReportUsageAction
|
||||
->where('status', 'active')
|
||||
->cursor()
|
||||
->each(function ($subscription) {
|
||||
$this->recordBandwidth($subscription);
|
||||
$this->recordStorageCapacity($subscription);
|
||||
if ($subscription->plan->meteredFeatures()->where('key', 'bandwidth')->exists()) {
|
||||
$this->recordBandwidth($subscription);
|
||||
}
|
||||
|
||||
if ($subscription->plan->meteredFeatures()->where('key', 'storage')->exists()) {
|
||||
$this->recordStorageUsage($subscription);
|
||||
}
|
||||
|
||||
if ($subscription->plan->meteredFeatures()->where('key', 'flatFee')->exists()) {
|
||||
$this->recordFlatFee($subscription);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function recordStorageCapacity(Subscription $subscription): void
|
||||
private function recordStorageUsage(Subscription $subscription): void
|
||||
{
|
||||
// Sum all file size
|
||||
$filesize = DB::table('files')
|
||||
@@ -45,4 +54,10 @@ class ReportUsageAction
|
||||
// Record storage capacity usage
|
||||
$subscription->recordUsage('bandwidth', $amount);
|
||||
}
|
||||
|
||||
private function recordFlatFee(Subscription $subscription): void
|
||||
{
|
||||
// Record flat fee
|
||||
$subscription->recordUsage('flatFee', 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user