diff --git a/app/Admin/Controllers/FeedbackController.php b/app/Admin/Controllers/FeedbackController.php new file mode 100644 index 0000000..e4bc224 --- /dev/null +++ b/app/Admin/Controllers/FeedbackController.php @@ -0,0 +1,29 @@ +baseCRUD() + ->filterTogglable(false) + ->columnsTogglable(false) + ->headerToolbar([]) + ->columns([ + amisMake()->TableColumn()->name('id')->label(__('banner.id')), + amisMake()->TableColumn()->name('content')->label(__('feedback.content')), + $this->rowActions([ + $this->rowDeleteButton() + ]), + ]); + + return $this->baseList($crud); + } +} diff --git a/app/Admin/Controllers/PartyCateController.php b/app/Admin/Controllers/PartyCateController.php index aa95252..614165e 100644 --- a/app/Admin/Controllers/PartyCateController.php +++ b/app/Admin/Controllers/PartyCateController.php @@ -69,6 +69,7 @@ class PartyCateController extends AdminController amisMake()->TableColumn()->name('name')->label(__('party_cate.name')), amisMake()->TableColumn()->name('master.name')->label(__('party_cate.master_id')), amisMake()->TableColumn()->name('plan.name')->label(__('party_cate.plan_id')), + amisMake()->TableColumn()->name('current_score')->label(__('party_cate.current_score')), amisMake()->TableColumn()->name('score')->label(__('party_cate.score')), amisMake()->TableColumn()->name('remarks')->label(__('party_cate.remarks')), $this->rowActions([ @@ -116,6 +117,7 @@ class PartyCateController extends AdminController amisMake()->TextControl()->name('master.name')->label(__('party_cate.master_id'))->static(), amisMake()->TextControl()->name('plan.name')->label(__('party_cate.plan_id'))->static(), amisMake()->TextControl()->name('remarks')->label(__('party_cate.remarks'))->static(), + amisMake()->TextControl()->name('current_score')->label(__('party_cate.current_score'))->static(), amisMake()->TextControl()->name('score')->label(__('party_cate.score'))->static(), amisMake()->TextControl()->name('scores')->label(__('party_cate.scores'))->static()->staticSchema(amisMake()->Json()), amisMake()->TextControl()->name('created_at')->label(__('party_cate.created_at'))->static(), @@ -154,6 +156,7 @@ class PartyCateController extends AdminController amisMake()->TableColumn()->name('id')->label(__('party_user.id')), amisMake()->TableColumn()->name('name')->label(__('party_user.name')), amisMake()->TableColumn()->set('type', 'avatar')->set('src', '${avatar}')->name('avatar')->label(__('party_user.avatar')), + amisMake()->TableColumn()->name('current_score')->label(__('party_user.current_score')), amisMake()->TableColumn()->name('score')->label(__('party_user.score')), $userController->rowActions([ amisMake()->DialogAction()->label(__('admin.show'))->icon('fa-regular fa-eye')->level('link')->dialog( diff --git a/app/Admin/Controllers/PartyUserController.php b/app/Admin/Controllers/PartyUserController.php index c56b03a..8e53e12 100644 --- a/app/Admin/Controllers/PartyUserController.php +++ b/app/Admin/Controllers/PartyUserController.php @@ -35,6 +35,7 @@ class PartyUserController extends AdminController amisMake()->TableColumn()->name('name')->label(__('party_user.name')), amisMake()->TableColumn()->type('avatar')->src('${avatar}')->name('avatar')->label(__('party_user.avatar')), amisMake()->TableColumn()->name('cate.name')->label(__('party_user.cate_id')), + amisMake()->TableColumn()->name('current_score')->label(__('party_user.current_score')), amisMake()->TableColumn()->name('score')->label(__('party_user.score')), $this->rowActions([ $this->rowShowButton(), @@ -66,6 +67,7 @@ class PartyUserController extends AdminController amisMake()->TextControl()->name('username')->label(__('party_user.username'))->static(), amisMake()->TextControl()->name('name')->label(__('party_user.name'))->static(), amisMake()->TextControl()->name('avatar')->label(__('party_user.avatar'))->static()->staticSchema(amisMake()->Image()), + amisMake()->TextControl()->name('current_score')->label(__('party_cate.current_score'))->static(), amisMake()->TextControl()->name('score')->label(__('party_cate.score'))->static(), amisMake()->TextControl()->name('scores')->label(__('party_cate.scores'))->static()->staticSchema(amisMake()->Json()), amisMake()->TextControl()->name('remarks')->label(__('party_cate.remarks'))->static(), diff --git a/app/Admin/Services/FeedbackService.php b/app/Admin/Services/FeedbackService.php new file mode 100644 index 0000000..e778130 --- /dev/null +++ b/app/Admin/Services/FeedbackService.php @@ -0,0 +1,14 @@ +update([ 'score' => $info->score + $score, + 'current_score' => $info->current_score + $score, 'scores' => $scores, ]); } diff --git a/app/Admin/Services/PartyUserService.php b/app/Admin/Services/PartyUserService.php index d8b3115..12c7604 100644 --- a/app/Admin/Services/PartyUserService.php +++ b/app/Admin/Services/PartyUserService.php @@ -78,6 +78,7 @@ class PartyUserService extends BaseService } $user->update([ 'score' => $user->score + $score, + 'current_score' => $user->current_score + $score, 'scores' => $scores, ]); diff --git a/app/Admin/routes.php b/app/Admin/routes.php index a48a868..e48c149 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -56,4 +56,6 @@ Route::group([ $router->resource('user-rank', \App\Admin\Controllers\UserRankController::class)->names('admin.user_rank'); // 党支部排名 $router->resource('cate-rank', \App\Admin\Controllers\CateRankController::class)->names('admin.cate_rank'); + + $router->resource('feedback', \App\Admin\Controllers\FeedbackController::class)->names('admin.feedback'); }); diff --git a/app/Console/Commands/CateRank.php b/app/Console/Commands/CateRank.php index 6aea1ae..78975bb 100644 --- a/app/Console/Commands/CateRank.php +++ b/app/Console/Commands/CateRank.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Models\UserScore; +use App\Models\PartyCate; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; use App\Models\CateRank as CateRankModel; @@ -50,5 +51,9 @@ class CateRank extends Command ]; } CateRankModel::insert($list); + // 清空党支部当前得分 + PartyCate::update([ + 'current_score' => 0 + ]); } } diff --git a/app/Console/Commands/UserRank.php b/app/Console/Commands/UserRank.php index 790d747..7356c58 100644 --- a/app/Console/Commands/UserRank.php +++ b/app/Console/Commands/UserRank.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Models\PartyUser; use App\Models\UserScore; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; @@ -53,5 +54,9 @@ class UserRank extends Command ]; } UserRankModel::insert($list); + // 清空党员当前得分 + PartyUser::update([ + 'current_score' => 0 + ]); } } diff --git a/app/Http/Controllers/Api/AccountController.php b/app/Http/Controllers/Api/AccountController.php new file mode 100644 index 0000000..450be21 --- /dev/null +++ b/app/Http/Controllers/Api/AccountController.php @@ -0,0 +1,36 @@ +user(); + + return $this->response()->success($user); + } + + public function update(Request $request) + { + $user = auth('api')->user(); + $service = PartyUserService::make(); + if ($service->update($user->id, $request->all())) { + return $this->response()->success('保存成功'); + } + return $this->response()->fail($service->getError()); + } + + public function logout() + { + $user = auth('api')->user(); + + $user->currentAccessToken()->delete(); + + return $this->response()->success(); + } +} diff --git a/app/Http/Controllers/Api/AuthController.php b/app/Http/Controllers/Api/AuthController.php new file mode 100644 index 0000000..aefe9a9 --- /dev/null +++ b/app/Http/Controllers/Api/AuthController.php @@ -0,0 +1,49 @@ +validate([ + 'username' => 'required', + 'password' => 'required', + ]); + + $user = PartyUser::where('username', $request->input('username'))->first(); + if (!Hash::check($request->input('password'), $user->password)) { + throw new BaseException('用户名或密码错误'); + } + // 更新第三方账户 + // $openid = $request->input('openid'); + // $open_type = $request->input('open_type'); + // if ($openid && $open_type) { + // $this->updateUserSocialite($user, $openid, SocialiteType::from($open_type)); + // } + $token = $user->createToken('client')->plainTextToken; + return $this->response()->success(['token' => $token, 'user' => $user]); + } + + // protected function updateUserSocialite($user, $openid, $type) + // { + // // 清空以前绑定的 + // UserSocialite::where([ + // 'type' => $type, + // 'user_type' => $user->getMorphClass(), + // 'user_id' => $user->id, + // ])->update(['user_id' => null]); + // UserSocialite::updateOrCreate([ + // 'type' => $type, + // 'user_type' => $user->getMorphClass(), + // 'openid' => $openid, + // ], [ + // 'user_id' => $user->id, + // ]); + // } +} diff --git a/app/Http/Controllers/Api/KeywordController.php b/app/Http/Controllers/Api/KeywordController.php new file mode 100644 index 0000000..806f56b --- /dev/null +++ b/app/Http/Controllers/Api/KeywordController.php @@ -0,0 +1,18 @@ +all())->get(); + + return $this->response()->success(KeywordResource::collection($list)); + } +} diff --git a/app/Http/Controllers/Web/AuthController.php b/app/Http/Controllers/Web/AuthController.php deleted file mode 100644 index 7057cb1..0000000 --- a/app/Http/Controllers/Web/AuthController.php +++ /dev/null @@ -1,40 +0,0 @@ -validate([ - 'username' => 'required', - 'password' => 'required' - ]); - - $auth = $this->guard(); - $user = PartyUser::where('username', $request->input('username'))->first(); - if ($user && Hash::check($request->input('password'), $user->getRawOriginal('password'))) { - $auth->login($user); - return back()->with('flash_message', '登录成功'); - } - - return back()->withErrors('用户名或密码错误')->withInput(['username' => $request->input('username')]); - } - - public function logout() - { - $this->guard()->logout(); - return back()->with('flash_message', '已退出'); - } - - protected function guard() - { - return Auth::guard('web'); - } -} diff --git a/app/Http/Resources/KeywordResource.php b/app/Http/Resources/KeywordResource.php new file mode 100644 index 0000000..f58db4d --- /dev/null +++ b/app/Http/Resources/KeywordResource.php @@ -0,0 +1,32 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->id, + 'key' => $this->key, + 'value' => $this->value, + 'parent_id' => $this->parent_id, + 'sort' => $this->sort, + 'level' => $this->level, + 'options' => $this->options, + 'image' => $this->image, + 'images' => $this->images, + 'description' => $this->description, + 'content' => $this->content, + ]; + } +} diff --git a/app/Models/Feedback.php b/app/Models/Feedback.php new file mode 100644 index 0000000..ac24bae --- /dev/null +++ b/app/Models/Feedback.php @@ -0,0 +1,16 @@ + 'array' diff --git a/app/Models/PartyUser.php b/app/Models/PartyUser.php index 3eb7957..b61f55f 100644 --- a/app/Models/PartyUser.php +++ b/app/Models/PartyUser.php @@ -15,7 +15,7 @@ class PartyUser extends Authenticatable { use HasDateTimeFormatter, Filterable, HasApiTokens; - protected $fillable = ['username', 'password', 'name', 'avatar', 'cate_id', 'remarks', 'score', 'scores']; + protected $fillable = ['username', 'password', 'name', 'avatar', 'cate_id', 'remarks', 'current_score', 'score', 'scores']; protected $hidden = ['password']; diff --git a/config/admin.php b/config/admin.php index f0a5fae..815931c 100644 --- a/config/admin.php +++ b/config/admin.php @@ -4,7 +4,7 @@ use Illuminate\Support\Str; return [ // 应用名称 - 'name' => 'Owl Admin', + 'name' => '五星党建', // 应用 logo 'logo' => '/admin/logo.png', @@ -66,7 +66,7 @@ return [ 'layout' => [ // 浏览器标题, 功能名称使用 %title% 代替 - 'title' => '%title% | OwlAdmin', + 'title' => '%title% | 五星党建', 'header' => [ // 是否显示 [刷新] 按钮 'refresh' => true, diff --git a/database/migrations/2023_12_01_140938_create_user_scores_table.php b/database/migrations/2023_12_01_140938_create_user_scores_table.php index 823aabf..328f1e6 100644 --- a/database/migrations/2023_12_01_140938_create_user_scores_table.php +++ b/database/migrations/2023_12_01_140938_create_user_scores_table.php @@ -30,11 +30,13 @@ return new class extends Migration }); Schema::table('party_users', function (Blueprint $table) { + $table->unsignedInteger('current_score')->default(0)->comment('当前得分'); $table->unsignedInteger('score')->default(0)->comment('累计得分'); $table->json('scores')->nullable()->comment('每项得分{score_cate_1: 10}'); }); Schema::table('party_cates', function (Blueprint $table) { + $table->unsignedInteger('current_score')->default(0)->comment('累计得分'); $table->unsignedInteger('score')->default(0)->comment('累计得分'); $table->json('scores')->nullable()->comment('每项得分{score_cate_1: 10}'); }); diff --git a/database/migrations/2023_12_06_093223_create_feedbacks_table.php b/database/migrations/2023_12_06_093223_create_feedbacks_table.php new file mode 100644 index 0000000..fa7a6d2 --- /dev/null +++ b/database/migrations/2023_12_06_093223_create_feedbacks_table.php @@ -0,0 +1,30 @@ +id(); + $table->text('content'); + $table->timestamps(); + + $table->comment('意见反馈'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('feedback'); + } +}; diff --git a/database/seeders/AdminMenuSeeder.php b/database/seeders/AdminMenuSeeder.php index 0b8fac6..163a553 100644 --- a/database/seeders/AdminMenuSeeder.php +++ b/database/seeders/AdminMenuSeeder.php @@ -28,6 +28,7 @@ class AdminMenuSeeder extends Seeder ['title' => '广告管理', 'icon' => 'icon-park:picture-one', 'url' => '/banner', 'permission' => ['banner']], ['title' => '支部排名', 'icon' => 'icon-park:sort-one', 'url' => '/cate-rank', 'permission' => ['cate-rank']], ['title' => '个人排名', 'icon' => 'icon-park:sort-one', 'url' => '/user-rank', 'permission' => ['user-rank']], + ['title' => '书记信箱', 'icon' => 'icon-park:comment', 'url' => '/feedback', 'permission' => ['feedback']], ['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'permission' => ['system'], 'children' => [ ['title' => '用户管理', 'icon' => 'icon-park:people-plus', 'url' => '/system/admin_users', 'permission' => ['admin_user']], ['title' => '角色管理', 'icon' => 'icon-park:people-plus-one', 'url' => '/system/admin_roles', 'permission' => ['admin_rule']], diff --git a/database/seeders/PartyUserSeeder.php b/database/seeders/PartyUserSeeder.php index 8e2565e..0a32b64 100644 --- a/database/seeders/PartyUserSeeder.php +++ b/database/seeders/PartyUserSeeder.php @@ -23,7 +23,7 @@ class PartyUserSeeder extends Seeder (new PartyCateFactory())->count(20)->create(); (new PartyUserFactory())->count(100)->create(); - UserScore::truncate(); - UserScore::factory()->count(100)->create(); + // UserScore::truncate(); + // UserScore::factory()->count(100)->create(); } } diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php index 037e98a..f76b069 100644 --- a/database/seeders/PermissionSeeder.php +++ b/database/seeders/PermissionSeeder.php @@ -28,6 +28,7 @@ class PermissionSeeder extends Seeder ['name' => '广告管理', 'slug' => 'banner'], ['name' => '党员排名', 'slug' => 'user_rank'], ['name' => '支部排名', 'slug' => 'cate_rank'], + ['name' => '书记信箱', 'slug' => 'feedback'], ['name' => '系统管理', 'slug' => 'system', 'children' => [ ['name' => '用户管理', 'slug' => 'admin_user'], ['name' => '角色管理', 'slug' => 'admin_role'], diff --git a/lang/zh_CN/feedback.php b/lang/zh_CN/feedback.php new file mode 100644 index 0000000..464f860 --- /dev/null +++ b/lang/zh_CN/feedback.php @@ -0,0 +1,5 @@ + '内容', +]; diff --git a/lang/zh_CN/party_cate.php b/lang/zh_CN/party_cate.php index 553ec2d..ac3202a 100644 --- a/lang/zh_CN/party_cate.php +++ b/lang/zh_CN/party_cate.php @@ -11,4 +11,5 @@ return [ 'remarks' => '备注', 'score' => '累计得分', 'scores' => '五星维度', + 'current_score' => '当前得分', ]; diff --git a/lang/zh_CN/party_user.php b/lang/zh_CN/party_user.php index 5007199..65332ef 100644 --- a/lang/zh_CN/party_user.php +++ b/lang/zh_CN/party_user.php @@ -12,5 +12,6 @@ return [ 'cate_id' => '党支部', 'remarks' => '备注', 'score' => '累计得分', + 'current_score' => '当前得分', 'scores' => '五星维度', ]; diff --git a/public/assets/app.js b/public/assets/app.js new file mode 100644 index 0000000..e9e717e --- /dev/null +++ b/public/assets/app.js @@ -0,0 +1,5 @@ +const toastElement = document.getElementById('toast') +if (toastElement) { + const toast = bootstrap.Toast.getOrCreateInstance(toastElement) + toast.show() +} diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php deleted file mode 100644 index baf6864..0000000 --- a/resources/views/index.blade.php +++ /dev/null @@ -1,111 +0,0 @@ -@extends('layout') -@section('title') - {{ config('admin.name') }} -@endsection -@section('content') -
- -