123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace core\base;
- use app\model\site\Site;
- use think\facade\Db;
- use think\Model;
- /**
- * 基础模型
- * Class BaseModel
- * @package app\model
- */
- class BaseModel extends Model
- {
- public function getModelColumn()
- {
- $table_name = $this->getTable();
- $sql = 'SHOW TABLE STATUS WHERE 1=1 ';
- $tablePrefix = config('database.connections.mysql.prefix');
- if (!empty($table_name)) {
- $sql .= "AND name='" .$table_name."'";
- }
- $tables = Db::query($sql);
- $table_info = $tables[0] ?? [];
- $table_name = str_replace($tablePrefix, '', $table_info['Name']);
- return Db::name($table_name)->getFields();
- }
- /**
- * 站点名称获取(针对有site_id字段的模型查询站点名称使用)
- * 使用with('siteName')
- * @return \think\model\relation\HasOne
- */
- public function siteName()
- {
- return $this->hasOne(Site::class, 'site_id', 'site_id')->joinType('left')->field('site_id, site_name')->bind(['site_name']);
- }
- /**
- * 处理搜索条件特殊字符(%、_)
- * @param $value
- */
- public function handelSpecialCharacter($value)
- {
- $value = str_replace('%', '\%', str_replace('_', '\_', $value));
- return $value;
- }
- }
|