test_lgq/niucloud/core/base/BaseModel.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2024-01-24 17:36:08 +08:00
<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的saas管理平台
// +----------------------------------------------------------------------
// | 官方网址https://www.niucloud-admin.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\base;
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();
}
}