mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
task claim
This commit is contained in:
@@ -56,10 +56,12 @@ class ExamResource extends Resource
|
||||
->reactive()
|
||||
,
|
||||
Forms\Components\TextInput::make('success_reward_bonus')
|
||||
->required()
|
||||
->label(__('exam.success_reward_bonus'))
|
||||
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
||||
,
|
||||
Forms\Components\TextInput::make('fail_deduct_bonus')
|
||||
->required()
|
||||
->label(__('exam.fail_deduct_bonus'))
|
||||
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
||||
,
|
||||
|
||||
@@ -29,6 +29,7 @@ class CreateExam extends CreateRecord
|
||||
}
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . "\n" . $exception->getTraceAsString(), "error");
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -165,7 +165,10 @@ class Exam extends NexusModel
|
||||
$filter = self::FILTER_USER_CLASS;
|
||||
if (!empty($currentFilters[$filter])) {
|
||||
$classes = collect(User::$classes)->only($currentFilters[$filter]);
|
||||
$arr[] = sprintf('%s: %s', nexus_trans("exam.filters.$filter"), $classes->pluck('text')->implode(', '));
|
||||
$arr[] = sprintf(
|
||||
'%s: %s',
|
||||
nexus_trans("exam.filters.$filter"), $classes->map(fn ($value, $key) => User::getClassText($key))->implode(', ')
|
||||
);
|
||||
}
|
||||
|
||||
$filter = self::FILTER_USER_REGISTER_TIME_RANGE;
|
||||
|
||||
@@ -519,6 +519,11 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
return $this->belongsToMany(Exam::class, "exam_users", "uid", "exam_id");
|
||||
}
|
||||
|
||||
public function onGoingExamAndTasks(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->examAndTasks()->wherePivot("status", ExamUser::STATUS_NORMAL);
|
||||
}
|
||||
|
||||
public function getAvatarAttribute($value)
|
||||
{
|
||||
if ($value) {
|
||||
|
||||
@@ -364,18 +364,30 @@ class ExamRepository extends BaseRepository
|
||||
/** @var Exam $exam */
|
||||
$exam = Exam::query()->find($examId);
|
||||
$user = User::query()->findOrFail($uid);
|
||||
if (Auth::user()->class <= $user->class) {
|
||||
throw new NexusException("No permission !");
|
||||
$locale = $user->locale;
|
||||
$authUserClass = get_user_class();
|
||||
$authUserId = get_user_id();
|
||||
if ($exam->isTypeExam()) {
|
||||
if ($authUserClass <= $user->class) {
|
||||
//exam only can assign by upper class admin
|
||||
throw new NexusException(nexus_trans("nexus.no_permission", [], $locale));
|
||||
}
|
||||
} elseif ($exam->isTypeTask()) {
|
||||
if ($user->id != $authUserId) {
|
||||
//task only can be claimed by self
|
||||
throw new NexusException(nexus_trans('exam.claim_by_yourself_only', [], $locale));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->isExamMatchUser($exam, $user)) {
|
||||
throw new NexusException("Exam: {$exam->id} no match this user.");
|
||||
throw new NexusException(nexus_trans('exam.not_match_target_user', [], $locale));
|
||||
}
|
||||
if ($user->exams()->where('status', ExamUser::STATUS_NORMAL)->exists()) {
|
||||
throw new NexusException("User: $uid already has exam on the way.");
|
||||
throw new NexusException(nexus_trans('exam.has_other_on_the_way', ['type_text' => $exam->typeText], $locale));
|
||||
}
|
||||
$exists = $user->exams()->where('exam_id', $exam->id)->exists();
|
||||
if ($exists) {
|
||||
throw new NexusException("Exam: {$exam->id} already assign to user: {$user->id}.");
|
||||
throw new NexusException(nexus_trans('exam.claimed_already', [], $locale));
|
||||
}
|
||||
$data = [
|
||||
'exam_id' => $exam->id,
|
||||
|
||||
Reference in New Issue
Block a user