60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?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' => 1,
|
|
'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;
|
|
}
|
|
|
|
public static function getByUuid(string $uuid)
|
|
{
|
|
return self::where("uuid", $uuid)->where("del_flag", 0)->select(['uuid','status','exp'])->first();
|
|
}
|
|
}
|