From 3a39ff3790aaa5a43c8c76e437927079ced240a6 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Sat, 26 Oct 2024 18:27:45 +0800 Subject: [PATCH] feat: command --- app/Command/CronTaskCommand.php | 57 ++++++++++++++++++++++++ app/Command/ServiceCommand.php | 49 ++++++++++++++++++++ app/Command/stubs/cron.stub | 23 ++++++++++ app/Command/stubs/service.stub | 19 ++++++++ app/Constants/AdminCode.php | 14 ++++++ app/Constants/ReturnCode.php | 20 +++++++++ app/Controller/Admin/LoginController.php | 24 ++++++++++ app/Lib/AdminReturn.php | 47 +++++++++++++++++++ app/Request/Admin/LoginRequest.php | 28 ++++++++++++ app/Service/Admin/BaseService.php | 42 +++++++++++++++++ app/Service/Admin/User/LoginService.php | 22 +++++++++ config/config.php | 2 +- 12 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 app/Command/CronTaskCommand.php create mode 100644 app/Command/ServiceCommand.php create mode 100644 app/Command/stubs/cron.stub create mode 100644 app/Command/stubs/service.stub create mode 100644 app/Constants/AdminCode.php create mode 100644 app/Constants/ReturnCode.php create mode 100644 app/Controller/Admin/LoginController.php create mode 100644 app/Lib/AdminReturn.php create mode 100644 app/Request/Admin/LoginRequest.php create mode 100644 app/Service/Admin/BaseService.php create mode 100644 app/Service/Admin/User/LoginService.php diff --git a/app/Command/CronTaskCommand.php b/app/Command/CronTaskCommand.php new file mode 100644 index 0000000..72094dc --- /dev/null +++ b/app/Command/CronTaskCommand.php @@ -0,0 +1,57 @@ +setDescription('Create a new cron task class'); + + parent::configure(); + } + + /** + * 获取stub文件 + * @return string + */ + protected function getStub(): string + { + return __DIR__ . '/stubs/cron.stub'; + } + + /** + * 获取默认命名空间 + * @return string + */ + protected function getDefaultNamespace(): string + { + return 'App\\Cron'; + } +} \ No newline at end of file diff --git a/app/Command/ServiceCommand.php b/app/Command/ServiceCommand.php new file mode 100644 index 0000000..3d5bea3 --- /dev/null +++ b/app/Command/ServiceCommand.php @@ -0,0 +1,49 @@ +setDescription('Create a new service class'); + + parent::configure(); + } + + /** + * 获取stub文件 + * @return string + */ + protected function getStub(): string + { + return __DIR__ . '/stubs/service.stub'; + } + + /** + * 获取默认命名空间 + * @return string + */ + protected function getDefaultNamespace(): string + { + return 'App\\Service'; + } +} \ No newline at end of file diff --git a/app/Command/stubs/cron.stub b/app/Command/stubs/cron.stub new file mode 100644 index 0000000..0488111 --- /dev/null +++ b/app/Command/stubs/cron.stub @@ -0,0 +1,23 @@ +handle(); + } +} diff --git a/app/Lib/AdminReturn.php b/app/Lib/AdminReturn.php new file mode 100644 index 0000000..03b6d34 --- /dev/null +++ b/app/Lib/AdminReturn.php @@ -0,0 +1,47 @@ + $code, + 'message' => $msg, + 'data' => $data + ]; + + return array_merge($res, $debug); + } + + /** + * 通用api返回 + * @param string $msg + * @param array $data + * @param int $code + * @param array $debug + * @return array + */ + public static function error(string $msg = 'error', array $data = [], int $code = ReturnCode::ERROR, array $debug = []): array + { + $res = [ + 'code' => $code, + 'message' => $msg, + 'data' => $data + ]; + + return array_merge($res, $debug); + } +} \ No newline at end of file diff --git a/app/Request/Admin/LoginRequest.php b/app/Request/Admin/LoginRequest.php new file mode 100644 index 0000000..9c28b96 --- /dev/null +++ b/app/Request/Admin/LoginRequest.php @@ -0,0 +1,28 @@ +adminId = Context::get("admin_id",0); + $this->roleId = Context::get("role_id",0); + } + + /** + * 主体函数抽象类 + */ + abstract public function handle(); +} \ No newline at end of file diff --git a/app/Service/Admin/User/LoginService.php b/app/Service/Admin/User/LoginService.php new file mode 100644 index 0000000..97ef803 --- /dev/null +++ b/app/Service/Admin/User/LoginService.php @@ -0,0 +1,22 @@ + [ LogLevel::ALERT, LogLevel::CRITICAL, - LogLevel::DEBUG, +// LogLevel::DEBUG, LogLevel::EMERGENCY, LogLevel::ERROR, LogLevel::INFO,