mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 02:50:39 +00:00
controller refactoring part 17
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Domain\Traffic\Actions;
|
||||
|
||||
use Domain\Traffic\Models\Traffic;
|
||||
|
||||
class RecordDownloadAction
|
||||
{
|
||||
/**
|
||||
* Record user download filesize
|
||||
*/
|
||||
public function __invoke(
|
||||
int $file_size,
|
||||
string $user_id,
|
||||
): void {
|
||||
$record = Traffic::currentMonth()
|
||||
->firstOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
|
||||
$record->update([
|
||||
'download' => $record->download + $file_size,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Domain\Traffic\Actions;
|
||||
|
||||
use Domain\Traffic\Models\Traffic;
|
||||
|
||||
class RecordUploadAction
|
||||
{
|
||||
/**
|
||||
* Record user upload filesize
|
||||
*/
|
||||
public function __invoke(
|
||||
int $file_size,
|
||||
string $user_id,
|
||||
): void {
|
||||
$record = Traffic::currentMonth()
|
||||
->firstOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
|
||||
$record->update([
|
||||
'upload' => $record->upload + $file_size,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@ namespace Domain\Traffic\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
/**
|
||||
* @method static whereYear(string $string, string $string1, int $year)
|
||||
* @method static currentMonth()
|
||||
*/
|
||||
class Traffic extends Model
|
||||
{
|
||||
@@ -22,6 +24,13 @@ class Traffic extends Model
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function scopeCurrentMonth($query): Builder
|
||||
{
|
||||
return $query
|
||||
->whereYear('created_at', '=', now()->year)
|
||||
->whereMonth('created_at', '=', now()->month);
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
Reference in New Issue
Block a user