mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
add exam index init value
This commit is contained in:
+1
-1
@@ -62,4 +62,4 @@ GOOGLE_DRIVE_REFRESH_TOKEN=
|
|||||||
GOOGLE_DRIVE_FOLDER_ID=
|
GOOGLE_DRIVE_FOLDER_ID=
|
||||||
|
|
||||||
GEOIP2_DATABASE=
|
GEOIP2_DATABASE=
|
||||||
EXAM_PROGRESS_UPDATE_PROBABILITY=60
|
EXAM_PROGRESS_UPDATE_PROBABILITY=20
|
||||||
|
|||||||
Vendored
+3
@@ -84,6 +84,9 @@ const api = {
|
|||||||
avoidExamUser: (id) => {
|
avoidExamUser: (id) => {
|
||||||
return axios.put('exam-users-avoid', {id});
|
return axios.put('exam-users-avoid', {id});
|
||||||
},
|
},
|
||||||
|
recoverExamUser: (id) => {
|
||||||
|
return axios.put('exam-users-recover', {id});
|
||||||
|
},
|
||||||
storeExamUser: (params) => {
|
storeExamUser: (params) => {
|
||||||
return axios.post('exam-users', params);
|
return axios.post('exam-users', params);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -125,6 +125,15 @@
|
|||||||
<el-button type="info" size="small">Avoid</el-button>
|
<el-button type="info" size="small">Avoid</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-popconfirm>
|
</el-popconfirm>
|
||||||
|
<el-popconfirm
|
||||||
|
v-if="examInfo.status === -1"
|
||||||
|
title="Confirm Recover ?"
|
||||||
|
@confirm="handleRecoverExam(examInfo.id)"
|
||||||
|
>
|
||||||
|
<template #reference>
|
||||||
|
<el-button type="primary" size="small">Recover</el-button>
|
||||||
|
</template>
|
||||||
|
</el-popconfirm>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -205,6 +214,12 @@ export default {
|
|||||||
await fetchPageData()
|
await fetchPageData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleRecoverExam = async (id) => {
|
||||||
|
let res = await api.recoverExamUser(id)
|
||||||
|
ElMessage.success(res.msg)
|
||||||
|
await fetchPageData()
|
||||||
|
}
|
||||||
|
|
||||||
const handleAssignExam = async () => {
|
const handleAssignExam = async () => {
|
||||||
assignExam.value.open(id)
|
assignExam.value.open(id)
|
||||||
}
|
}
|
||||||
@@ -230,6 +245,7 @@ export default {
|
|||||||
handleRemoveExam,
|
handleRemoveExam,
|
||||||
handleAvoidExam,
|
handleAvoidExam,
|
||||||
handleAssignExam,
|
handleAssignExam,
|
||||||
|
handleRecoverExam,
|
||||||
handleEnableUser,
|
handleEnableUser,
|
||||||
handleViewInviteInfo,
|
handleViewInviteInfo,
|
||||||
handleDisableUser,
|
handleDisableUser,
|
||||||
|
|||||||
@@ -99,4 +99,11 @@ class ExamUserController extends Controller
|
|||||||
return $this->success($result, 'Avoid user exam success!');
|
return $this->success($result, 'Avoid user exam success!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function recover(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate(['id' => 'required']);
|
||||||
|
$result = $this->repository->recoverExamUser($request->id);
|
||||||
|
return $this->success($result, 'Recover user exam success!');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
class ExamIndexInitValue extends NexusModel
|
||||||
|
{
|
||||||
|
protected $fillable = ['uid', 'exam_id', 'index', 'value',];
|
||||||
|
|
||||||
|
public $timestamps = true;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ namespace App\Repositories;
|
|||||||
|
|
||||||
use App\Exceptions\NexusException;
|
use App\Exceptions\NexusException;
|
||||||
use App\Models\Exam;
|
use App\Models\Exam;
|
||||||
|
use App\Models\ExamIndexInitValue;
|
||||||
use App\Models\ExamProgress;
|
use App\Models\ExamProgress;
|
||||||
use App\Models\ExamUser;
|
use App\Models\ExamUser;
|
||||||
use App\Models\Message;
|
use App\Models\Message;
|
||||||
@@ -91,12 +92,22 @@ class ExamRepository extends BaseRepository
|
|||||||
return $exam;
|
return $exam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete an exam task, also will delete all exam user and progress.
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
$exam = Exam::query()->findOrFail($id);
|
$exam = Exam::query()->findOrFail($id);
|
||||||
DB::transaction(function () use ($exam) {
|
DB::transaction(function () use ($exam) {
|
||||||
ExamUser::query()->where('exam_id', $exam->id)->delete();
|
do {
|
||||||
ExamProgress::query()->where('exam_id', $exam->id)->delete();
|
$deleted = ExamUser::query()->where('exam_id', $exam->id)->limit(10000)->delete();
|
||||||
|
} while ($deleted > 0);
|
||||||
|
do {
|
||||||
|
$deleted = ExamProgress::query()->where('exam_id', $exam->id)->limit(10000)->delete();
|
||||||
|
} while ($deleted > 0);
|
||||||
$exam->delete();
|
$exam->delete();
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
@@ -232,8 +243,9 @@ class ExamRepository extends BaseRepository
|
|||||||
$data['end'] = $end;
|
$data['end'] = $end;
|
||||||
}
|
}
|
||||||
do_log("$logPrefix, data: " . nexus_json_encode($data));
|
do_log("$logPrefix, data: " . nexus_json_encode($data));
|
||||||
$result = $user->exams()->create($data);
|
$examUser = $user->exams()->create($data);
|
||||||
return $result;
|
$this->initProgress($examUser, $user);
|
||||||
|
return $examUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listUser(array $params)
|
public function listUser(array $params)
|
||||||
@@ -343,6 +355,41 @@ class ExamRepository extends BaseRepository
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function initProgress($examUser, $user = null)
|
||||||
|
{
|
||||||
|
if (!$examUser instanceof ExamUser) {
|
||||||
|
$examUser = ExamUser::query()->findOrFail((int)$examUser);
|
||||||
|
}
|
||||||
|
$exam = $examUser->exam;
|
||||||
|
if (!$user instanceof User) {
|
||||||
|
$user = $examUser->user()->select(['id', 'uploaded', 'downloaded', 'seedtime', 'leechtime', 'seedbonus'])->first();
|
||||||
|
}
|
||||||
|
$insert = [
|
||||||
|
'uid' => $user->id,
|
||||||
|
'exam_id' => $exam->id,
|
||||||
|
];
|
||||||
|
foreach ($exam->indexes as $key => $index) {
|
||||||
|
if (!isset($index['checked']) || !$index['checked']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$insert['index'] = $index['index'];
|
||||||
|
if ($index['index'] == Exam::INDEX_UPLOADED) {
|
||||||
|
$insert['value'] = $user->uploaded;
|
||||||
|
} elseif ($index['index'] == Exam::INDEX_DOWNLOADED) {
|
||||||
|
$insert['value'] = $user->downloaded;
|
||||||
|
} elseif ($index['index'] == Exam::INDEX_SEED_BONUS) {
|
||||||
|
$insert['value'] = $user->seedbonus;
|
||||||
|
} elseif ($index['index'] == Exam::INDEX_SEED_TIME_AVERAGE) {
|
||||||
|
$insert['value'] = 0;
|
||||||
|
} else {
|
||||||
|
throw new \RuntimeException("Unknown index: {$index['index']}");
|
||||||
|
}
|
||||||
|
ExamIndexInitValue::query()->insert($insert);
|
||||||
|
do_log("insert: " . json_encode($insert));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUserExamProgress($uid, $status = null, $with = ['exam', 'user'])
|
public function getUserExamProgress($uid, $status = null, $with = ['exam', 'user'])
|
||||||
{
|
{
|
||||||
$logPrefix = "uid: $uid";
|
$logPrefix = "uid: $uid";
|
||||||
@@ -449,7 +496,9 @@ class ExamRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
$examUser = ExamUser::query()->findOrFail($examUserId);
|
$examUser = ExamUser::query()->findOrFail($examUserId);
|
||||||
$result = DB::transaction(function () use ($examUser) {
|
$result = DB::transaction(function () use ($examUser) {
|
||||||
$examUser->progresses()->delete();
|
do {
|
||||||
|
$deleted = $examUser->progresses()->limit(10000)->delete();
|
||||||
|
} while ($deleted > 0);
|
||||||
return $examUser->delete();
|
return $examUser->delete();
|
||||||
});
|
});
|
||||||
return $result;
|
return $result;
|
||||||
@@ -457,11 +506,18 @@ class ExamRepository extends BaseRepository
|
|||||||
|
|
||||||
public function avoidExamUser(int $examUserId)
|
public function avoidExamUser(int $examUserId)
|
||||||
{
|
{
|
||||||
$examUser = ExamUser::query()->findOrFail($examUserId);
|
$examUser = ExamUser::query()->where('status',ExamUser::STATUS_NORMAL)->findOrFail($examUserId);
|
||||||
$result = $examUser->update(['status' => ExamUser::STATUS_AVOIDED]);
|
$result = $examUser->update(['status' => ExamUser::STATUS_AVOIDED]);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function recoverExamUser(int $examUserId)
|
||||||
|
{
|
||||||
|
$examUser = ExamUser::query()->where('status',ExamUser::STATUS_AVOIDED)->findOrFail($examUserId);
|
||||||
|
$result = $examUser->update(['status' => ExamUser::STATUS_NORMAL]);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public function cronjonAssign()
|
public function cronjonAssign()
|
||||||
{
|
{
|
||||||
$exams = $this->listValid(null, Exam::DISCOVERED_YES);
|
$exams = $this->listValid(null, Exam::DISCOVERED_YES);
|
||||||
@@ -523,17 +579,16 @@ class ExamRepository extends BaseRepository
|
|||||||
// do_log("$currentLogPrefix, exam not match this user.");
|
// do_log("$currentLogPrefix, exam not match this user.");
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
$insert[] = [
|
$insert = [
|
||||||
'uid' => $user->id,
|
'uid' => $user->id,
|
||||||
'exam_id' => $exam->id,
|
'exam_id' => $exam->id,
|
||||||
'created_at' => $now,
|
'created_at' => $now,
|
||||||
'updated_at' => $now,
|
'updated_at' => $now,
|
||||||
];
|
];
|
||||||
do_log("$currentLogPrefix, exam will be assigned to this user.");
|
do_log("$currentLogPrefix, exam will be assigned to this user.");
|
||||||
}
|
$examUser = ExamUser::query()->create($insert);
|
||||||
if (!empty($insert)) {
|
$this->initProgress($examUser, $user);
|
||||||
$result += count($insert);
|
$result++;
|
||||||
ExamUser::query()->insert($insert);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateExamIndexInitValuesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('exam_index_init_values', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->integer('uid')->index();
|
||||||
|
$table->integer('exam_user_id');
|
||||||
|
$table->integer('exam_id')->index();
|
||||||
|
$table->integer('index')->index();
|
||||||
|
$table->bigInteger('value');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->unique(['exam_user_id', 'exam_id', 'index']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('exam_index_init_values');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,7 @@ Route::group(['middleware' => ['auth:sanctum', 'permission', 'locale']], functio
|
|||||||
|
|
||||||
Route::resource('exam-users', \App\Http\Controllers\ExamUserController::class);
|
Route::resource('exam-users', \App\Http\Controllers\ExamUserController::class);
|
||||||
Route::put('exam-users-avoid', [\App\Http\Controllers\ExamUserController::class, 'avoid']);
|
Route::put('exam-users-avoid', [\App\Http\Controllers\ExamUserController::class, 'avoid']);
|
||||||
|
Route::put('exam-users-recover', [\App\Http\Controllers\ExamUserController::class, 'recover']);
|
||||||
|
|
||||||
Route::get('dashboard/system-info', [\App\Http\Controllers\DashboardController::class, 'systemInfo']);
|
Route::get('dashboard/system-info', [\App\Http\Controllers\DashboardController::class, 'systemInfo']);
|
||||||
Route::get('dashboard/stat-data', [\App\Http\Controllers\DashboardController::class, 'statData']);
|
Route::get('dashboard/stat-data', [\App\Http\Controllers\DashboardController::class, 'statData']);
|
||||||
|
|||||||
Reference in New Issue
Block a user