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

54 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\model;
use think\Model;
class Client extends Model
{
protected $name = 'clients';
protected $pk = 'id';
protected $autoWriteTimestamp = true;
protected $createTime = 'created_at';
protected $updateTime = 'updated_at';
protected $append = ['api_keys'];
// 客户类型枚举
const TYPE_SUPPLIER = 'supplier';
const TYPE_DISTRIBUTOR = 'distributor';
const TYPE_HOSPITAL = 'hospital';
const TYPE_OTHER = 'other';
// 状态枚举
const STATUS_ENABLED = 1;
const STATUS_DISABLED = 0;
/**
* 关联API密钥
*/
public function apiKeys()
{
return $this->hasMany(ApiKey::class, 'client_id');
}
/**
* 获取api_keys字段下划线命名
*/
public function getApiKeysAttr()
{
return $this->apiKeys()->select()->toArray();
}
/**
* 获取客户类型列表
*/
public static function getClientTypes()
{
return [
self::TYPE_SUPPLIER => '供应商',
self::TYPE_DISTRIBUTOR => '分销商',
self::TYPE_HOSPITAL => '医院',
self::TYPE_OTHER => '其他',
];
}
}