You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.1 KiB
74 lines
2.1 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace core\base;
|
|
|
|
|
|
use think\facade\Db;
|
|
use think\Model;
|
|
|
|
/**
|
|
* 基础模型
|
|
* Class BaseModel
|
|
* @package app\model
|
|
*/
|
|
class BaseModel extends Model
|
|
{
|
|
protected $autoWriteTimestamp = true;
|
|
|
|
public static function onBeforeInsert($model)
|
|
{
|
|
$userId = Request()->uid();
|
|
$roleId = 0;
|
|
|
|
$model->created_by = $userId;
|
|
$model->created_role = $roleId;
|
|
$model->created_time = date('Y-m-d H:i:s');
|
|
|
|
$model->updated_by = $userId;
|
|
$model->updated_role = $roleId;
|
|
$model->updated_time = date('Y-m-d H:i:s');
|
|
}
|
|
|
|
public static function onBeforeUpdate($model)
|
|
{
|
|
$userId = Request()->uid();
|
|
$roleId = 0;
|
|
|
|
$model->updated_by = $userId;
|
|
$model->updated_role = $roleId;
|
|
$model->updated_time = date('Y-m-d H:i:s');
|
|
}
|
|
|
|
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 = preg_replace("/^{$tablePrefix}/", '', $table_info['Name'], 1);
|
|
return Db::name($table_name)->getFields();
|
|
}
|
|
|
|
/**
|
|
* 处理搜索条件特殊字符(%、_)
|
|
* @param $value
|
|
*/
|
|
public function handelSpecialCharacter($value)
|
|
{
|
|
$value = str_replace('%', '\%', str_replace('_', '\_', $value));
|
|
return $value;
|
|
}
|
|
}
|
|
|