Files
docs/thinkphp/app/model/Permission.php
cenzuhai 3a04eede84 feat: 初始化进销存数据开放平台项目
初始化完整的前后端项目结构,包含ThinkPHP后端API服务和Next.js前端管理系统,添加基础配置、中间件、模型、路由等核心代码,以及项目文档和静态资源。
2026-07-08 17:48:00 +08:00

55 lines
1.1 KiB
PHP

<?php
namespace app\model;
use think\Model;
class Permission extends Model
{
protected $name = 'permissions';
protected $pk = 'id';
protected $autoWriteTimestamp = true;
protected $createTime = 'created_at';
protected $updateTime = 'updated_at';
// 权限枚举
const ALLOW_NO = 0;
const ALLOW_YES = 1;
// 数据模式枚举
const MODE_FILTER = 'filter';
const MODE_CUSTOM = 'custom';
const MODE_FULL = 'full';
/**
* 关联API密钥
*/
public function apiKey()
{
return $this->belongsTo(ApiKey::class, 'api_key_id');
}
/**
* 检查是否允许访问接口
*/
public function canAccess($endpoint)
{
if ($this->isFullData()) {
return true;
}
if ($endpoint === 'chuku') {
return $this->allow_chuku == self::ALLOW_YES;
} elseif ($endpoint === 'ruku') {
return $this->allow_ruku == self::ALLOW_YES;
}
return false;
}
/**
* 检查是否允许全量数据
*/
public function isFullData()
{
return $this->allow_full_data == self::ALLOW_YES;
}
}