REAPI/app/setting/model/SystemParams.php

69 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?php
declare (strict_types=1);
namespace app\setting\model;
use think\admin\Model;
/**
* 数据字典模型
* @class SystemBase
* @package think\admin\model
*/
class SystemParams extends Model
{
protected $createTime = 'create_at';
protected $updateTime = false;
/**
* 日志名称
* @var string
*/
protected $oplogName = '系统参数';
/**
* 日志类型
* @var string
*/
protected $oplogType = '系统参数管理';
/**
* 获取指定数据列表
* @param string $type 数据类型
* @param array $data 外围数据
* @param string $field 外链字段
* @param string $bind 绑定字段
* @return array
*/
public static function items(string $type, array &$data = [], string $field = 'params_code', string $bind = 'params_info'): array
{
$map = ['type' => $type, 'status' => 1, 'deleted' => 0];
$bases = static::mk()->where($map)->order('sort desc,id asc')->column('code,name,content', 'code');
if (count($data) > 0) foreach ($data as &$vo) $vo[$bind] = $bases[$vo[$field]] ?? [];
return $bases;
}
/**
* 获取所有数据类型
* @param boolean $simple 加载默认值
* @return array
*/
public static function types(bool $simple = false): array
{
$types = static::mk()->where(['deleted' => 0])->distinct()->column('type');
if (empty($types) && empty($simple)) $types = ['系统通用参数'];
return $types;
}
/**
* 格式化创建时间
* @param mixed $value
* @return string
*/
public function getCreateAtAttr($value): string
{
return format_datetime($value);
}
}