Files
swiftadmin/app/common/model/system/Dictionary.php

62 lines
1.3 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
declare(strict_types=1);
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class Dictionary extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
// 字段修改器
public function setSortAttr($value)
{
if (is_empty($value)) {
return self::max('id') + 1;
}
return $value;
}
/**
* 获取字典信息
* @param string $value
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getValueList(string $value = '')
2022-08-19 19:48:37 +08:00
{
$list = [];
$data = self::where(['pid' => 0,'value' => $value])->find();
2022-08-19 19:48:37 +08:00
if (!empty($data)) {
$list = self::where('pid', $data['id'])->select();
}
return $list;
}
/**
* 返回最小id
* @return int
*/
public static function minId(): int
{
return (int)self::where('pid', '0')->min('id');
}
}