mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
login notify + bonus log
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\GenerateTemporaryInvite;
|
||||
use App\Jobs\SendLoginNotify;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UserLoginNotify extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:login_notify {--this_id=} {--last_id=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Send login notify, option: --this_id, --last_id';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$thisId = $this->option('this_id');
|
||||
$lastId = $this->option('last_id');
|
||||
$this->info("thisId: $thisId, lastId: $lastId");
|
||||
SendLoginNotify::dispatch($thisId, $lastId);
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User;
|
||||
|
||||
use App\Filament\Resources\User\BonusLogResource\Pages;
|
||||
use App\Filament\Resources\User\BonusLogResource\RelationManagers;
|
||||
use App\Models\BonusLogs;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class BonusLogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = BonusLogs::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-collection';
|
||||
|
||||
protected static ?string $navigationGroup = 'User';
|
||||
|
||||
protected static ?int $navigationSort = 10;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.bonus_log');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('uid')
|
||||
->formatStateUsing(fn ($state) => username_for_admin($state))
|
||||
->label(__('label.username'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('business_type_text')
|
||||
->label(__('bonus-log.fields.business_type'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('old_total_value')
|
||||
->label(__('bonus-log.fields.old_total_value'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('value')
|
||||
->label(__('bonus-log.fields.value'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('new_total_value')
|
||||
->label(__('bonus-log.fields.new_total_value'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('comment')
|
||||
->label(__('label.comment'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('label.created_at'))
|
||||
,
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('uid')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('uid')
|
||||
->label(__('label.username'))
|
||||
->placeholder('UID')
|
||||
,
|
||||
])->query(function (Builder $query, array $data) {
|
||||
return $query->when($data['uid'], fn (Builder $query, $value) => $query->where("uid", $value));
|
||||
})
|
||||
,
|
||||
Tables\Filters\SelectFilter::make('business_type')
|
||||
->options(BonusLogs::listStaticProps(BonusLogs::$businessTypes, 'bonus-log.business_types', true))
|
||||
->label(__('bonus-log.fields.business_type'))
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
// Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
// Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManageBonusLogs::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User\BonusLogResource\Pages;
|
||||
|
||||
use App\Filament\PageListSingle;
|
||||
use App\Filament\Resources\User\BonusLogResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageBonusLogs extends PageListSingle
|
||||
{
|
||||
protected static string $resource = BonusLogResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
// Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User;
|
||||
|
||||
use App\Filament\Resources\User\LoginLogResource\Pages;
|
||||
use App\Filament\Resources\User\LoginLogResource\RelationManagers;
|
||||
use App\Models\LoginLog;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class LoginLogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = LoginLog::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-collection';
|
||||
|
||||
protected static ?string $navigationGroup = 'User';
|
||||
|
||||
protected static ?int $navigationSort = 9;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.login_log');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('uid')
|
||||
->formatStateUsing(fn ($state) => username_for_admin($state))
|
||||
->label(__('label.username'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('ip')->searchable(),
|
||||
Tables\Columns\TextColumn::make('country')->label(__('label.country'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('city')->label(__('label.city'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('client')->label(__('label.client')),
|
||||
Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at')),
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('uid')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('uid')
|
||||
->label(__('label.username'))
|
||||
->placeholder('UID')
|
||||
,
|
||||
])->query(function (Builder $query, array $data) {
|
||||
return $query->when($data['uid'], fn (Builder $query, $value) => $query->where("uid", $value));
|
||||
})
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
// Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
// Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManageLoginLogs::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User\LoginLogResource\Pages;
|
||||
|
||||
use App\Filament\PageListSingle;
|
||||
use App\Filament\Resources\User\LoginLogResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageLoginLogs extends PageListSingle
|
||||
{
|
||||
protected static string $resource = LoginLogResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
// Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\LoginLog;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Repositories\ToolRepository;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SendLoginNotify implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
private int $thisLoginLogId;
|
||||
|
||||
private int $lastLoginLogId;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $thisLoginLogId, int $lastLoginLogId)
|
||||
{
|
||||
$this->thisLoginLogId = $thisLoginLogId;
|
||||
|
||||
$this->lastLoginLogId = $lastLoginLogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$thisLoginLog = LoginLog::query()->findOrFail($this->thisLoginLogId);
|
||||
$lastLoginLog = LoginLog::query()->findOrFail($this->lastLoginLogId);
|
||||
$user = User::query()->findOrFail($thisLoginLog->uid, User::$commonFields);
|
||||
$locale = $user->locale;
|
||||
$toolRep = new ToolRepository();
|
||||
$subject = nexus_trans('message.login_notify.subject', ['site_name' => Setting::get('basic.SITENAME')], $locale);
|
||||
$body = nexus_trans('message.login_notify.body', [
|
||||
'this_login_time' => $thisLoginLog->created_at,
|
||||
'this_ip' => $thisLoginLog->ip,
|
||||
'this_location' => sprintf('%s·%s', $thisLoginLog->city, $thisLoginLog->country),
|
||||
'last_login_time' => $lastLoginLog->created_at,
|
||||
'last_ip' => $lastLoginLog->ip,
|
||||
'last_location' => sprintf('%s·%s', $lastLoginLog->city, $lastLoginLog->country),
|
||||
], $locale);
|
||||
$result = $toolRep->sendMail($user->email, $subject, $body);
|
||||
do_log(sprintf('user: %s login notify result: %s', $user->username, var_export($result, true)));
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,11 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_GIFT_MEDAL => ['text' => 'Gift medal to someone'],
|
||||
];
|
||||
|
||||
public function getBusinessTypeTextAttribute()
|
||||
{
|
||||
return nexus_trans('bonus-log.business_types.' . $this->business_type);
|
||||
}
|
||||
|
||||
public static function getBonusForCancelHitAndRun()
|
||||
{
|
||||
$result = Setting::get('bonus.cancel_hr');
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class LoginLog extends NexusModel
|
||||
{
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = [
|
||||
'uid', 'ip', 'country', 'city', 'client'
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -222,7 +222,7 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
'id', 'username', 'email', 'class', 'status', 'added', 'avatar',
|
||||
'uploaded', 'downloaded', 'seedbonus', 'seedtime', 'leechtime',
|
||||
'invited_by', 'enabled', 'seed_points', 'last_access', 'invites',
|
||||
'lang', 'attendance_card', 'privacy', 'noad', 'downloadpos', 'donoruntil', 'donor'
|
||||
'lang', 'attendance_card', 'privacy', 'noad', 'downloadpos', 'donoruntil', 'donor', 'language'
|
||||
];
|
||||
|
||||
public static function getDefaultUserAttributes(): array
|
||||
|
||||
Reference in New Issue
Block a user