From e561fc1be3a14cb2dbe66f45394bedba7be52f3e Mon Sep 17 00:00:00 2001 From: zhang zhuo Date: Tue, 9 Sep 2025 13:34:20 +0800 Subject: [PATCH] uuid --- app/Controller/GaoDingController.php | 29 +++++++++++++++ app/Model/Uuid.php | 54 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 app/Controller/GaoDingController.php create mode 100644 app/Model/Uuid.php diff --git a/app/Controller/GaoDingController.php b/app/Controller/GaoDingController.php new file mode 100644 index 0000000..757971b --- /dev/null +++ b/app/Controller/GaoDingController.php @@ -0,0 +1,29 @@ + + */ + +namespace App\Controller; + +use App\Kernel\Annotation\PreAuthorization; +use Hyperf\HttpServer\Annotation\Controller; +use Hyperf\HttpServer\Annotation\GetMapping; +use App\Model\Uuid as uModel; + +#[Controller()] +class GaoDingController extends AbstractController +{ + #[GetMapping("uuid/get")] + #[PreAuthorization(needAuth: false)] + public function get() + { + return $this->success(uModel::add()); + } + + #[GetMapping("uuid/query")] + #[PreAuthorization(needAuth: false)] + public function query() + { + return $this->success([]); + } +} \ No newline at end of file diff --git a/app/Model/Uuid.php b/app/Model/Uuid.php new file mode 100644 index 0000000..bcc668a --- /dev/null +++ b/app/Model/Uuid.php @@ -0,0 +1,54 @@ + 'integer', 'del_flag' => 'integer', 'status' => 'integer']; + + public static function add() + { + $data = [ + 'uuid' => self::uuid(), + 'exp' => date("Y-m-d"), + 'status' => 0, + 'create_time' => date("Y-m-d H:i:s") + ]; + // 判断uuid是否存在 + $res = self::insert($data); + return $res ? ['uuid' => $data['uuid'], 'exp' => $data['exp']] : []; + } + + static function uuid() + { + $uuid = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ2356789'), 0, 8); + if (self::where("uuid", $uuid)->where("del_flag", 0)->count() > 0) { + return self::uuid(); + } + return $uuid; + } +}