mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
task claim
This commit is contained in:
@@ -56,10 +56,12 @@ class ExamResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
,
|
,
|
||||||
Forms\Components\TextInput::make('success_reward_bonus')
|
Forms\Components\TextInput::make('success_reward_bonus')
|
||||||
|
->required()
|
||||||
->label(__('exam.success_reward_bonus'))
|
->label(__('exam.success_reward_bonus'))
|
||||||
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
||||||
,
|
,
|
||||||
Forms\Components\TextInput::make('fail_deduct_bonus')
|
Forms\Components\TextInput::make('fail_deduct_bonus')
|
||||||
|
->required()
|
||||||
->label(__('exam.fail_deduct_bonus'))
|
->label(__('exam.fail_deduct_bonus'))
|
||||||
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
||||||
,
|
,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class CreateExam extends CreateRecord
|
|||||||
}
|
}
|
||||||
$this->redirect($this->getResource()::getUrl('index'));
|
$this->redirect($this->getResource()::getUrl('index'));
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
do_log($exception->getMessage() . "\n" . $exception->getTraceAsString(), "error");
|
||||||
$this->notify('danger', $exception->getMessage());
|
$this->notify('danger', $exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -165,7 +165,10 @@ class Exam extends NexusModel
|
|||||||
$filter = self::FILTER_USER_CLASS;
|
$filter = self::FILTER_USER_CLASS;
|
||||||
if (!empty($currentFilters[$filter])) {
|
if (!empty($currentFilters[$filter])) {
|
||||||
$classes = collect(User::$classes)->only($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;
|
$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");
|
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)
|
public function getAvatarAttribute($value)
|
||||||
{
|
{
|
||||||
if ($value) {
|
if ($value) {
|
||||||
|
|||||||
@@ -364,18 +364,30 @@ class ExamRepository extends BaseRepository
|
|||||||
/** @var Exam $exam */
|
/** @var Exam $exam */
|
||||||
$exam = Exam::query()->find($examId);
|
$exam = Exam::query()->find($examId);
|
||||||
$user = User::query()->findOrFail($uid);
|
$user = User::query()->findOrFail($uid);
|
||||||
if (Auth::user()->class <= $user->class) {
|
$locale = $user->locale;
|
||||||
throw new NexusException("No permission !");
|
$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)) {
|
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()) {
|
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();
|
$exists = $user->exams()->where('exam_id', $exam->id)->exists();
|
||||||
if ($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 = [
|
$data = [
|
||||||
'exam_id' => $exam->id,
|
'exam_id' => $exam->id,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
|
||||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-05-20');
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-06-07');
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
@@ -150,6 +150,13 @@ class AjaxInterface{
|
|||||||
$rep = new \App\Repositories\MedalRepository();
|
$rep = new \App\Repositories\MedalRepository();
|
||||||
return $rep->saveUserMedal($CURUSER['id'], $data);
|
return $rep->saveUserMedal($CURUSER['id'], $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function claimTask($params)
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
$rep = new \App\Repositories\ExamRepository();
|
||||||
|
return $rep->assignToUser($CURUSER['id'], $params['exam_id']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = 'AjaxInterface';
|
$class = 'AjaxInterface';
|
||||||
|
|||||||
+9
-7
@@ -43,18 +43,20 @@ TABLE;
|
|||||||
$now = now();
|
$now = now();
|
||||||
$table .= '<tbody>';
|
$table .= '<tbody>';
|
||||||
$userInfo = \App\Models\User::query()->findOrFail($CURUSER['id'], \App\Models\User::$commonFields);
|
$userInfo = \App\Models\User::query()->findOrFail($CURUSER['id'], \App\Models\User::$commonFields);
|
||||||
$userTasks = $userInfo->examAndTasks()->where("type", \App\Models\Exam::TYPE_TASK)
|
$userTasks = $userInfo->onGoingExamAndTasks()->where("type", \App\Models\Exam::TYPE_TASK)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->get()
|
->get()
|
||||||
->keyBy('id')
|
->keyBy('id')
|
||||||
;
|
;
|
||||||
//dd($userTasks);
|
//dd(last_query());
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$claimDisabled = $claimClass = '';
|
$claimDisabled = $claimClass = '';
|
||||||
$claimBtnText = "认领";
|
$claimBtnText = "认领";
|
||||||
if ($userTasks->has($row->id)) {
|
if ($userTasks->has($row->id)) {
|
||||||
$claimDisabled = " disabled";
|
$claimDisabled = " disabled";
|
||||||
$claimBtnText = "已认领";
|
$claimBtnText = "已认领";
|
||||||
|
} else {
|
||||||
|
$claimClass = "claim";
|
||||||
}
|
}
|
||||||
$claimAction = sprintf(
|
$claimAction = sprintf(
|
||||||
'<input type="button" class="%s" data-id="%s" value="%s"%s>',
|
'<input type="button" class="%s" data-id="%s" value="%s"%s>',
|
||||||
@@ -75,15 +77,15 @@ foreach ($rows as $row) {
|
|||||||
$table .= '</tbody></table>';
|
$table .= '</tbody></table>';
|
||||||
echo $header . $table . $paginationBottom;
|
echo $header . $table . $paginationBottom;
|
||||||
end_main_frame();
|
end_main_frame();
|
||||||
$confirmBuyMsg = nexus_trans('medal.confirm_to_buy');
|
$confirmBuyMsg = nexus_trans('exam.confirm_to_claim');
|
||||||
$confirmGiftMsg = nexus_trans('medal.confirm_to_gift');
|
$confirmGiftMsg = nexus_trans('medal.confirm_to_gift');
|
||||||
$js = <<<JS
|
$js = <<<JS
|
||||||
jQuery('.buy').on('click', function (e) {
|
jQuery('.claim').on('click', function (e) {
|
||||||
let medalId = jQuery(this).attr('data-id')
|
let id = jQuery(this).attr('data-id')
|
||||||
layer.confirm("{$confirmBuyMsg}", function (index) {
|
layer.confirm("{$confirmBuyMsg}", function (index) {
|
||||||
let params = {
|
let params = {
|
||||||
action: "buyMedal",
|
action: "claimTask",
|
||||||
params: {medal_id: medalId}
|
params: {exam_id: id}
|
||||||
}
|
}
|
||||||
console.log(params)
|
console.log(params)
|
||||||
jQuery.post('ajax.php', params, function(response) {
|
jQuery.post('ajax.php', params, function(response) {
|
||||||
|
|||||||
@@ -48,4 +48,11 @@ return [
|
|||||||
|
|
||||||
'fail_deduct_bonus' => 'Deduct bonus for task failure',
|
'fail_deduct_bonus' => 'Deduct bonus for task failure',
|
||||||
'success_reward_bonus' => 'Reward bonus for task completion',
|
'success_reward_bonus' => 'Reward bonus for task completion',
|
||||||
|
|
||||||
|
'action_claim_task' => 'Claim',
|
||||||
|
'confirm_to_claim' => 'Sure you want to claim?' ,
|
||||||
|
'claim_by_yourself_only' => 'Claim only by yourself!' ,
|
||||||
|
'not_match_target_user' => 'You are not a matching target user!' ,
|
||||||
|
'has_other_on_the_way' => 'There is an other :type_text in progress!' ,
|
||||||
|
'claimed_already' => 'Already claimed',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ return [
|
|||||||
'no_limit' => 'No limit',
|
'no_limit' => 'No limit',
|
||||||
'sum' => 'Sum',
|
'sum' => 'Sum',
|
||||||
'do_not_repeat' => 'Please do not repeat the operation!',
|
'do_not_repeat' => 'Please do not repeat the operation!',
|
||||||
|
'no_permission' => 'No permission!',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -61,5 +61,9 @@ return [
|
|||||||
'success_reward_bonus' => '任务完成奖励魔力',
|
'success_reward_bonus' => '任务完成奖励魔力',
|
||||||
|
|
||||||
'action_claim_task' => '领取',
|
'action_claim_task' => '领取',
|
||||||
|
'confirm_to_claim' => '确定要认领吗?',
|
||||||
|
'claim_by_yourself_only' => '只能自己认领!',
|
||||||
|
'not_match_target_user' => '你不是匹配的目标用户!',
|
||||||
|
'has_other_on_the_way' => '有其他进行中的:type_text',
|
||||||
|
'claimed_already' => '已经认领',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ return [
|
|||||||
'no_limit' => '不限',
|
'no_limit' => '不限',
|
||||||
'sum' => '累计',
|
'sum' => '累计',
|
||||||
'do_not_repeat' => '请不要重复操作!',
|
'do_not_repeat' => '请不要重复操作!',
|
||||||
|
'no_permission' => '无权限!',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -48,4 +48,11 @@ return [
|
|||||||
|
|
||||||
'fail_deduct_bonus' => '任务失败扣除魔力',
|
'fail_deduct_bonus' => '任务失败扣除魔力',
|
||||||
'success_reward_bonus' => '任务完成奖励魔力',
|
'success_reward_bonus' => '任务完成奖励魔力',
|
||||||
|
|
||||||
|
'action_claim_task' => '領取',
|
||||||
|
'confirm_to_claim' => '確定要認領嗎?',
|
||||||
|
'claim_by_yourself_only' => '只能自己認領!',
|
||||||
|
'not_match_target_user' => '你不是匹配的目標用戶!',
|
||||||
|
'has_other_on_the_way' => '有其他進行中的:type_text',
|
||||||
|
'claimed_already' => '已經認領',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ return [
|
|||||||
'no_limit' => '不限',
|
'no_limit' => '不限',
|
||||||
'sum' => '累計',
|
'sum' => '累計',
|
||||||
'do_not_repeat' => '請不要重復操作!',
|
'do_not_repeat' => '請不要重復操作!',
|
||||||
|
'no_permission' => '無權限!',
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user