master
cody 3 weeks ago
parent e00dd15e29
commit 7712f27714

@ -27,15 +27,15 @@ class ScheduleOverviewController extends CommonController
$year = request('year', date('Y')); $year = request('year', date('Y'));
return $this->success([ return $this->success([
'systems' => $this->getSystems(), 'systems' => $this->getSystems($year),
'courses' => $this->getCourses(), 'courses' => $this->getCourses($year),
'schedules' => $this->getSchedules($year), 'schedules' => $this->getSchedules($year),
]); ]);
} }
public function systemIndex() public function systemIndex()
{ {
return $this->success($this->getSystems()); return $this->success($this->getSystems(request('year', date('Y'))));
} }
public function systemShow() public function systemShow()
@ -63,9 +63,11 @@ class ScheduleOverviewController extends CommonController
{ {
$all = request()->all(); $all = request()->all();
$validator = Validator::make($all, [ $validator = Validator::make($all, [
'year' => 'required|string|size:4',
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'sort' => 'nullable|integer', 'sort' => 'nullable|integer',
], [ ], [
'year.required' => '年份必填',
'name.required' => '体系名称必填', 'name.required' => '体系名称必填',
]); ]);
@ -86,6 +88,7 @@ class ScheduleOverviewController extends CommonController
DB::beginTransaction(); DB::beginTransaction();
try { try {
$model->year = $all['year'];
$model->name = $all['name']; $model->name = $all['name'];
$model->sort = (int) ($all['sort'] ?? 0); $model->sort = (int) ($all['sort'] ?? 0);
$model->save(); $model->save();
@ -136,7 +139,7 @@ class ScheduleOverviewController extends CommonController
public function courseIndex() public function courseIndex()
{ {
return $this->success($this->getCourses()); return $this->success($this->getCourses(request('year', date('Y'))));
} }
public function courseShow() public function courseShow()
@ -313,6 +316,10 @@ class ScheduleOverviewController extends CommonController
return $this->fail([ResponseCode::ERROR_BUSINESS, '课程不属于当前体系']); return $this->fail([ResponseCode::ERROR_BUSINESS, '课程不属于当前体系']);
} }
if ((string) $system->year !== (string) $all['year']) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '体系不属于当前年份']);
}
if (!empty($all['id'])) { if (!empty($all['id'])) {
$model = $this->scheduleModel->find($all['id']); $model = $this->scheduleModel->find($all['id']);
if (empty($model)) { if (empty($model)) {
@ -366,18 +373,22 @@ class ScheduleOverviewController extends CommonController
return $this->success('删除成功'); return $this->success('删除成功');
} }
protected function getSystems() protected function getSystems($year)
{ {
return $this->systemModel return $this->systemModel
->where('year', $year)
->orderBy('sort') ->orderBy('sort')
->orderBy('id') ->orderBy('id')
->get(); ->get();
} }
protected function getCourses() protected function getCourses($year)
{ {
return $this->courseModel return $this->courseModel
->with('system') ->with('system')
->whereHas('system', function ($query) use ($year) {
$query->where('year', $year);
})
->orderBy('sort') ->orderBy('sort')
->orderBy('id') ->orderBy('id')
->get(); ->get();

@ -13,12 +13,15 @@ return new class extends Migration
{ {
Schema::create('schedule_overview_systems', function (Blueprint $table) { Schema::create('schedule_overview_systems', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('year', 4)->comment('年份');
$table->string('name')->comment('体系名称'); $table->string('name')->comment('体系名称');
$table->integer('sort')->default(0)->comment('排序'); $table->integer('sort')->default(0)->comment('排序');
$table->bigInteger('admin_id')->nullable()->comment('创建管理员'); $table->bigInteger('admin_id')->nullable()->comment('创建管理员');
$table->bigInteger('department_id')->nullable()->comment('部门ID'); $table->bigInteger('department_id')->nullable()->comment('部门ID');
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->index('year');
}); });
Schema::create('schedule_overview_courses', function (Blueprint $table) { Schema::create('schedule_overview_courses', function (Blueprint $table) {

@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (!Schema::hasTable('schedule_overview_systems')) {
return;
}
Schema::table('schedule_overview_systems', function (Blueprint $table) {
if (!Schema::hasColumn('schedule_overview_systems', 'year')) {
$table->string('year', 4)->default(date('Y'))->after('id')->comment('年份');
$table->index('year');
}
});
DB::table('schedule_overview_systems')
->whereNull('year')
->orWhere('year', '')
->update(['year' => date('Y')]);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
if (!Schema::hasTable('schedule_overview_systems') || !Schema::hasColumn('schedule_overview_systems', 'year')) {
return;
}
Schema::table('schedule_overview_systems', function (Blueprint $table) {
$table->dropIndex(['year']);
$table->dropColumn('year');
});
}
};
Loading…
Cancel
Save