diff --git a/app/Http/Controllers/Console/Link.php b/app/Http/Controllers/Console/Link.php index 4dd1149..c3f8fc2 100644 --- a/app/Http/Controllers/Console/Link.php +++ b/app/Http/Controllers/Console/Link.php @@ -91,6 +91,11 @@ protected function ViewList(Request $request): Factory|View|Application|Redirect protected function ViewCheck(Request $request): Factory|View|Application { + // 检查是否存在含有未在本站分配位置 + $this->data['blog'] = DB::table('blog_link') + ->whereIn('blog_link.blogLocation',[0]) + ->get() + ->toArray(); return view('console.friends-link.check', $this->data); } @@ -106,6 +111,11 @@ protected function ViewSort(): Factory|View|Application protected function ViewColor(): Factory|View|Application { - return view('concole.friends-link.color',$this->data); + return view('console.friends-link.color',$this->data); + } + + protected function apiConsoleAdd() { + // 检查数据 + } } diff --git a/app/Http/Controllers/Function/Link.php b/app/Http/Controllers/Function/Link.php index c3f5d21..fba3798 100644 --- a/app/Http/Controllers/Function/Link.php +++ b/app/Http/Controllers/Function/Link.php @@ -12,8 +12,13 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Mail\Message; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Response; +use Illuminate\Support\Facades\Validator; class Link extends Controller { @@ -25,22 +30,252 @@ public function __construct() $this->data = $data->data; } - protected function ViewLink(Request $request): Factory|View|Application + public function apiCustomAdd(Request $request): JsonResponse + { + /** @var array $returnData Json的 return 返回值 */ + /** @var Validator $dataCheck 数据判断 */ + /** @var array $errorInfo 错误信息 */ + /** @var array $errorSingle 输出单个错误信息 */ + // 检查数据 + $dataCheck = Validator::make($request->all(), [ + 'userEmail' => 'required|email', + 'userServerHost' => 'required|string', + 'userBlog' => 'required|string', + 'userUrl' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'userDescription' => 'required|string', + 'userIcon' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'checkRssJudge' => 'boolean', + 'userRss' => 'string|regex:#[a-zA-z]+://[^\s]*#', + 'userLocation' => 'required|int', + 'userSelColor' => 'required|int', + 'userRemark' => 'required|string', + ]); + + // 检查发现错误 + if ($dataCheck->fails()) { + $errorType = array_keys($dataCheck->failed()); + $i = 0; + foreach ($dataCheck->failed() as $valueData) { + $errorInfo[$errorType[$i]] = array_keys($valueData); + if ($i == 0) { + $errorSingle = [ + 'info' => $errorType[$i], + 'need' => $errorInfo[$errorType[$i]], + ]; + } + $i++; + } + $returnData = [ + 'output' => 'DataFormatError', + 'code' => 403, + 'data' => [ + 'message' => '输入内容有错误', + 'errorSingle' => $errorSingle, + 'error' => $errorInfo, + ], + ]; + } else { + // 检查数据 + if (empty($request->checkRssJudge)) { + $request->checkRssJudge = 0; + } + + // 根据数据库检查邮箱用户是否已存在 + $resultBlog = DB::table('blog_link') + ->where([ + ['blogOwnEmail', '=', $request->userEmail, 'or'], + ['blogName', '=', $request->userBlog, 'or'], + ['blogUrl', '=', $request->userUrl, 'or'] + ])->get()->toArray(); + + if (empty($resultBlog)) { + // 数据写入数据库 + $insertData = DB::table('blog_link') + ->insert([ + 'blogOwnEmail' => $request->userEmail, + 'blogUrl' => $request->userUrl, + 'blogName' => $request->userBlog, + 'blogDescription' => $request->userDescription, + 'blogIcon' => $request->userIcon, + 'blogRssJudge' => $request->checkRssJudge, + 'blogRSS' => $request->userRss, + 'blogUserLocation' => $request->userLocation, + 'blogSetColor' => $request->userSelColor, + 'blogRemark' => $request->userRemark, + ]); + if ($insertData) { + // 邮件发送系统 + Mail::send('mail.link-custom-add', $request->toArray(), function (Message $mail) { + global $request; + $mail->from(env('MAIL_USERNAME'), env('APP_NAME')); + $mail->to($request->userEmail); + $mail->subject(env('APP_NAME') . '-友链等待审核通知'); + }); + // 消息成功通知 + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '您已成功申请', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'AlreadyUser', + 'code' => 403, + 'data' => [ + 'message' => '已有此用户,您是否已在本博客注册过', + ], + ]; + } + } + + return Response::json($returnData, $returnData['code']); + } + + public function apiCustomSearch(Request $request): JsonResponse + { + /** @var array $returnData Json的 return 返回值 */ + if (!empty($request->location_search)) { + if ($request->searchType == 'all') { + $resultData = DB::table('blog_link') + ->where([ + ['blogName', 'LIKE', '%' . $request->location_search . '%', 'or'], + ['blogUrl', 'LIKE', '%' . $request->location_search . '%', 'or'], + ['blogOwnEmail', 'LIKE', '%' . $request->location_search . '%', 'or']]) + ->select('blogName','blogUrl','blogDescription','blogIcon') + ->orderBy('id') + ->get() + ->toArray(); + if (!empty($resultData)) { + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '数据输出成功', + 'data' => $resultData, + ], + ]; + } else { + $returnData = [ + 'output' => 'NoData', + 'code' => 200, + 'data' => [ + 'message' => '没有数据', + ], + ]; + } + } else { + if ($request->searchType == 'blogName') { + $resultData = DB::table('blog_link') + ->where([['blogName', 'LIKE', '%' . $request->location_search . '%']]) + ->select('blogName','blogUrl','blogDescription','blogIcon') + ->orderBy('id') + ->get() + ->toArray(); + if (!empty($resultData)) { + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '数据输出成功', + 'data' => $resultData, + ], + ]; + } else { + $returnData = [ + 'output' => 'NoData', + 'code' => 200, + 'data' => [ + 'message' => '没有数据', + ], + ]; + } + } elseif ($request->searchType == 'blogUrl') { + $resultData = DB::table('blog_link') + ->where([['blogUrl', 'LIKE', '%' . $request->location_search . '%']]) + ->select('blogName','blogUrl','blogDescription','blogIcon') + ->orderBy('id') + ->get() + ->toArray(); + if (!empty($resultData)) { + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '数据输出成功', + 'data' => $resultData, + ], + ]; + } else { + $returnData = [ + 'output' => 'NoData', + 'code' => 200, + 'data' => [ + 'message' => '没有数据', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'TypeError', + 'code' => 403, + 'data' => [ + 'message' => '类型错误请检查', + ], + ]; + } + } + } else { + $returnData = [ + 'output' => 'SearchEmpty', + 'code' => 403, + 'data' => [ + 'message' => '搜索为空,请输入内容', + ], + ]; + } + return Response::json($returnData,$returnData['code']); + } + + protected function viewLink(Request $request): Factory|View|Application { $this->data['webSubTitle'] = '友链'; $this->GetFriendsLink($this->data); - return view('function.link',$this->data); - } - - protected function ViewMakeFriend(): Factory|View|Application - { - $this->data['webSubTitle'] = '添加友链'; - return view('function.make-friend',$this->data); + return view('function.link', $this->data); } private function GetFriendsLink(array &$data): void { - $data['blogLink'] = DB::table('blog_link')->whereNotIn('blog_link.blogLocation',[0])->get()->toArray(); + $data['blogLink'] = DB::table('blog_link')->whereNotIn('blog_link.blogLocation', [0])->get()->toArray(); $data['blogSort'] = DB::table('blog_sort')->orderBy('blog_sort.sort')->get()->toArray(); } + + protected function viewMakeFriend(): Factory|View|Application + { + $this->data['webSubTitle'] = '添加友链'; + $this->data['blogColor'] = DB::table('blog_color') + ->orderBy('id') + ->get() + ->toArray(); + $this->data['blogSort'] = DB::table('blog_sort') + ->orderBy('sort') + ->get() + ->toArray(); + return view('function.make-friend', $this->data); + } + + protected function viewEditFriend(): Factory|View|Application + { + $this->data['webSubTitle'] = '修改友链'; + + return view('function.edit-friend', $this->data); + } + + protected function viewSearchFriends(): Factory|View|Application + { + $this->data['webSubTitle'] = '查询列表'; + return view('function.edit-search', $this->data); + } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index bd816f6..bb88ce4 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -45,7 +45,7 @@ public function boot() $this->routes(function () { Route::prefix('api') ->middleware('api') - ->namespace($this->namespace) + ->namespace($this->namespace.'\\api') ->group(base_path('routes/api.php')); Route::middleware('web') diff --git a/database/migrations/2023_06_11_145919_update_blog_link_table.php b/database/migrations/2023_06_11_145919_update_blog_link_table.php index faee97f..9bca0ab 100644 --- a/database/migrations/2023_06_11_145919_update_blog_link_table.php +++ b/database/migrations/2023_06_11_145919_update_blog_link_table.php @@ -20,6 +20,18 @@ public function up() { Schema::table('blog_link', function (Blueprint $table) { $table->boolean('blogAddType')->default(0)->after('blogLocation'); + $table->unsignedInteger('blogUserLocation') + ->default(0) + ->after('blogSetColor') + ->comment('用户期望位置'); + $table->unsignedBigInteger('blogForUser') + ->nullable() + ->after('blogUserLocation') + ->comment('绑定已注册用户'); + $table->string('blogRemark') + ->nullable() + ->after('blogForUser') + ->comment('博客备注信息'); }); } diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 12f4ace..55b4a25 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -46,7 +46,7 @@ class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ri