This commit is contained in:
zhang zhuo 2025-09-09 13:34:20 +08:00
parent dd9b4845ad
commit e561fc1be3
2 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
/**
* Author: cfn <cfn@leapy.cn>
*/
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([]);
}
}

54
app/Model/Uuid.php Normal file
View File

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $id
* @property string $uuid
* @property string $exp
* @property int $del_flag
* @property int $status
* @property string $create_time
* @property string $update_time
*/
class Uuid extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'uuid';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => '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;
}
}