diff --git a/app/Http/Controllers/Admin/CourseController.php b/app/Http/Controllers/Admin/CourseController.php index f7b8e31..4edcf29 100755 --- a/app/Http/Controllers/Admin/CourseController.php +++ b/app/Http/Controllers/Admin/CourseController.php @@ -58,91 +58,107 @@ class CourseController extends BaseController { $all = request()->all(); $list = $this->model->with(underlineToHump($all['show_relation'] ?? [])) - ->withCount(['courseSigns' => function ($query) { - $query->whereNotIn('status', [4, 5]); - }])->withCount(['courseSigns as sign_pass_total' => function ($query) { - $query->where('status', 1)->whereHas('user'); - }])->withCount(['courseSigns as sign_wait_total' => function ($query) { - $query->where('status', 0)->whereHas('user'); - }])->withCount(['courseSigns as sign_fault_total' => function ($query) { - $query->where('status', 2)->whereHas('user'); - }])->withCount(['courseSigns as sign_prepare_total' => function ($query) { - $query->where('status', 3)->whereHas('user'); - }])->withCount(['courseSigns as sign_cancel_total' => function ($query) { - $query->where('status', 4)->whereHas('user'); - }])->withCount(['courseSigns as sign_give_up_total' => function ($query) { - $query->where('status', 5)->whereHas('user'); - }])->withCount(['courseSigns as sign_black_total' => function ($query) { - $query->where('status', 6)->whereHas('user'); - }])->where(function ($query) use ($all) { - if (isset($all['has_course_forms']) && !empty($all['has_course_forms'])) { - $query->whereHas('courseForms'); + ->withCount([ + 'courseSigns' => function ($query) { + $query->whereNotIn('status', [4, 5]); } - if (isset($all['start_date'])) { - $query->where('start_date', '>=', $all['start_date']); - } - if (isset($all['end_date'])) { - $query->where('end_date', '<=', $all['end_date']); - } - if (isset($all['course_type_id'])) { - $course_type_id = explode(',', $all['course_type_id']); - $query->whereIn('type', $course_type_id); - } - if (isset($all['filter']) && !empty($all['filter'])) { - foreach ($all['filter'] as $condition) { - $key = $condition['key'] ?? null; - $op = $condition['op'] ?? null; - $value = $condition['value'] ?? null; - if (!isset($key) || !isset($op) || !isset($value)) { - continue; - } - // 等于 - if ($op == 'eq') { - $query->where($key, $value); - } - // 不等于 - if ($op == 'neq') { - $query->where($key, '!=', $value); - } - // 大于 - if ($op == 'gt') { - $query->where($key, '>', $value); - } - // 大于等于 - if ($op == 'egt') { - $query->where($key, '>=', $value); - } - // 小于 - if ($op == 'lt') { - $query->where($key, '<', $value); - } - // 小于等于 - if ($op == 'elt') { - $query->where($key, '<=', $value); - } - // 模糊搜索 - if ($op == 'like') { - $query->where($key, 'like', '%' . $value . '%'); - } - // 否定模糊搜索 - if ($op == 'notlike') { - $query->where($key, 'not like', '%' . $value . '%'); - } - // 范围搜索 - if ($op == 'range') { - list($from, $to) = explode(',', $value); - if (empty($from) || empty($to)) { + ])->withCount([ + 'courseSigns as sign_pass_total' => function ($query) { + $query->where('status', 1)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_wait_total' => function ($query) { + $query->where('status', 0)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_fault_total' => function ($query) { + $query->where('status', 2)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_prepare_total' => function ($query) { + $query->where('status', 3)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_cancel_total' => function ($query) { + $query->where('status', 4)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_give_up_total' => function ($query) { + $query->where('status', 5)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_black_total' => function ($query) { + $query->where('status', 6)->whereHas('user'); + } + ])->where(function ($query) use ($all) { + if (isset($all['has_course_forms']) && !empty($all['has_course_forms'])) { + $query->whereHas('courseForms'); + } + if (isset($all['start_date'])) { + $query->where('start_date', '>=', $all['start_date']); + } + if (isset($all['end_date'])) { + $query->where('end_date', '<=', $all['end_date']); + } + if (isset($all['course_type_id'])) { + $course_type_id = explode(',', $all['course_type_id']); + $query->whereIn('type', $course_type_id); + } + if (isset($all['filter']) && !empty($all['filter'])) { + foreach ($all['filter'] as $condition) { + $key = $condition['key'] ?? null; + $op = $condition['op'] ?? null; + $value = $condition['value'] ?? null; + if (!isset($key) || !isset($op) || !isset($value)) { continue; } - $query->whereBetween($key, [$from, $to]); - } - if ($op == 'in') { - $array = explode(',', $value); - $query->whereIn($key, $array); + // 等于 + if ($op == 'eq') { + $query->where($key, $value); + } + // 不等于 + if ($op == 'neq') { + $query->where($key, '!=', $value); + } + // 大于 + if ($op == 'gt') { + $query->where($key, '>', $value); + } + // 大于等于 + if ($op == 'egt') { + $query->where($key, '>=', $value); + } + // 小于 + if ($op == 'lt') { + $query->where($key, '<', $value); + } + // 小于等于 + if ($op == 'elt') { + $query->where($key, '<=', $value); + } + // 模糊搜索 + if ($op == 'like') { + $query->where($key, 'like', '%' . $value . '%'); + } + // 否定模糊搜索 + if ($op == 'notlike') { + $query->where($key, 'not like', '%' . $value . '%'); + } + // 范围搜索 + if ($op == 'range') { + list($from, $to) = explode(',', $value); + if (empty($from) || empty($to)) { + continue; + } + $query->whereBetween($key, [$from, $to]); + } + if ($op == 'in') { + $array = explode(',', $value); + $query->whereIn($key, $array); + } } } - } - }); + }); $list = $list->orderBy($all['sort_name'] ?? 'sign_status', $all['sort_type'] ?? 'asc'); if (isset($all['is_export']) && !empty($all['is_export'])) { $list = $list->limit(5000)->get()->toArray(); @@ -219,6 +235,8 @@ class CourseController extends BaseController * @OA\Parameter(name="latitude", in="query", @OA\Schema(type="string"), description="纬度"), * @OA\Parameter(name="address_detail", in="query", @OA\Schema(type="string"), description="详细地址"), * @OA\Parameter(name="url_title", in="query", @OA\Schema(type="string"), description="链接地址"), + * @OA\Parameter(name="is_ganbu", in="query", @OA\Schema(type="integer"), description="是否干部课程-0否1是"), + * @OA\Parameter(name="is_chart", in="query", @OA\Schema(type="integer"), description="是否参与统计-0否1是,默认1"), * @OA\Response( * response=200, * description="操作成功" diff --git a/app/Http/Controllers/Admin/TimeEventController.php b/app/Http/Controllers/Admin/TimeEventController.php new file mode 100644 index 0000000..8ab2990 --- /dev/null +++ b/app/Http/Controllers/Admin/TimeEventController.php @@ -0,0 +1,219 @@ +all(); + $list = $this->model->where(function ($query) use ($all) { + if (isset($all['filter']) && !empty($all['filter'])) { + foreach ($all['filter'] as $condition) { + $key = $condition['key'] ?? null; + $op = $condition['op'] ?? null; + $value = $condition['value'] ?? null; + if (!isset($key) || !isset($op) || !isset($value)) { + continue; + } + // 等于 + if ($op == 'eq') { + $query->where($key, $value); + } + // 不等于 + if ($op == 'neq') { + $query->where($key, '!=', $value); + } + // 大于 + if ($op == 'gt') { + $query->where($key, '>', $value); + } + // 大于等于 + if ($op == 'egt') { + $query->where($key, '>=', $value); + } + // 小于 + if ($op == 'lt') { + $query->where($key, '<', $value); + } + // 小于等于 + if ($op == 'elt') { + $query->where($key, '<=', $value); + } + // 模糊搜索 + if ($op == 'like') { + $query->where($key, 'like', '%' . $value . '%'); + } + // 否定模糊搜索 + if ($op == 'notlike') { + $query->where($key, 'not like', '%' . $value . '%'); + } + // 范围搜索 + if ($op == 'range') { + list($from, $to) = explode(',', $value); + if (empty($from) || empty($to)) { + continue; + } + $query->whereBetween($key, [$from, $to]); + } + } + } + })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc'); + if (isset($all['is_export']) && !empty($all['is_export'])) { + $list = $list->get()->toArray(); + $export_fields = $all['export_fields'] ?? []; + // 导出文件名字 + $tableName = $this->model->getTable(); + $filename = (new CustomForm())->getTableComment($tableName); + return Excel::download(new BaseExport($export_fields, $list, $tableName), $filename . date('YmdHis') . '.xlsx'); + } else { + // 输出 + $list = $list->paginate($all['page_size'] ?? 20); + } + return $this->success($list); + } + + /** + * @OA\Get( + * path="/api/admin/time-event/show", + * tags={"时间轴"}, + * summary="详情", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="show_relation", in="query", @OA\Schema(type="string"), required=false, description="需要输出的关联关系数组,填写输出指定数据"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public function show() + { + $all = \request()->all(); + $messages = [ + 'id.required' => 'Id必填', + ]; + $validator = Validator::make($all, [ + 'id' => 'required' + ], $messages); + if ($validator->fails()) { + return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); + } + $detail = $this->model->find($all['id']); + return $this->success($detail); + } + + /** + * @OA\Post( + * path="/api/admin/time-event/save", + * tags={"时间轴"}, + * summary="保存", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="int"), required=true, description="Id(存在更新,不存在新增)"), + * @OA\Parameter(name="title", in="query", @OA\Schema(type="string", nullable=true), description="标题"), + * @OA\Parameter(name="content", in="query", @OA\Schema(type="string", nullable=true), description="内容"), + * @OA\Parameter(name="type", in="query", @OA\Schema(type="string", nullable=true), description="类型1校友动态2业界动态"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="认证token"), + * @OA\Response( + * response="200", + * description="操作成功" + * ) + * ) + */ + public function save() + { + $all = \request()->all(); + DB::beginTransaction(); + try { + if (isset($all['id'])) { + $model = $this->model->find($all['id']); + if (empty($model)) { + return $this->fail([ResponseCode::ERROR_BUSINESS, '数据不存在']); + } + } else { + $model = $this->model; + $all['admin_id'] = $this->getUserId(); + $all['department_id'] = $this->getUser()->department_id; + } + $original = $model->getOriginal(); + $model->fill($all); + $model->save(); + DB::commit(); + return $this->success($model); + } catch (\Exception $exception) { + DB::rollBack(); + return $this->fail([$exception->getCode(), $exception->getMessage()]); + } + } + + /** + * @OA\Get( + * path="/api/admin/time-event/destroy", + * tags={"时间轴"}, + * summary="删除", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public function destroy() + { + return parent::destroy(); + } + +} diff --git a/app/Models/TimeEvent.php b/app/Models/TimeEvent.php new file mode 100644 index 0000000..00b36da --- /dev/null +++ b/app/Models/TimeEvent.php @@ -0,0 +1,7 @@ +tinyInteger('is_ganbu')->nullable()->default(0)->comment('是否干部课程-0否1是'); + $table->tinyInteger('is_chart')->nullable()->default(1)->comment('是否参与统计-0否1是'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('courses', function (Blueprint $table) { + $table->dropColumn(['is_ganbu', 'is_chart']); + }); + } +}; diff --git a/database/migrations/2025_11_18_162248_create_time_events_table.php b/database/migrations/2025_11_18_162248_create_time_events_table.php new file mode 100644 index 0000000..3010364 --- /dev/null +++ b/database/migrations/2025_11_18_162248_create_time_events_table.php @@ -0,0 +1,35 @@ +id(); + $table->string('title')->comment('标题'); + $table->date('date')->nullable()->comment('日期'); + $table->integer('sort')->default(0)->comment('排序'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('time_events'); + } +}; diff --git a/routes/api.php b/routes/api.php index f4e213b..d3f0a59 100755 --- a/routes/api.php +++ b/routes/api.php @@ -246,6 +246,12 @@ Route::group(["namespace" => "Admin", "prefix" => "admin"], function () { Route::get('article/show', [\App\Http\Controllers\Admin\ArticleController::class, "show"]); Route::post('article/save', [\App\Http\Controllers\Admin\ArticleController::class, "save"]); Route::get('article/destroy', [\App\Http\Controllers\Admin\ArticleController::class, "destroy"]); + + // 时间轴管理 + Route::get('time-event/index', [\App\Http\Controllers\Admin\TimeEventController::class, "index"]); + Route::get('time-event/show', [\App\Http\Controllers\Admin\TimeEventController::class, "show"]); + Route::post('time-event/save', [\App\Http\Controllers\Admin\TimeEventController::class, "save"]); + Route::get('time-event/destroy', [\App\Http\Controllers\Admin\TimeEventController::class, "destroy"]); }); });