fix h&R detail

This commit is contained in:
xiaomlove
2025-01-27 14:07:44 +08:00
parent e48932d74d
commit efb635c12b
3 changed files with 67 additions and 7 deletions

View File

@@ -5,9 +5,11 @@ namespace App\Filament\Resources\User;
use App\Filament\Resources\User\HitAndRunResource\Pages;
use App\Filament\Resources\User\HitAndRunResource\RelationManagers;
use App\Models\HitAndRun;
use App\Models\User;
use App\Repositories\HitAndRunRepository;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Tables\Table;
use Filament\Tables;
@@ -16,6 +18,8 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\HtmlString;
use Filament\Infolists\Components;
use Filament\Infolists;
class HitAndRunResource extends Resource
{
@@ -87,6 +91,51 @@ class HitAndRunResource extends Resource
]);
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Infolists\Components\TextEntry::make('id'),
Infolists\Components\TextEntry::make('statusText')
->label(__("label.status"))
,
Infolists\Components\TextEntry::make('uid')
->formatStateUsing(fn ($record) => username_for_admin($record->uid))
->label(__("label.username"))
,
Infolists\Components\TextEntry::make('torrent_id')
->formatStateUsing(fn ($record) => $record->torrent->name)
->label(__("label.torrent.label"))
,
Infolists\Components\TextEntry::make('snatch.uploadedText')
->label(__("label.uploaded"))
,
Infolists\Components\TextEntry::make('snatch.downloadedText')
->label(__("label.downloaded"))
,
Infolists\Components\TextEntry::make('snatch.shareRatio')
->label(__("label.ratio"))
,
Infolists\Components\TextEntry::make('seedTimeRequired')
->label(__("label.seed_time_required"))
,
Infolists\Components\TextEntry::make('inspectTimeLeft')
->label(__("label.inspect_time_left"))
,
Infolists\Components\TextEntry::make('comment')
->formatStateUsing(fn ($record) => nl2br($record->comment))
->label(__("label.comment"))
,
Infolists\Components\TextEntry::make('created_at')
->label(__("label.created_at"))
,
Infolists\Components\TextEntry::make('updated_at')
->label(__("label.updated_at"))
,
])->columns(4);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->with(['user', 'torrent', 'snatch', 'torrent.basic_category']);

View File

@@ -14,7 +14,7 @@ class ViewHitAndRun extends ViewRecord
{
protected static string $resource = HitAndRunResource::class;
protected static string $view = 'filament.detail-card';
// protected static string $view = 'filament.detail-card';
private function getDetailCardData(): array
{

View File

@@ -11,6 +11,7 @@ use App\Models\Snatch;
use App\Models\Torrent;
use App\Models\User;
use App\Models\UserBanLog;
use App\Models\UserModifyLog;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
@@ -1137,9 +1138,10 @@ class ExamRepository extends BaseRepository
}
$result += $examUsers->count();
$now = Carbon::now()->toDateTimeString();
$examUserIdArr = $uidToDisable = $messageToSend = $userBanLog = $userModcommentUpdate = [];
$examUserIdArr = $uidToDisable = $messageToSend = $userBanLog = [];
$bonusLog = $userBonusUpdate = $uidToUpdateBonus = [];
$examUserToInsert = [];
$userModifyLogs = [];
foreach ($examUsers as $examUser) {
$minId = $examUser->id;
$examUserIdArr[] = $examUser->id;
@@ -1200,8 +1202,14 @@ class ExamRepository extends BaseRepository
'begin' => $examUser->begin,
'end' => $examUser->end
], $locale);
$userModcomment = sprintf('%s - %s', date('Y-m-d'), $userModcomment);
$userModcommentUpdate[] = sprintf("when `id` = %s then concat_ws('\n', '%s', modcomment)", $uid, $userModcomment);
// $userModcomment = sprintf('%s - %s', date('Y-m-d'), $userModcomment);
// $userModcommentUpdate[] = sprintf("when `id` = %s then concat_ws('\n', '%s', modcomment)", $uid, $userModcomment);
$userModifyLogs[] = [
'user_id' => $uid,
'content' => $userModcomment,
'created_at' => $now,
'updated_at' => $now,
];
$banLogReason = nexus_trans('exam.ban_log_reason', [
'exam_name' => $exam->name,
'begin' => $examUser->begin,
@@ -1242,7 +1250,7 @@ class ExamRepository extends BaseRepository
'msg' => $msg
];
}
DB::transaction(function () use ($uidToDisable, $messageToSend, $examUserIdArr, $examUserToInsert, $userBanLog, $userModcommentUpdate, $userBonusUpdate, $bonusLog, $uidToUpdateBonus, $userTable, $logPrefix) {
DB::transaction(function () use ($uidToDisable, $messageToSend, $examUserIdArr, $examUserToInsert, $userBanLog, $userModifyLogs, $userBonusUpdate, $bonusLog, $uidToUpdateBonus, $userTable, $logPrefix) {
ExamUser::query()->whereIn('id', $examUserIdArr)->update(['status' => ExamUser::STATUS_FINISHED]);
do {
$deleted = ExamProgress::query()->whereIn('exam_user_id', $examUserIdArr)->limit(10000)->delete();
@@ -1252,8 +1260,8 @@ class ExamRepository extends BaseRepository
if (!empty($uidToDisable)) {
$uidStr = implode(', ', $uidToDisable);
$sql = sprintf(
"update %s set enabled = '%s', modcomment = case %s end where id in (%s)",
$userTable, User::ENABLED_NO, implode(' ', $userModcommentUpdate), $uidStr
"update %s set enabled = '%s' where id in (%s)",
$userTable, User::ENABLED_NO, $uidStr
);
$updateResult = DB::update($sql);
do_log(sprintf("$logPrefix, disable %s users: %s, sql: %s, updateResult: %s", count($uidToDisable), $uidStr, $sql, $updateResult));
@@ -1276,6 +1284,9 @@ class ExamRepository extends BaseRepository
if (!empty($bonusLog)) {
BonusLogs::query()->insert($bonusLog);
}
if (!empty($userModifyLogs)) {
UserModifyLog::query()->insert($userModifyLogs);
}
});
}
return $result;